InstCombine: call FoldOpIntoSelect for all floating binops, not just fmul

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186759 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Stephen Lin
2013-07-20 07:13:13 +00:00
parent ff29d235ed
commit a98ce503b9
3 changed files with 94 additions and 3 deletions
@@ -1186,9 +1186,15 @@ Instruction *InstCombiner::visitFAdd(BinaryOperator &I) {
if (Value *V = SimplifyFAddInst(LHS, RHS, I.getFastMathFlags(), TD))
return ReplaceInstUsesWith(I, V);
if (isa<Constant>(RHS) && isa<PHINode>(LHS))
if (Instruction *NV = FoldOpIntoPhi(I))
return NV;
if (isa<Constant>(RHS)) {
if (isa<PHINode>(LHS))
if (Instruction *NV = FoldOpIntoPhi(I))
return NV;
if (SelectInst *SI = dyn_cast<SelectInst>(LHS))
if (Instruction *NV = FoldOpIntoSelect(I, SI))
return NV;
}
// -A + B --> B - A
// -A + -B --> -(A + B)
@@ -1517,6 +1523,11 @@ Instruction *InstCombiner::visitFSub(BinaryOperator &I) {
if (Value *V = SimplifyFSubInst(Op0, Op1, I.getFastMathFlags(), TD))
return ReplaceInstUsesWith(I, V);
if (isa<Constant>(Op0))
if (SelectInst *SI = dyn_cast<SelectInst>(Op1))
if (Instruction *NV = FoldOpIntoSelect(I, SI))
return NV;
// If this is a 'B = x-(-A)', change to B = x+A...
if (Value *V = dyn_castFNegVal(Op1))
return BinaryOperator::CreateFAdd(Op0, V);