Fix two cases where we could lose fast math flags when optimizing FADD expressions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199427 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson 2014-01-16 21:26:02 +00:00
parent 5d9450f92f
commit 5ee5e0c430
2 changed files with 30 additions and 4 deletions

View File

@ -1198,13 +1198,19 @@ Instruction *InstCombiner::visitFAdd(BinaryOperator &I) {
// -A + B --> B - A
// -A + -B --> -(A + B)
if (Value *LHSV = dyn_castFNegVal(LHS))
return BinaryOperator::CreateFSub(RHS, LHSV);
if (Value *LHSV = dyn_castFNegVal(LHS)) {
Instruction *RI = BinaryOperator::CreateFSub(RHS, LHSV);
RI->copyFastMathFlags(&I);
return RI;
}
// A + -B --> A - B
if (!isa<Constant>(RHS))
if (Value *V = dyn_castFNegVal(RHS))
return BinaryOperator::CreateFSub(LHS, V);
if (Value *V = dyn_castFNegVal(RHS)) {
Instruction *RI = BinaryOperator::CreateFSub(LHS, V);
RI->copyFastMathFlags(&I);
return RI;
}
// Check for (fadd double (sitofp x), y), see if we can merge this into an
// integer add followed by a promotion.

View File

@ -140,6 +140,26 @@ define float @fold13(float %x) {
; CHECK: ret
}
; -x + y => y - x
define float @fold14(float %x, float %y) {
%neg = fsub fast float -0.0, %x
%add = fadd fast float %neg, %y
ret float %add
; CHECK: fold14
; CHECK: fsub fast float %y, %x
; CHECK: ret
}
; x + -y => x - y
define float @fold15(float %x, float %y) {
%neg = fsub fast float -0.0, %y
%add = fadd fast float %x, %neg
ret float %add
; CHECK: fold15
; CHECK: fsub fast float %x, %y
; CHECK: ret
}
; =========================================================================
;
; Testing-cases about fmul begin