mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 11:02:59 +02:00
InstSimplify: ((X % Y) % Y) -> (X % Y)
Patch by Sonam Kumari! Differential Revision: http://reviews.llvm.org/D5350 llvm-svn: 217937
This commit is contained in:
parent
1cd062c7e5
commit
9a670c8293
@ -1171,6 +1171,11 @@ static Value *SimplifyRem(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1,
|
|||||||
if (Op0 == Op1)
|
if (Op0 == Op1)
|
||||||
return Constant::getNullValue(Op0->getType());
|
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
|
// 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.
|
// operating on either branch of the select always yields the same value.
|
||||||
if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
|
if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
|
||||||
|
@ -15,3 +15,12 @@ define i32 @select2(i32 %x, i1 %b) {
|
|||||||
ret i32 %rem
|
ret i32 %rem
|
||||||
; CHECK: ret i32 0
|
; 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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user