[PATCH] [Reassocate] Add support for vector instructions.

Chad Rosier mcrosier at codeaurora.org
Wed Sep 10 14:38:18 PDT 2014


>>! In D5222#8, @spatel wrote:
> Here's what I see in clang: when you pass '-ffast-math', the IRBuilderBases's FastMathFlag has its UnsafeAlgebra bit set and that is used as a function attribute. The bit is then propagated to any created instruction in the function that is eligible (fmul, fadd, fsub, fdiv, frem) to have a 'fast' modifier. So in practice, it seems like we can use either variable to detect if '-ffast-math' was specified if you're only interested in optimizing those FP instructions, but I don't see an explicit guarantee or documentation about this.

Thanks for looking into how this all works.

> I think the case where detecting a 'fast' flag on an instruction is inadequate is when we're looking to optimize an FP intrinsic, such as square root:
>    float reciprocal_square_root(float x) {
>         return 1.0f / sqrtf(x);
>    }
> 
> With -ffast-math on, we should be able to turn that into 'rsqrtss' (x86) and a Newton-Raphson step, but there's no way to express 'fast' on an intrinsic in the IR, so we have to use a function-level attribute.

If and when the Reassociation pass starts playing with intrinsics, we should consider addressing this issue.  However, until that time the only advantage I see is that it would remove a few characters from the lit tests.

http://reviews.llvm.org/D5222






More information about the llvm-commits mailing list