Skip to content

Commit 106a9cd

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 a953ef8 commit 106a9cd

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
@@ -836,9 +836,7 @@ static bool expandUDivOrURem(BinaryOperator *Instr, const ConstantRange &XCR,
836836

837837
// Even if we don't know X's range, the divisor may be so large, X can't ever
838838
// be 2x larger than that. I.e. if divisor is always negative.
839-
if (!XCR.icmp(ICmpInst::ICMP_ULT,
840-
YCR.umul_sat(APInt(YCR.getBitWidth(), 2))) &&
841-
!YCR.isAllNegative())
839+
if (!XCR.icmp(ICmpInst::ICMP_ULT, YCR.uadd_sat(YCR)) && !YCR.isAllNegative())
842840
return false;
843841

844842
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)