[llvm] [InstCombine] Fold more 'fcmp' 'select' instrs idioms into 'fabs' (PR #83381)

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 11 23:00:56 PDT 2024


sushgokh wrote:

1. Lets look at the unoptimized IR for motivating example('nofabs') and its slightly modified version('fabs') here: https://godbolt.org/z/cMe3ca38G
There are 2 aspects to consider here
   a) missing phi node from frontend: For 'nofabs', why are we not getting the phi node as we are getting it for 'fabs'? Modifying clang to generate phi node for 'nofabs' may solve this particular issue.
   
   b) fast math attributes on select/phi instructions: For the 'fabs', front end is probably deducing the fast math attribute from the fast-math flag and already setting it for phi node. In this sense, it wont be inappropriate to set the fast-math flags on the select instruction in 'nofabs' somehow. 
>Joshua's concern is that select and phi don't actually perform an operation, they are just data moving operations

So, I disagree with @jcranmer-intel **for now** considering his statement that select/phi are just data moving ops and that fast-math attributes be not placed on select/phi nodes.

2. Deducing fast-math attributes on the all the instructions just before inlining:
Why not do this similar to 1(b) above and as @nikic might be suggesting?

3. Fast-math attributes on the function parameters:
Is there  documentation somewhere that says if you have fast-math flag enabled at frontend, the fast-math attributes apply to function paramters as well? Also, having `nzero` on function parameter would disallow passing -0.0 as the function argument as the lang reference says:

>"This attribute applies to parameters and return values with floating-point and vector of floating-point types, as well as arrays of such types. The test mask has the same format as the second argument to the llvm.is.fpclass, and indicates which classes of floating-point values are not permitted for the value. For example a bitmask of 3 indicates the parameter may not be a NaN.
If the value is a floating-point class indicated by the nofpclass test mask, a poison value is passed or returned instead."

@andykaylor @jcranmer-intel what do you opine?

https://github.com/llvm/llvm-project/pull/83381


More information about the llvm-commits mailing list