From: Sanjay Patel Date: Fri, 19 Dec 2014 16:44:08 +0000 (+0000) Subject: use -0.0 when creating an fneg instruction X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=7c5fa5087522e674c6a3b2396437285c62230ed9;p=oota-llvm.git 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224583 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/lib/Transforms/InstCombine/InstCombineAddSub.cpp index 39b71f37f8b..c2d2eec3fc3 100644 --- a/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -759,7 +759,7 @@ Value *FAddCombine::createFSub(Value *Opnd0, Value *Opnd1) { } Value *FAddCombine::createFNeg(Value *V) { - Value *Zero = cast(ConstantFP::get(V->getType(), 0.0)); + Value *Zero = cast(ConstantFP::getZeroValueForNegation(V->getType())); Value *NewV = createFSub(Zero, V); if (Instruction *I = dyn_cast(NewV)) createInstPostProc(I, true); // fneg's don't receive instruction numbers. diff --git a/test/Transforms/InstCombine/fast-math.ll b/test/Transforms/InstCombine/fast-math.ll index b0ec8952bb3..f39adba6560 100644 --- a/test/Transforms/InstCombine/fast-math.ll +++ b/test/Transforms/InstCombine/fast-math.ll @@ -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