835 Commits

Author SHA1 Message Date
Matt Arsenault
2502e3b7ba
IR: Promote "denormal-fp-math" to a first class attribute (#174293)
Convert "denormal-fp-math" and "denormal-fp-math-f32" into a first
class denormal_fpenv attribute. Previously the query for the effective
denormal mode involved two string attribute queries with parsing. I'm
introducing more uses of this, so it makes sense to convert this
to a more efficient encoding. The old representation was also awkward
since it was split across two separate attributes. The new encoding
just stores the default and float modes as bitfields, largely avoiding
the need to consider if the other mode is set.

The syntax in the common cases looks like this:
  `denormal_fpenv(preservesign,preservesign)`
  `denormal_fpenv(float: preservesign,preservesign)`
  `denormal_fpenv(dynamic,dynamic float: preservesign,preservesign)`

I wasn't sure about reusing the float type name instead of adding a
new keyword. It's parsed as a type but only accepts float. I'm also
debating switching the name to subnormal to match the current
preferred IEEE terminology (also used by nofpclass and other
contexts).

This has a behavior change when using the command flag debug
options to set the denormal mode. The behavior of the flag
ignored functions with an explicit attribute set, per
the default and f32 version. Now that these are one attribute,
the flag logic can't distinguish which of the two components
were explicitly set on the function. Only one test appeared to
rely on this behavior, so I just avoided using the flags in it.

This also does not perform all the code cleanups this enables.
In particular the attributor handling could be cleaned up.

I also guessed at how to support this in MLIR. I followed
MemoryEffects as a reference; it appears bitfields are expanded
into arguments to attributes, so the representation there is
a bit uglier with the 2 2-element fields flattened into 4 arguments.
2026-02-05 13:31:26 +00: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
287c69b469
Attributor: Add denormal-fp-math to attributor-light (#79576) 2026-02-03 08:57:03 +01: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
485eb62afd
Attributor: Use anchor scope for SimplifyQuery context (#178958)
This was asserting in computeKnownFPClass when a dominator tree
check happened across functions.

Fixes #178954
2026-01-30 22:38:07 +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
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
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
0387625c3e
ValueTracking: Detect cases with no underflow for fadd (#177746)
In the case where both operands have the same sign,
as long as one of the operands is normal or infinity,
the result cannot underflow to a zero.

Pre-committing for #175614
2026-01-24 09:50:01 +00:00
Matt Arsenault
7826cbeacb
Attributor: Regenerate baseline test checks (#177560) 2026-01-23 10:34:00 +00: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
Matt Arsenault
f7ee822e0c
ValueTracking: Propagate non-nan sources through fmul square (#176243)
ValueTracking: Propagate non-nan sources through fmul square

https://alive2.llvm.org/ce/z/hbZUfc
2026-01-16 16:45:21 +01:00
Matt Arsenault
4fa99b6465
ValueTracking: Add baseline tests for improved fma handling (#175613)
Improved signbit and not-nan tracking.
2026-01-15 21:02:14 +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
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
Matt Arsenault
3ad028173b
ValueTracking: sqrt never returns subnormal (#174846) 2026-01-11 18:07:53 +00: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
98df73d52a
ValueTracking: Add more baseline tests for fdiv sign tracking (#174651)
This is the fmul version of 08b1403228953866cb052a3fdb34719a7f4e87e2
2026-01-10 15:57:01 +01:00
Matt Arsenault
4deb16c481
Attributor: Set up full SimplifyQuery for nofpclass (#174928)
This enables assumes to work. Somehow the most obvious example
I could think of does not work (return of assumed argument).
The context instruction for the return seems to be off by one.
2026-01-08 19:37:55 +01: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
fd5cfcc413
ValueTracking: Check if x is undef for fma(x, x, y) analysis (#174763) 2026-01-07 17:40:07 +00: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
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
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
Matt Arsenault
3d3093e4e3
ValueTracking: Add more baseline tests for computeKnownPPClass of fadd (#174122)
Test cases with fadd x, x. Also test cases where both inputs are known
negative.
2026-01-03 11:14:36 +01:00
Matt Arsenault
3b09719963
ValueTracking: Improve handling of exp intrinsic for overflow (#173430)
Teach exp handling that positive inputs cannot introduce overflow,
and negative inputs cannot introduce underflow.
2025-12-29 14:24:24 +00:00
Matt Arsenault
92e0cd2ef7
ValueTracking: Add baseline tests for computeKnownFPClass exp (#173429)
This is already handled, but misses opportunities. Test cases
where the input is known positive or negative.
2025-12-29 14:45:26 +01:00
Matt Arsenault
559e8131ec
ValueTracking: log may never return -0 (#173380) 2025-12-29 11:08:08 +01:00
Matt Arsenault
5020e0ff14
ValueTracking: Improve computeKnownFPClass fmul handling (#173247)
Improve known non-nan sign bit tracking. Handle cases with
a known 0 or inf input of indeterminate sign.

The tails of some library functions have sign management
for special cases.
2025-12-24 22:17:58 +00:00
Matt Arsenault
08b1403228
ValueTracking: Add baseline tests for fmul computeKnownFPClass (#173246) 2025-12-24 21:25:58 +00:00
Matt Arsenault
42b3483ac4
ValueTracking: Improve accuracy of 0 handling with PreserveSign (#173165)
If the source value is known not subnormal and not zero with the
same sign, we can infer the result is also not zero with the same
sign.
2025-12-21 11:14:24 +00:00
Matt Arsenault
ffbed74c75
ValueTracking: Add more tests for computeKnownFPClass canonicalize (#173164) 2025-12-21 11:32:40 +01:00
Matt Arsenault
c68fa5ebab
AMDGPU: Handle amdgcn_rcp in computeKnownFPClass (#172490) 2025-12-18 13:50:11 +01:00
Matt Arsenault
eecce1689a
ValueTracking: Add baseline test for amdgcn_rcp handling (#172489) 2025-12-17 23:19:53 +01:00
Matt Arsenault
7b9168caa9
ValueTracking: Handle amdgcn_exp2 in computeKnownFPClass (#172495) 2025-12-17 23:17:13 +01:00
Matt Arsenault
82cdc300fa
ValueTracking: Handle amdgcn_log in computeKnownFPClass (#172492) 2025-12-17 23:16:25 +01:00
Matt Arsenault
33d7cd67a8
ValueTracking: Add baseline test for amdgcn_exp2 handling (#172494) 2025-12-17 22:14:01 +01:00
Matt Arsenault
3734ace841
ValueTracking: Add baseline test for nofpclass handling of amdgcn_log (#172491) 2025-12-17 22:08:35 +01:00
Matt Arsenault
44c0469e5f
ValueTracking: Handle amdgcn.rsq intrinsic in computeKnownFPClass (#171837)
We have other target intrinsics already in ValueTracking functions,
and no access to TTI.
2025-12-12 16:48:12 +01:00
Matt Arsenault
87b3bf5b66
ValueTracking: Add baseline test for fpclass handling of amdgcn.rsq (#171836) 2025-12-12 13:54:39 +01:00
Matt Arsenault
39fcd2cb81
ValueTracking: Teach computeKnownFPClass that multiply can avoid denormals (#171730)
Multiply by large constant can be used to scale denormal inputs into
a normal range. This pattern appears frequently in math function library
implementations to make use of hardware instructions that do not support
denormals. We already handle this case for ldexp, but now canonicalize
ldexp by a constant to an fmul.

The test cases are mostly the existing nofpclass test for ldexp,
run through the new instcombine to replace ldexp with fmul.
2025-12-11 12:39:58 +00:00
Matt Arsenault
4be3df8cf1
ValueTracking: Add baseline test for fmul denormal scaling handling (#171729) 2025-12-11 13:06:08 +01:00
Shoreshen
e442904e70
[AMDGPU] Apply alignment attr for make.buffer.rsrc (#166914)
Calculating alignment for `make.buffer.rsrc` intrinsic. The logic is the
alignment on use of return value of `make.buffer.rsrc` should be capped
by the base operand's alignment of `make.buffer.rsrc`.

For example:
```ll
define float @foo(ptr addrspace(1) align X %ptr) {
  %fat.ptr = call ptr addrspace(7) @llvm.amdgcn.make.buffer.rsrc.p7.p1(ptr addrspace(1) %ptr, i16 0, i32 C, i32 0)
  %y = load float, ptr addrspace(7) %fat.ptr, align Y
  ret float %y
}
```

We hopes that `Y = min(X, Y)`

---

After discussion, it seems improper for letting `Y = min(X, Y)` since it
contradict with the semantic of align on load.

So we would apply the origin behavior of align, which is letting `X` and
`Y` both equal to `max(X, Y)`

---------

Co-authored-by: Shilei Tian <i@tianshilei.me>
2025-12-08 12:48:54 +08:00