[InstSimplify] fold srem with sext bool divisor
llvm-svn: 335616
This commit is contained in:
parent
c307b00348
commit
2b7e31095d
|
@ -1099,6 +1099,12 @@ Value *llvm::SimplifyUDivInst(Value *Op0, Value *Op1, const SimplifyQuery &Q) {
|
||||||
/// If not, this returns null.
|
/// If not, this returns null.
|
||||||
static Value *SimplifySRemInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
|
static Value *SimplifySRemInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
|
||||||
unsigned MaxRecurse) {
|
unsigned MaxRecurse) {
|
||||||
|
// If the divisor is 0, the result is undefined, so assume the divisor is -1.
|
||||||
|
// srem Op0, (sext i1 X) --> srem Op0, -1 --> 0
|
||||||
|
Value *X;
|
||||||
|
if (match(Op1, m_SExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1))
|
||||||
|
return ConstantInt::getNullValue(Op0->getType());
|
||||||
|
|
||||||
return simplifyRem(Instruction::SRem, Op0, Op1, Q, MaxRecurse);
|
return simplifyRem(Instruction::SRem, Op0, Op1, Q, MaxRecurse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -309,9 +309,7 @@ define i32 @rem10(i32 %x, i32 %y) {
|
||||||
|
|
||||||
define i32 @srem_with_sext_bool_divisor(i1 %x, i32 %y) {
|
define i32 @srem_with_sext_bool_divisor(i1 %x, i32 %y) {
|
||||||
; CHECK-LABEL: @srem_with_sext_bool_divisor(
|
; CHECK-LABEL: @srem_with_sext_bool_divisor(
|
||||||
; CHECK-NEXT: [[S:%.*]] = sext i1 [[X:%.*]] to i32
|
; CHECK-NEXT: ret i32 0
|
||||||
; CHECK-NEXT: [[R:%.*]] = srem i32 [[Y:%.*]], [[S]]
|
|
||||||
; CHECK-NEXT: ret i32 [[R]]
|
|
||||||
;
|
;
|
||||||
%s = sext i1 %x to i32
|
%s = sext i1 %x to i32
|
||||||
%r = srem i32 %y, %s
|
%r = srem i32 %y, %s
|
||||||
|
@ -320,9 +318,7 @@ define i32 @srem_with_sext_bool_divisor(i1 %x, i32 %y) {
|
||||||
|
|
||||||
define <2 x i32> @srem_with_sext_bool_divisor_vec(<2 x i1> %x, <2 x i32> %y) {
|
define <2 x i32> @srem_with_sext_bool_divisor_vec(<2 x i1> %x, <2 x i32> %y) {
|
||||||
; CHECK-LABEL: @srem_with_sext_bool_divisor_vec(
|
; CHECK-LABEL: @srem_with_sext_bool_divisor_vec(
|
||||||
; CHECK-NEXT: [[S:%.*]] = sext <2 x i1> [[X:%.*]] to <2 x i32>
|
; CHECK-NEXT: ret <2 x i32> zeroinitializer
|
||||||
; CHECK-NEXT: [[R:%.*]] = srem <2 x i32> [[Y:%.*]], [[S]]
|
|
||||||
; CHECK-NEXT: ret <2 x i32> [[R]]
|
|
||||||
;
|
;
|
||||||
%s = sext <2 x i1> %x to <2 x i32>
|
%s = sext <2 x i1> %x to <2 x i32>
|
||||||
%r = srem <2 x i32> %y, %s
|
%r = srem <2 x i32> %y, %s
|
||||||
|
|
Loading…
Reference in New Issue