InstCombine: Fold compare with smallest normal if input denormals are flushed
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Fri, 4 Nov 2022 01:26:59 +0000 (18:26 -0700)
committerMatt Arsenault <Matthew.Arsenault@amd.com>
Mon, 7 Nov 2022 15:16:47 +0000 (07:16 -0800)
commit0f68ffe1e2b2d4b518aebe14709aff253658cfb2
tree79b62311cb57167cd564618c474a134994f39cb1
parentb9b74fc6e98a6e9bd50a1882b839419c9a6577b2
InstCombine: Fold compare with smallest normal if input denormals are flushed

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.
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/fcmp-denormals-are-zero.ll