mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-19 18:24:00 +00:00
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217939 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -1171,10 +1171,12 @@ 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)
|
// (X % Y) % Y -> X % Y
|
||||||
if (match(Op0, m_SRem(m_Value(), m_Specific(Op1)))) {
|
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;
|
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.
|
||||||
|
@ -16,11 +16,30 @@ define i32 @select2(i32 %x, i1 %b) {
|
|||||||
; CHECK: ret i32 0
|
; CHECK: ret i32 0
|
||||||
}
|
}
|
||||||
|
|
||||||
define i32 @select3(i32 %x, i32 %n) {
|
define i32 @rem1(i32 %x, i32 %n) {
|
||||||
; CHECK-LABEL: @select3(
|
; CHECK-LABEL: @rem1(
|
||||||
; CHECK-NEXT: %mod = srem i32 %x, %n
|
; CHECK-NEXT: %mod = srem i32 %x, %n
|
||||||
; CHECK-NEXT: ret i32 %mod
|
; CHECK-NEXT: ret i32 %mod
|
||||||
%mod = srem i32 %x, %n
|
%mod = srem i32 %x, %n
|
||||||
%mod1 = srem i32 %mod, %n
|
%mod1 = srem i32 %mod, %n
|
||||||
ret i32 %mod1
|
ret i32 %mod1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define i32 @rem2(i32 %x, i32 %n) {
|
||||||
|
; CHECK-LABEL: @rem2(
|
||||||
|
; CHECK-NEXT: %mod = urem i32 %x, %n
|
||||||
|
; CHECK-NEXT: ret i32 %mod
|
||||||
|
%mod = urem i32 %x, %n
|
||||||
|
%mod1 = urem i32 %mod, %n
|
||||||
|
ret i32 %mod1
|
||||||
|
}
|
||||||
|
|
||||||
|
define i32 @rem3(i32 %x, i32 %n) {
|
||||||
|
; CHECK-LABEL: @rem3(
|
||||||
|
; CHECK-NEXT: %[[srem:.*]] = srem i32 %x, %n
|
||||||
|
; CHECK-NEXT: %[[urem:.*]] = urem i32 %[[srem]], %n
|
||||||
|
; CHECK-NEXT: ret i32 %[[urem]]
|
||||||
|
%mod = srem i32 %x, %n
|
||||||
|
%mod1 = urem i32 %mod, %n
|
||||||
|
ret i32 %mod1
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user