aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-09-17 04:16:35 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-09-17 04:16:35 +0000
commitb435a4214e5920e56dd2e9fb5fb29bb2d4e98fab (patch)
treeded4fd97a32f32c0f9007df848fb85b2d56b2e20 /llvm/lib/Analysis/InstructionSimplify.cpp
parent29298664d907ad227991075add40b46893867930 (diff)
downloadllvm-b435a4214e5920e56dd2e9fb5fb29bb2d4e98fab.zip
llvm-b435a4214e5920e56dd2e9fb5fb29bb2d4e98fab.tar.gz
llvm-b435a4214e5920e56dd2e9fb5fb29bb2d4e98fab.tar.bz2
InstSimplify: Don't allow (x srem y) urem y -> x srem y
Let's consider the case where: %x i16 = 32768 %y i16 = 384 %x srem %y = 65408 (%x srem %y) urem %y = 128 llvm-svn: 217939
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 039d828..f2f6706 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -1171,10 +1171,12 @@ static Value *SimplifyRem(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1,
if (Op0 == Op1)
return Constant::getNullValue(Op0->getType());
- // ((X % Y) % Y) -> (X % Y)
- if (match(Op0, m_SRem(m_Value(), m_Specific(Op1)))) {
+ // (X % Y) % Y -> X % Y
+ if ((Opcode == Instruction::SRem &&
+ match(Op0, m_SRem(m_Value(), m_Specific(Op1)))) ||
+ (Opcode == Instruction::URem &&
+ match(Op0, m_URem(m_Value(), m_Specific(Op1)))))
return Op0;
- }
// If the operation is with the result of a select instruction, check whether
// operating on either branch of the select always yields the same value.