summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-04-16 15:19:24 +0000
committerSanjay Patel <spatel@rotateright.com>2018-04-16 15:19:24 +0000
commitd93b8a0740c8c5aecd53a7ffff1bff58647f2e20 (patch)
tree08ce785aceb41c4389024f96b50121a2039b9e19
parentc3d6e991f886c8f57c7f227dcd920a96bd30799c (diff)
downloadbcm5719-llvm-d93b8a0740c8c5aecd53a7ffff1bff58647f2e20.tar.gz
bcm5719-llvm-d93b8a0740c8c5aecd53a7ffff1bff58647f2e20.zip
[InstCombine] simplify getBinOpsForFactorization(); NFC
llvm-svn: 330129
-rw-r--r--llvm/lib/Transforms/InstCombine/InstructionCombining.cpp40
1 files changed, 15 insertions, 25 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index af4449a9dd2..d33fba852e7 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -486,37 +486,27 @@ static Value *getIdentityValue(Instruction::BinaryOps Opcode, Value *V) {
return ConstantExpr::getBinOpIdentity(Opcode, V->getType());
}
-/// This function factors binary ops which can be combined using distributive
-/// laws. This function tries to transform 'Op' based TopLevelOpcode to enable
-/// factorization e.g for ADD(SHL(X , 2), MUL(X, 5)), When this function called
-/// with TopLevelOpcode == Instruction::Add and Op = SHL(X, 2), transforms
-/// SHL(X, 2) to MUL(X, 4) i.e. returns Instruction::Mul with LHS set to 'X' and
-/// RHS to 4.
+/// This function predicates factorization using distributive laws. By default,
+/// it just returns the 'Op' inputs. But for special-cases like
+/// 'add(shl(X, 5), ...)', this function will have TopOpcode == Instruction::Add
+/// and Op = shl(X, 5). The 'shl' is treated as the more general 'mul X, 32' to
+/// allow more factorization opportunities.
static Instruction::BinaryOps
-getBinOpsForFactorization(Instruction::BinaryOps TopLevelOpcode,
- BinaryOperator *Op, Value *&LHS, Value *&RHS) {
+getBinOpsForFactorization(Instruction::BinaryOps TopOpcode, BinaryOperator *Op,
+ Value *&LHS, Value *&RHS) {
assert(Op && "Expected a binary operator");
-
LHS = Op->getOperand(0);
RHS = Op->getOperand(1);
-
- switch (TopLevelOpcode) {
- default:
- return Op->getOpcode();
-
- case Instruction::Add:
- case Instruction::Sub:
- if (Op->getOpcode() == Instruction::Shl) {
- if (Constant *CST = dyn_cast<Constant>(Op->getOperand(1))) {
- // The multiplier is really 1 << CST.
- RHS = ConstantExpr::getShl(ConstantInt::get(Op->getType(), 1), CST);
- return Instruction::Mul;
- }
+ if (TopOpcode == Instruction::Add || TopOpcode == Instruction::Sub) {
+ Constant *C;
+ if (match(Op, m_Shl(m_Value(), m_Constant(C)))) {
+ // X << C --> X * (1 << C)
+ RHS = ConstantExpr::getShl(ConstantInt::get(Op->getType(), 1), C);
+ return Instruction::Mul;
}
- return Op->getOpcode();
+ // TODO: We can add other conversions e.g. shr => div etc.
}
-
- // TODO: We can add other conversions e.g. shr => div etc.
+ return Op->getOpcode();
}
/// This tries to simplify binary operations by factorizing out common terms
OpenPOWER on IntegriCloud