1675 Commits

Author SHA1 Message Date
Qinkun Bao
43905d6c8a
Revert "[ValueTracking] Propagate sign information out of loop" (#180354)
Reverts llvm/llvm-project#175590

Break https://lab.llvm.org/buildbot/#/builders/55/builds/23820 and clang
2026-02-07 17:02:17 +00:00
Kshitij Paranjape
7054a4b8f9
[ValueTracking] Propagate sign information out of loop (#175590)
LLVM converts sqrt libcall to intrinsic call if the argument is within
the range(greater than or equal to 0.0). In this case the compiler is
not able to deduce the non-negativity on its own. Extended ValueTracking
to understand such loops.

Fixes llvm/llvm-project#174813
2026-02-07 14:36:00 +01:00
Matt Arsenault
7df2bd648e
AMDGPU: Implement computeKnownFPClass for llvm.amdgcn.fract (#179134) 2026-02-04 18:02:50 +01:00
Matt Arsenault
e747287f61
AMDGPU: Implement computeKnownFPClass for llvm.amdgcn.trig.preop (#179026)
Surprisingly this doesn't consider the special cases, and literally
just extracts the exponent and proceeds as normal.
2026-02-04 17:57:10 +01:00
Matt Arsenault
880ed01100
ValueTracking: Move powi logic to KnownFPClass (#179301)
This case is kind of ugly because we still need to look at the
known bits to short circuit the source check
2026-02-02 19:18:49 +00:00
Matt Arsenault
32ccf4eed0
ValueTracking: Move ldexp KnownFPClass handling to support (#179235)
Will enable code sharing with SImplifyDemandedFPClass, SelectionDAG
and GlobalISel.
2026-02-02 18:23:07 +00:00
Matt Arsenault
b556e41ac6
ValueTracking: Use computeKnownBits for ldexp integer handling (#179234)
Switch to using computeKnownBits instead of computeConstantRange
in computeKnownFPClass's ldexp handling. This is preparation to
move the handling into KnownFPClass. Since KnownFPClass is in Support,
it can make use of KnownBits as the input argument. ConstantRange is in
IR, so it cannot be used from Support.
2026-02-02 18:39:27 +01:00
Matt Arsenault
07ec2fa144
ValueTracking: Revert noundef checks in computeKnownFPClass for fmul/fma (#178850)
This functionally reverts fd5cfcc41311c6287e9dc408b8aae499501660e1 and
35ce17b6f6ca5dd321af8e6763554b10824e4ac4.

This was correct and necessary, but is causing performance regressions
since isGuaranteedNotToBeUndef is apparently not smart enough to detect
through recurrences. Revert this for the release branch.

Also the test coverage was inadequate for the fma case, so add a new
case which changes with and without the check.
2026-01-30 11:48:36 +01:00
Matt Arsenault
a692d171ec
ValueTracking: log never returns denormal (#178234) 2026-01-27 17:56:23 +01:00
Matt Arsenault
81fa743e3d
ValueTracking: Move sin/cos computeKnownFPClass handling to support (#178240)
These are the same for now but keep the separate names for future
use.
2026-01-27 17:47:29 +01:00
Lleu Yang
b8cccd6cef
[Analysis] computeKnownBitsFromOperator - add @llvm.clmul knownbits handling and tests (#177893)
This adds knownbits handling for `Intrinsic::clmul` inside
`computeKnownBitsFromOperator`. Tests are also included.

Closes #177550
2026-01-27 11:54:24 +00:00
Matt Arsenault
528c99df3a
ValueTracking: Use m_CheckedFp in isKnownIntegral (#178019) 2026-01-26 19:24:28 +00:00
Matt Arsenault
a25c7d7ade
ValueTracking: Extract isKnownIntegral out of AMDGPU (#177912)
Also do some basic conversions to use SimplifyQuery and add tests to
show assume works in a new context.
2026-01-26 19:55:14 +01:00
Matt Arsenault
f8a4091f15
ValueTracking: Improve nan tracking for fma square special case (#175999)
In the square multiply case, we can infer if the add of opposite
sign infinities can occur.
2026-01-24 12:42:25 +01:00
Matt Arsenault
0993d69bc3
InstCombine: Handle fdiv in SimplifyDemandedFPClass (#175946) 2026-01-24 11:37:04 +00:00
Matt Arsenault
aa53f6f3db
ValueTracking: Improve handling for fma/fmuladd (#175614)
The handling for fma was very basic and only handled the
repeated input case. Re-use the fmul and fadd handling for more
accurate sign bit and nan handling.
2026-01-24 11:35:14 +01:00
Matt Arsenault
403502f478
InstCombine: Implement SimplifyDemandedFPClass for frexp (#176122) 2026-01-24 08:11:50 +01:00
Matt Arsenault
c991fdd4bc
InstCombine: Handle fsub in SimplifyDemandedFPClass (#175852)
alive2 fails on some of the tests, but this is due to existing
folds in instsimplify and
https://github.com/AliveToolkit/alive2/issues/1273
2026-01-23 23:59:02 +01:00
Matt Arsenault
6000703ba8
InstCombine: Handle fptrunc in SimplifyDemandedFPClass (#175421)
Also handle llvm.fptrunc.round since it's the same.
2026-01-23 23:40:59 +01:00
Matt Arsenault
6934ed51b3
IR: Add !nofpclass metadata (#177140)
This adds the analogous metadata to the nofpclass attribute
to assert values are not a certain set of floating-point classes.
This allows the same information to be expressed if a function
argument is passed indirectly. This matches the bitmask encoding
of nofpclass.

I also think this should be allowed for stores to symmetrically handle
sret, but leave that for later.

Alternatively we could add a more expressive !fprange metadata,
but that would be much more complex. It's useful to match the attribute,
and more annotations can always be added.

Fixes #133560
2026-01-22 20:49:34 +01:00
Nathan Corbyn
a8098629bc
[IR] Teach drop/hasPoisonGeneratingAnnotations() about abs, ctlz and cttz (#175941) 2026-01-15 00:01:58 +00:00
Nikolas Klauser
d2afc3e84b
[ValueTracking] Allow dereferenceable(0) to be applied to a null pointer (#175913)
`dereferenceable(<n>)` with n being potentially zero can come up when
using an operand bundle with a variable size. Currently this implies
that the pointer is non-null, even though `[nullptr, nullptr)` is a
valid range in any programming language I'm aware of. This patch removes
this implication and updates the language reference to reflect that
`dereferenceable` with a zero argument is valid.
2026-01-14 15:58:39 +01:00
Matt Arsenault
c620b47751
ValueTracking: Account for undef in adjustKnownFPClassForSelectArm (#175372)
This needs to consider undef like the KnownBits case does.
2026-01-13 20:36:00 +01:00
Justin Lebar
bbcab0bf57
[InstCombine] Fix i1 ssub.sat compare folding (#173742)
For every type other than i1, ssub.sat x, y = 0 implies x == y.  But
ssub.sat.i1 0, -1 = 0 (because the result of 1 saturates to 0).

The changes to instcombine are not strictly necessary.  Instcombine
canonicalizes the ssub.sat.i1 before we arrive at these pattern-matches.
The real fix is in ValueTracking.

Nonetheless we agreed in review it makes sense to add these checks to
instcombine, even though they're currently unreachable:
https://github.com/llvm/llvm-project/pull/173742#issuecomment-3696631396

This was found by a fuzzer I'm working on!
2026-01-12 11:03:00 -08:00
Matt Arsenault
acfc31a4a7
InstCombine: Handle rounding intrinsics in SimplifyDemandedFPClass (#174842) 2026-01-12 18:51:44 +00:00
Matt Arsenault
669d71be6f
ValueTracking: Fix handling of fadd with mixed denormal modes (#175454)
Fix case where the input mode is IEEE, the output flushes, and the
input could be subnormal. Also improves accuracy with positive zero
case.
2026-01-12 17:17:53 +01:00
Valeriy Savchenko
8877491388
[ValueTracking] Support horizontal vector add in computeKnownBits (#174410)
Alive2 proofs:
* Leading zeros - [4vi32](https://alive2.llvm.org/ce/z/w--S2D),
[16vi8](https://alive2.llvm.org/ce/z/hEdVks)
* Leading ones - [4vi16](https://alive2.llvm.org/ce/z/RyPdBS),
[16vi8](https://alive2.llvm.org/ce/z/UTFFt9)
2026-01-11 15:28:31 +00:00
Matt Arsenault
99ab1dd145
InstCombine: Implement SimplifyDemandedFPClass for sqrt (#173883) 2026-01-11 11:42:41 +00:00
Matt Arsenault
7e4f390c38
InstCombine: Handle fpext in SimplifyDemandedFPClass (#174849) 2026-01-11 11:46:50 +01:00
Matt Arsenault
35ce17b6f6
ValueTracking: Check if fmul operand could be undef (#174458)
In the special case for the same value for both operands,
ensure the value isn't undef.
2026-01-10 19:05:56 +00:00
Matt Arsenault
ba79486b6a
ValueTracking: Rule out nan for fdiv self special case (#174857)
Addresses TODO for signaling nan handling.
2026-01-10 16:56:06 +00:00
Matt Arsenault
481cf71a02
ValueTracking: Handle fdiv by known 0 case in computeKnownFPClass (#174855)
This will help subsume some transforms instsimplify performs
in the middle of SimplifyDemandedFPClass
2026-01-10 16:20:49 +00:00
Matt Arsenault
e2ff1348f8
ValueTracking: Improve sign bit handling for fdiv (#174652)
This is the fdiv version of 5020e0ff1494137ff12b4ed7c8fa896f8088b17b for
fmul.
2026-01-10 15:48:24 +00:00
Matt Arsenault
75b6493cc2
ValueTracking: Check if fdiv operand could be undef (#174453)
In the special case for fdiv/frem with the same operands, make
sure the input isn't undef.
2026-01-08 17:42:10 +01:00
Matt Arsenault
80296b618e
ValueTracking: Refactor computeKnownFPClass select handling (#174957)
Match the structure of ComputeKnownBits. Expose the condition
handling as a utility function so SimplifyDemanedFPClass can make
use of this. Avoids some redundant code and improves accuracy in
at least one case.
2026-01-08 17:11:28 +01:00
Matt Arsenault
a8f51a3ad6
ValueTracking: Use fcmp parent function to query denormal mode (#174929)
Avoid depending on the SimplifyQuery's context instruction,
which may be null to query the function context to use for the
denormal mode. This avoids crashes in future patches.
2026-01-08 09:41:57 +00:00
Matt Arsenault
e29abeae77
InstCombine: Handle log/log2/log10 in SimplifyDemandedFPClass (#173881) 2026-01-07 19:37:21 +01:00
Matt Arsenault
f38e54ee83
InstCombine: Handle minimum/maximum in SimplifyDemandedFPClass (#173897) 2026-01-07 19:35:04 +01:00
Matt Arsenault
fd5cfcc413
ValueTracking: Check if x is undef for fma(x, x, y) analysis (#174763) 2026-01-07 17:40:07 +00:00
Matt Arsenault
28de3c1576
InstCombine: Handle fmul in SimplifyDemandedFPClass (#173872) 2026-01-07 17:34:23 +01:00
Matt Arsenault
3d59a4da94
ValueTracking: Reapply remainder of fadd handling from #174290 (#174569)
Reapply the zero handling, reverted in
108a22ed5fa1836b4cfcd05e9d96f98a533068d5

The failing libc test should have been fixed by
e25eacf10c0d6718bad4e18e63757f97be9f9596
2026-01-06 11:42:46 +00:00
Matt Arsenault
fbbd2e319c
ValueTracking: Rephrase fmul sign bit checks (#174498)
Consistently use isKnownNever instead of isKnownAlways
2026-01-06 00:12:06 +01:00
Nikita Popov
30a1ffb7ab
[ValueTracking] Support ptrtoaddr in inequality implication (#173362)
`ptrtoaddr(p1) - ptrtoaddr(p2) == non-zero` implies `p1 != p2`, same as
for ptrtoint.
2026-01-05 09:39:16 +01:00
Nikita Popov
e65317acbb
[ValueTracking] Support ptrtoaddr in computeKnownBits() (#173358)
ptrtoaddr can be handled the same as ptrtoint here. The pointer known
bits cover the full pointer width, and ptrtoaddr either passes those
through directly or truncates to the address size.
2026-01-05 09:37:34 +01:00
Matt Arsenault
c03b6f3d2a
Partially reapply "ValueTracking: Improve handling of fadd in computeKnownFPClass." (#174290) (#174332)
This partially reverts commit 108a22ed5fa1836b4cfcd05e9d96f98a533068d5.

Restore the sign-bit tracking for both inputs known-negative case,
and leave the 0 handling for later. There is a libc test improperly
relying on running code compiled for IEEE behavior that changed
the output denormal mode.
2026-01-04 15:02:33 +00:00
Aiden Grossman
108a22ed5f
Revert "ValueTracking: Improve handling of fadd in computeKnownFPClass." (#174290)
Reverts llvm/llvm-project#174123

This caused test failures within LLVM libc. They can be reproduced by
doing a libc build against a clang with this commit included and running
`ninja -k 0 libc.test.src.math.smoke.log1p_test.__unit__
libc.test.src.math.smoke.log1p_test.__unit__.__NO_FMA_OPT`.
2026-01-03 14:12:21 -08:00
Matt Arsenault
00fdb29752
ValueTracking: Avoid unnecessary denormal mode lookup for fadd (#174272)
The mode was already queried, so don't do it again.
2026-01-03 10:59:32 +00:00
Matt Arsenault
5cbc6a63a1
ValueTracking: Improve handling of fadd in computeKnownFPClass. (#174123)
This already recognized that if both inputs are positive, the
result is positive. Extend this to the mirror situation with
negative inputs.

Also special case fadd x, x. Canonically, fmul x, 2 is fadd x, x.
We can tell the sign bit won't change, and 0 will propagate.
2026-01-03 10:57:01 +00:00
Victor Chernyakin
c438773432
[LLVM][ADT] Migrate users of make_scope_exit to CTAD (#174030)
This is a followup to #173131, which introduced the CTAD functionality.
2026-01-02 20:42:56 -08:00
Matt Arsenault
e4722c69b8
InstCombine: Handle exp/exp2/exp10 in SimplifyDemandedFPClass (#173432)
I'm working on optimizing out the tail sequences in the
implementations of the 4 different flavors of pow. These
include chains of selects on the various edge cases.

Related to #64870
2025-12-29 15:03:13 +00:00