[InstCombine] add a wrapper for a common pair of transforms; NFCI

Some of the callers are artificially limiting this transform to integer types;
this should make it easier to incrementally remove that restriction.

llvm-svn: 291620
This commit is contained in:
Sanjay Patel
2017-01-10 23:49:07 +00:00
parent 4f9d6d56c0
commit db0938fd9a
6 changed files with 44 additions and 75 deletions

View File

@@ -1371,15 +1371,9 @@ Instruction *InstCombiner::visitFAdd(BinaryOperator &I) {
SimplifyFAddInst(LHS, RHS, I.getFastMathFlags(), DL, &TLI, &DT, &AC))
return replaceInstUsesWith(I, V);
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;
}
if (isa<Constant>(RHS))
if (Instruction *FoldedFAdd = foldOpWithConstantIntoOperand(I))
return FoldedFAdd;
// -A + B --> B - A
// -A + -B --> -(A + B)