Skip to content

Commit 0fd0358

Browse files
nikicakiramenai
authored andcommitted
[CVP] Fix APInt ctor assertion with i1 urem
This is creating an APInt with value 2, which may not be well-defined for i1 values. Fix this by replacing the Y.umul_sat(2) with Y.uadd_sat(Y).
1 parent eeb1525 commit 0fd0358

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -832,9 +832,7 @@ static bool expandUDivOrURem(BinaryOperator *Instr, const ConstantRange &XCR,
832832

833833
// Even if we don't know X's range, the divisor may be so large, X can't ever
834834
// be 2x larger than that. I.e. if divisor is always negative.
835-
if (!XCR.icmp(ICmpInst::ICMP_ULT,
836-
YCR.umul_sat(APInt(YCR.getBitWidth(), 2))) &&
837-
!YCR.isAllNegative())
835+
if (!XCR.icmp(ICmpInst::ICMP_ULT, YCR.uadd_sat(YCR)) && !YCR.isAllNegative())
838836
return false;
839837

840838
IRBuilder<> B(Instr);

llvm/test/Transforms/CorrelatedValuePropagation/urem.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,4 +462,13 @@ join:
462462
ret i8 %res
463463
}
464464

465+
define i1 @urem_i1() {
466+
; CHECK-LABEL: @urem_i1(
467+
; CHECK-NEXT: [[REM:%.*]] = urem i1 false, false
468+
; CHECK-NEXT: ret i1 [[REM]]
469+
;
470+
%rem = urem i1 false, false
471+
ret i1 %rem
472+
}
473+
465474
declare void @use(i1)

0 commit comments

Comments
 (0)