This is an archive of the discontinued LLVM Phabricator instance.

ValueTracking: Add start of computeKnownFPClass API
ClosedPublic

Authored by arsenm on Feb 2 2023, 8:52 AM.

Details

Summary

Add a new compute-known-bits like function to compute all
the interesting floating point properties at once.

Eventually this should absorb all the various floating point
queries we already have.

The operators on FPClassTest should really go with the definition in FloatingPointMode.h
and are reusable in InstCombine; they're where they are to avoid merge pain for myself in
some of my other patches backed up in review

Diff Detail

Event Timeline

arsenm created this revision.Feb 2 2023, 8:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 2 2023, 8:52 AM
arsenm requested review of this revision.Feb 2 2023, 8:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 2 2023, 8:52 AM
Herald added a subscriber: wdng. · View Herald Transcript
llvm/include/llvm/Analysis/ValueTracking.h
224–228

Would it make sense instead to have a std::optional<bool> KnownSignBit here?

llvm/lib/Analysis/ValueTracking.cpp
4234–4236

This pattern is common enough that I think KnownFPClass should have a ruleOut(FPClassTest) method or something similar to implement this method.

arsenm updated this revision to Diff 497635.Feb 15 2023, 4:31 AM
arsenm marked 2 inline comments as done.

Address comments, move FPClassTest functions (FPClassTest needs additional cleanups to get it into the llvm namespace and use BitmaskEnum(

foad added a subscriber: foad.Feb 15 2023, 5:40 AM
foad added inline comments.
llvm/include/llvm/Analysis/ValueTracking.h
258

You shouldn't need & fcAllFlags here.

arsenm added inline comments.Feb 15 2023, 5:42 AM
llvm/include/llvm/Analysis/ValueTracking.h
224–228

Annoyingly operator &/|/^ don't work on std::optional<bool> so I think this made some of the patch a bit uglier

llvm/lib/Analysis/ValueTracking.cpp
4234–4236

knownNot?

arsenm updated this revision to Diff 500160.Feb 24 2023, 5:28 AM

Clean up a few more casts now that BitmaskEnum works for FPClassTest

arsenm updated this revision to Diff 501303.Feb 28 2023, 3:13 PM

Move classify to APFloat

nikic added inline comments.Mar 1 2023, 5:55 AM
llvm/include/llvm/ADT/FloatingPointMode.h
255 ↗(On Diff #501303)

Commit these NFC changes separately? It would be nice if they weren't part of the header though.

llvm/lib/Support/APFloat.cpp
5375 ↗(On Diff #501303)

Commit this separately (with more extensive unit test coverage)?

sepavloff added inline comments.Mar 1 2023, 9:04 PM
llvm/include/llvm/ADT/FloatingPointMode.h
255 ↗(On Diff #501303)

Both these functions require documentation about its meaning.

nikic added inline comments.Mar 9 2023, 5:37 AM
llvm/include/llvm/Analysis/ValueTracking.h
234

I don't understand your logic here. If & is supposed to be (doc comments?) an intersection, then if one side knows the sign bit and the other doesn't, shouldn't we be using the known sign bit?

It doesn't look like operator&= or commonBits() is actually used though. It may be worthwhile to split out this class into a separate header (like KnownBits) and unit test it.

arsenm added inline comments.Mar 9 2023, 5:41 AM
llvm/include/llvm/Analysis/ValueTracking.h
234

If you don't know one of the sign bits you don't know anything. & should only return true if we know both sign bits must be true

nikic added inline comments.Mar 9 2023, 5:46 AM
llvm/include/llvm/Analysis/ValueTracking.h
234

Isn't that inconsistent with what you do with the FP classes? Say the left one is fcNegative | fcPositive with SignBit unknown and the right one is fcPositive with SignBit one. Now I would expect & to return fcPositive with SignBit one, but you return fcPositive with SignBit unknown.

(I'm assuming you aren't treating & as a literally a bitwise operation on the bitwise float representation, because then the FP class handling makes no sense.)

arsenm added inline comments.Mar 9 2023, 5:52 AM
llvm/include/llvm/Analysis/ValueTracking.h
234

There are additional fixups for the known sign bit implied by the mask, like your example. This should be conservatively correct as-is. But since it's unused I can just drop this and sort it out later

jcranmer-intel added inline comments.Mar 9 2023, 1:39 PM
llvm/include/llvm/Analysis/ValueTracking.h
234

I'm with nikic here--the natural interpretation of &/| for this datastructure is intersection/union of knowledge, and the sign bit handling in & seems out-of-place compared to in other places. Without seeing uses of this method, it's not clear to me why the unknown-if-either-is-unknown should be correct for &.

jcranmer-intel added inline comments.Mar 9 2023, 1:47 PM
llvm/lib/Analysis/ValueTracking.cpp
4244–4245

Redundant with the make_scope_exit, no?

arsenm updated this revision to Diff 505255.Mar 14 2023, 2:13 PM
arsenm marked an inline comment as done.

Drop unused operator &, remove redundant flag part

arsenm updated this revision to Diff 505263.Mar 14 2023, 2:28 PM

cleanup & fcAllFlags in tests

arsenm updated this revision to Diff 505269.Mar 14 2023, 2:46 PM

Clean up another & fcAllFlags

jcranmer-intel accepted this revision.Mar 16 2023, 1:41 PM
This revision is now accepted and ready to land.Mar 16 2023, 1:41 PM