[llvm] r224583 - use -0.0 when creating an fneg instruction

David Majnemer david.majnemer at gmail.com
Fri Dec 19 09:05:31 PST 2014


This improves things when forming fneg but what if we see fsub 0.00, %V in
the IR? Shouldn't we add a canonicalization for that?

On Fri, Dec 19, 2014 at 11:44 AM, Sanjay Patel <spatel at rotateright.com>
wrote:
>
> Author: spatel
> Date: Fri Dec 19 10:44:08 2014
> New Revision: 224583
>
> URL: http://llvm.org/viewvc/llvm-project?rev=224583&view=rev
> Log:
> use -0.0 when creating an fneg instruction
>
> Backends recognize (-0.0 - X) as the canonical form for fneg
> and produce better code. Eg, ppc64 with 0.0:
>
>    lis r2, ha16(LCPI0_0)
>    lfs f0, lo16(LCPI0_0)(r2)
>    fsubs f1, f0, f1
>    blr
>
> vs. -0.0:
>
>    fneg f1, f1
>    blr
>
> Differential Revision: http://reviews.llvm.org/D6723
>
>
> Modified:
>     llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
>     llvm/trunk/test/Transforms/InstCombine/fast-math.ll
>
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp?rev=224583&r1=224582&r2=224583&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp Fri Dec 19
> 10:44:08 2014
> @@ -759,7 +759,7 @@ Value *FAddCombine::createFSub(Value *Op
>  }
>
>  Value *FAddCombine::createFNeg(Value *V) {
> -  Value *Zero = cast<Value>(ConstantFP::get(V->getType(), 0.0));
> +  Value *Zero =
> cast<Value>(ConstantFP::getZeroValueForNegation(V->getType()));
>    Value *NewV = createFSub(Zero, V);
>    if (Instruction *I = dyn_cast<Instruction>(NewV))
>      createInstPostProc(I, true); // fneg's don't receive instruction
> numbers.
>
> Modified: llvm/trunk/test/Transforms/InstCombine/fast-math.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fast-math.ll?rev=224583&r1=224582&r2=224583&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/fast-math.ll (original)
> +++ llvm/trunk/test/Transforms/InstCombine/fast-math.ll Fri Dec 19
> 10:44:08 2014
> @@ -93,7 +93,7 @@ define float @fold9(float %f1, float %f2
>    ret float %t3
>
>  ; CHECK-LABEL: @fold9(
> -; CHECK: fsub fast float 0.000000e+00, %f2
> +; CHECK: fsub fast float -0.000000e+00, %f2
>  }
>
>  ; Let C3 = C1 + C2. (f1 + C1) + (f2 + C2) => (f1 + f2) + C3 instead of
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141219/b48cb6e9/attachment.html>


More information about the llvm-commits mailing list