aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2007-09-17 17:31:57 +0000
committerDan Gohman <gohman@apple.com>2007-09-17 17:31:57 +0000
commit5d066ff7f0845abd224a4b60cd9bf9f7516b04a6 (patch)
tree532b1fb10d73efd4bccdcdbe5bbe0cfc9060da4f /lib/Transforms
parentbaa2fa5823fe4598d158794711d88af21976c182 (diff)
Instcombine x-((x/y)*y) into a remainder operator.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42035 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 787a3d5ccf..55ef0a8098 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -2257,6 +2257,17 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
Constant *CP1 = Subtract(ConstantInt::get(I.getType(), 1), C2);
return BinaryOperator::createMul(Op0, CP1);
}
+
+ // X - ((X / Y) * Y) --> X % Y
+ if (Op1I->getOpcode() == Instruction::Mul)
+ if (Instruction *I = dyn_cast<Instruction>(Op1I->getOperand(0)))
+ if (Op0 == I->getOperand(0) &&
+ Op1I->getOperand(1) == I->getOperand(1)) {
+ if (I->getOpcode() == Instruction::SDiv)
+ return BinaryOperator::createSRem(Op0, Op1I->getOperand(1));
+ if (I->getOpcode() == Instruction::UDiv)
+ return BinaryOperator::createURem(Op0, Op1I->getOperand(1));
+ }
}
}
@@ -2902,7 +2913,7 @@ static unsigned getICmpCode(const ICmpInst *ICI) {
/// getICmpValue - This is the complement of getICmpCode, which turns an
/// opcode and two operands into either a constant true or false, or a brand
-/// new /// ICmp instruction. The sign is passed in to determine which kind
+/// new ICmp instruction. The sign is passed in to determine which kind
/// of predicate to use in new icmp instructions.
static Value *getICmpValue(bool sign, unsigned code, Value *LHS, Value *RHS) {
switch (code) {