[llvm] r187462 - Preserve fast-math flags when folding (fsub x, (fneg y)) to (fadd x, y).
Owen Anderson
resistor at mac.com
Tue Jul 30 16:53:18 PDT 2013
Author: resistor
Date: Tue Jul 30 18:53:17 2013
New Revision: 187462
URL: http://llvm.org/viewvc/llvm-project?rev=187462&view=rev
Log:
Preserve fast-math flags when folding (fsub x, (fneg y)) to (fadd x, y).
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/trunk/test/Transforms/InstCombine/fneg-ext.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp?rev=187462&r1=187461&r2=187462&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp Tue Jul 30 18:53:17 2013
@@ -1530,17 +1530,24 @@ Instruction *InstCombiner::visitFSub(Bin
// If this is a 'B = x-(-A)', change to B = x+A, potentially looking
// through FP extensions/truncations along the way.
- if (Value *V = dyn_castFNegVal(Op1))
- return BinaryOperator::CreateFAdd(Op0, V);
+ if (Value *V = dyn_castFNegVal(Op1)) {
+ Instruction *NewI = BinaryOperator::CreateFAdd(Op0, V);
+ NewI->copyFastMathFlags(&I);
+ return NewI;
+ }
if (FPTruncInst *FPTI = dyn_cast<FPTruncInst>(Op1)) {
if (Value *V = dyn_castFNegVal(FPTI->getOperand(0))) {
Value *NewTrunc = Builder->CreateFPTrunc(V, I.getType());
- return BinaryOperator::CreateFAdd(Op0, NewTrunc);
+ Instruction *NewI = BinaryOperator::CreateFAdd(Op0, NewTrunc);
+ NewI->copyFastMathFlags(&I);
+ return NewI;
}
} else if (FPExtInst *FPEI = dyn_cast<FPExtInst>(Op1)) {
if (Value *V = dyn_castFNegVal(FPEI->getOperand(0))) {
Value *NewExt = Builder->CreateFPExt(V, I.getType());
- return BinaryOperator::CreateFAdd(Op0, NewExt);
+ Instruction *NewI = BinaryOperator::CreateFAdd(Op0, NewExt);
+ NewI->copyFastMathFlags(&I);
+ return NewI;
}
}
Modified: llvm/trunk/test/Transforms/InstCombine/fneg-ext.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fneg-ext.ll?rev=187462&r1=187461&r2=187462&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fneg-ext.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fneg-ext.ll Tue Jul 30 18:53:17 2013
@@ -10,3 +10,14 @@ define double @test1(float %a, double %b
%3 = fsub double %b, %2
ret double %3
}
+
+; CHECK: test2
+define double @test2(float %a, double %b) nounwind readnone ssp uwtable {
+; CHECK-NOT: fsub
+; CHECK: fpext
+; CHECK: fadd fast
+ %1 = fsub float -0.000000e+00, %a
+ %2 = fpext float %1 to double
+ %3 = fsub fast double %b, %2
+ ret double %3
+}
More information about the llvm-commits
mailing list