This is an archive of the discontinued LLVM Phabricator instance.

InstCombine: Fold compare with smallest normal if input denormals are flushed
ClosedPublic

Authored by arsenm on Nov 4 2022, 10:02 AM.

Details

Summary

Try to simplify comparisons with the smallest normalized value. If
denormals will be treated as 0, we can simplify by using an equality
comparison with 0.

fcmp olt fabs(x), smallest_normalized_number -> fcmp oeq x, 0.0
fcmp ult fabs(x), smallest_normalized_number -> fcmp ueq x, 0.0
fcmp oge fabs(x), smallest_normalized_number -> fcmp one x, 0.0
fcmp ult fabs(x), smallest_normalized_number -> fcmp ueq x, 0.0

The device libraries have a few range checks that look like
this for denormal handling paths.

Diff Detail

Event Timeline

arsenm created this revision.Nov 4 2022, 10:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 4 2022, 10:02 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
arsenm requested review of this revision.Nov 4 2022, 10:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 4 2022, 10:02 AM
Herald added a subscriber: wdng. · View Herald Transcript
spatel added inline comments.Nov 6 2022, 6:31 AM
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
6799

In general, we haven't put Alive2 links in the code (because the top-level URL or the hashed short links might change some day?).

Links are in the test file too, so that's good enough?

llvm/test/Transforms/InstCombine/fcmp-denormals-are-zero.ll
9

Do the diffs in alignment have meaning?

If not, can we avoid that noise (by writing the minimal test for each pattern as a unique function or don't use a null ptr)?

arsenm updated this revision to Diff 473551.Nov 6 2022, 9:08 PM

Don't store to null

arsenm marked 2 inline comments as done.Nov 6 2022, 9:09 PM
spatel accepted this revision.Nov 7 2022, 5:33 AM

LGTM

This revision is now accepted and ready to land.Nov 7 2022, 5:33 AM