This is an archive of the discontinued LLVM Phabricator instance.

[ConstantFold] fp_binop AnyConstant, undef --> NaN

Authored by spatel on Mar 9 2018, 8:05 AM.



With the first update to the LangRef ( D44216 / rL327138 ) in place, we can proceed with more constant folding.

I'm intentionally taking the conservative path here: no matter what the constant or the FMF, we can always fold to NaN. This is because the undef operand can be chosen as NaN, and in our simplified default FP env, nothing else happens - NaN just propagates to the result. If we find some way/need to propagate undef instead, that can be added subsequently.

The tests show that we always choose the same quiet NaN constant (0x7FF8000000000000 in IR text). There were suggestions to improve that with a 'NaN' string token or not always print a 64-bit hex value, but those are independent changes. We might also consider setting/propagating the payload of NaN constants as an enhancement.

Diff Detail

Event Timeline

spatel created this revision.Mar 9 2018, 8:05 AM
arsenm added inline comments.Mar 9 2018, 8:07 AM

This is potentially a bad test change because this is now a divergent branch. Adding inreg to the parameter should fix it

spatel added inline comments.Mar 9 2018, 8:31 AM

Thanks - I didn't understand what was happening there. I'll fix it and remove this test from the patch.

spatel updated this revision to Diff 137760.Mar 9 2018, 8:40 AM

Patch updated:

  1. Fixed the AMDGPU test to not be affected ( rL327147 ).
  2. Fixed the 'Inf' constants in some tests to actually be 'Inf' ( rL327144 ).
majnemer accepted this revision.Mar 9 2018, 8:53 AM
majnemer added a subscriber: majnemer.


This revision is now accepted and ready to land.Mar 9 2018, 8:53 AM
This revision was automatically updated to reflect the committed changes.