Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 27e656c

Browse files
committed
InstSimplify: ((X % Y) % Y) -> (X % Y)
Patch by Sonam Kumari! Differential Revision: http://reviews.llvm.org/D5350 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217937 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 22d885d commit 27e656c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/Analysis/InstructionSimplify.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,11 @@ static Value *SimplifyRem(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1,
11711171
if (Op0 == Op1)
11721172
return Constant::getNullValue(Op0->getType());
11731173

1174+
// ((X % Y) % Y) -> (X % Y)
1175+
if (match(Op0, m_SRem(m_Value(), m_Specific(Op1)))) {
1176+
return Op0;
1177+
}
1178+
11741179
// If the operation is with the result of a select instruction, check whether
11751180
// operating on either branch of the select always yields the same value.
11761181
if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))

test/Transforms/InstSimplify/rem.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,12 @@ define i32 @select2(i32 %x, i1 %b) {
1515
ret i32 %rem
1616
; CHECK: ret i32 0
1717
}
18+
19+
define i32 @select3(i32 %x, i32 %n) {
20+
; CHECK-LABEL: @select3(
21+
; CHECK-NEXT: %mod = srem i32 %x, %n
22+
; CHECK-NEXT: ret i32 %mod
23+
%mod = srem i32 %x, %n
24+
%mod1 = srem i32 %mod, %n
25+
ret i32 %mod1
26+
}

0 commit comments

Comments
 (0)