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

Sanjay Patel spatel at rotateright.com
Wed Sep 10 13:53:24 PDT 2014


>>! In D5222#7, @mcrosier wrote:
> Good question.  When I added support for unsafe-math I checked the instruction FPMath flags directly and not the function attributes.  That doesn't mean it couldn't work that way, I just didn't implement it that way.  Does this effect anything other than simplifying lit test creation?  If this is commonly done, please file a PR and I'll be happy to address it.

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.

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.

http://reviews.llvm.org/D5222






More information about the llvm-commits mailing list