/// operators which are associative or commutative.
bool SimplifyAssociativeOrCommutative(BinaryOperator &I);
- /// SimplifyDistributed - This tries to simplify binary operations which some
- /// other binary operation distributes over (eg "A*B+A*C" -> "A*(B+C)" since
- /// addition is distributed over by multiplication). Returns the result of
- /// the simplification, or null if no simplification was performed.
- Instruction *SimplifyDistributed(BinaryOperator &I);
+ /// SimplifyByFactorizing - This tries to simplify binary operations which
+ /// some other binary operation distributes over by factorizing out a common
+ /// term (eg "(A*B)+(A*C)" -> "A*(B+C)"). Returns the simplified value, or
+ /// null if no simplification was performed.
+ Instruction *SimplifyByFactorizing(BinaryOperator &I);
/// SimplifyDemandedUseBits - Attempts to replace V with a simpler value
/// based on the demanded bits.
I.hasNoUnsignedWrap(), TD))
return ReplaceInstUsesWith(I, V);
- if (Instruction *NV = SimplifyDistributed(I)) // (A*B)+(A*C) -> A*(B+C)
+ if (Instruction *NV = SimplifyByFactorizing(I)) // (A*B)+(A*C) -> A*(B+C)
return NV;
if (Constant *RHSC = dyn_cast<Constant>(RHS)) {
if (Op0 == Op1) // sub X, X -> 0
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
- if (Instruction *NV = SimplifyDistributed(I)) // (A*B)-(A*C) -> A*(B-C)
+ if (Instruction *NV = SimplifyByFactorizing(I)) // (A*B)-(A*C) -> A*(B-C)
return NV;
// If this is a 'B = x-(-A)', change to B = x+A. This preserves NSW/NUW.
if (Value *V = SimplifyAndInst(Op0, Op1, TD))
return ReplaceInstUsesWith(I, V);
- if (Instruction *NV = SimplifyDistributed(I)) // (A|B)&(A|C) -> A|(B&C)
+ if (Instruction *NV = SimplifyByFactorizing(I)) // (A|B)&(A|C) -> A|(B&C)
return NV;
// See if we can simplify any instructions used by the instruction whose sole
if (Value *V = SimplifyOrInst(Op0, Op1, TD))
return ReplaceInstUsesWith(I, V);
- if (Instruction *NV = SimplifyDistributed(I)) // (A&B)|(A&C) -> A&(B|C)
+ if (Instruction *NV = SimplifyByFactorizing(I)) // (A&B)|(A&C) -> A&(B|C)
return NV;
// See if we can simplify any instructions used by the instruction whose sole
if (Value *V = SimplifyXorInst(Op0, Op1, TD))
return ReplaceInstUsesWith(I, V);
- if (Instruction *NV = SimplifyDistributed(I)) // (A&B)^(A&C) -> A&(B^C)
+ if (Instruction *NV = SimplifyByFactorizing(I)) // (A&B)^(A&C) -> A&(B^C)
return NV;
// See if we can simplify any instructions used by the instruction whose sole
return false;
}
-/// SimplifyDistributed - This tries to simplify binary operations which some
-/// other binary operation distributes over (eg "A*B+A*C" -> "A*(B+C)" since
-/// addition is distributed over by multiplication). Returns the result of
-/// the simplification, or null if no simplification was performed.
-Instruction *InstCombiner::SimplifyDistributed(BinaryOperator &I) {
+/// SimplifyByFactorizing - This tries to simplify binary operations which
+/// some other binary operation distributes over by factorizing out a common
+/// term (eg "(A*B)+(A*C)" -> "A*(B+C)"). Returns the simplified value, or
+/// null if no simplification was performed.
+Instruction *InstCombiner::SimplifyByFactorizing(BinaryOperator &I) {
BinaryOperator *Op0 = dyn_cast<BinaryOperator>(I.getOperand(0));
BinaryOperator *Op1 = dyn_cast<BinaryOperator>(I.getOperand(1));
if (!Op0 || !Op1 || Op0->getOpcode() != Op1->getOpcode())