Skip to content

Commit 46ccefb

Browse files
committed
[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 dc62edf commit 46ccefb

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

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

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