diff options
author | David Majnemer <david.majnemer@gmail.com> | 2014-09-17 03:34:34 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2014-09-17 03:34:34 +0000 |
commit | ac717f0972b7bb1a138bbf3fdd7dd282462c6d49 (patch) | |
tree | 90e0f08d410de8a9655a1f7c920be6e8f60b1204 | |
parent | 85d5e6f25b4b8439e1fada9c2c46e9ab78bbb813 (diff) | |
download | bcm5719-llvm-ac717f0972b7bb1a138bbf3fdd7dd282462c6d49.tar.gz bcm5719-llvm-ac717f0972b7bb1a138bbf3fdd7dd282462c6d49.zip |
InstSimplify: ((X % Y) % Y) -> (X % Y)
Patch by Sonam Kumari!
Differential Revision: http://reviews.llvm.org/D5350
llvm-svn: 217937
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 5 | ||||
-rw-r--r-- | llvm/test/Transforms/InstSimplify/rem.ll | 9 |
2 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index a745d14ca42..039d8286ecb 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -1171,6 +1171,11 @@ 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)))) { + 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. if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1)) diff --git a/llvm/test/Transforms/InstSimplify/rem.ll b/llvm/test/Transforms/InstSimplify/rem.ll index 80fa8e7b483..b757ccd6e4d 100644 --- a/llvm/test/Transforms/InstSimplify/rem.ll +++ b/llvm/test/Transforms/InstSimplify/rem.ll @@ -15,3 +15,12 @@ define i32 @select2(i32 %x, i1 %b) { ret i32 %rem ; CHECK: ret i32 0 } + +define i32 @select3(i32 %x, i32 %n) { +; CHECK-LABEL: @select3( +; CHECK-NEXT: %mod = srem i32 %x, %n +; CHECK-NEXT: ret i32 %mod + %mod = srem i32 %x, %n + %mod1 = srem i32 %mod, %n + ret i32 %mod1 +} |