11 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
91c4decc01
InstCombine: Fix SimplifyDemandedFPClass bug with known-snan sources (#179244)
If the result can be a qnan, the source can be a signaling nan.
2026-02-02 17:57:21 +00:00
Matt Arsenault
12731bd6ed
InstCombine: Stop using nsz in multi-use min/max fold (#176579)
In SimplifyDemandedFPClass, stop using nsz when there's a
mismatch in the sign of 0 for the various min and maxes.

Alive2 doesn't like it: https://alive2.llvm.org/ce/z/ZyhSGA,
presumably because of the possible mismatch between the stored
value and the propagated. Maybe it would be OK if nsz is on all
the uses.
2026-02-02 18:48:12 +01:00
Matt Arsenault
48e64a7924
InstCombine: Add baseline tests for broken snan handling (#179243)
SimplifyDemandedFPClass doesn't correctly account for possible
quieting in all cases.
2026-02-02 18:23:53 +01:00
Matt Arsenault
35efc168dd
InstCombine: Fold known-qnan results to a literal nan (#176123)
Previously we only considered fcNan to fold to qnan for canonicalizing
results, ignoring the simpler case where we know the nan is already
quiet.
2026-01-24 10:41:29 +00:00
Matt Arsenault
0f54961189
InstCombine: Introduce nsz flag on minimum/maximum in SimplifyDemandedFPClass (#173898)
Alive isn't particularly happy with this in the case where
one of the inputs could be zero, but I think
it's wrong: https://alive2.llvm.org/ce/z/dF7V6k

nsz shouldn't permit introducing a -0 result where
there wasn't one in the input here.
2026-01-15 09:23:27 +00:00
Matt Arsenault
fb67ef1a8b
InstCombine: Handle multiple uses for min/max in SimplifyDemandedFPClass (#175974) 2026-01-14 18:31:16 +00:00
Matt Arsenault
196433eb27
InstCombine: Improve SimplifyDemandedFPClass min/max handling (#175382)
Refine handling of minimum/maximum and minimumnum/maximumnum. The
previous folds to input were based on sign bit checks. This was too
conservative with 0s. This can now consider -0 as less than or equal
to +0 as appropriate, account for nsz. It additionally can handle
cases like one half is known positive normal and the other subnormal.
2026-01-14 18:01:14 +00:00
Matt Arsenault
c55f690213
InstCombine: Add more tests for min/max SimplifyDemandedFPClass (#175381)
Test some more refined cases, such as ordering with 0s and within
known positive and known negative cases.
2026-01-14 18:27:13 +01:00
Matt Arsenault
f38e54ee83
InstCombine: Handle minimum/maximum in SimplifyDemandedFPClass (#173897) 2026-01-07 19:35:04 +01:00
Matt Arsenault
6153876d0f
InstCombine: Add baseline tests for minimum/maximum SimplifyDemandedFPClass handling (#173896) 2026-01-07 17:44:02 +00:00