[llvm] 46ccefb - [CVP] Fix APInt ctor assertion with i1 urem
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 5 01:03:46 PST 2024
Author: Nikita Popov
Date: 2024-11-05T10:03:37+01:00
New Revision: 46ccefb1236bf29b2d752715373d407f2d4c3d61
URL: https://github.com/llvm/llvm-project/commit/46ccefb1236bf29b2d752715373d407f2d4c3d61
DIFF: https://github.com/llvm/llvm-project/commit/46ccefb1236bf29b2d752715373d407f2d4c3d61.diff
LOG: [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).
Added:
Modified:
llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
llvm/test/Transforms/CorrelatedValuePropagation/urem.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
index f2856ae3bdf163..7f838340410b51 100644
--- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -831,9 +831,7 @@ static bool expandUDivOrURem(BinaryOperator *Instr, const ConstantRange &XCR,
// Even if we don't know X's range, the divisor may be so large, X can't ever
// be 2x larger than that. I.e. if divisor is always negative.
- if (!XCR.icmp(ICmpInst::ICMP_ULT,
- YCR.umul_sat(APInt(YCR.getBitWidth(), 2))) &&
- !YCR.isAllNegative())
+ if (!XCR.icmp(ICmpInst::ICMP_ULT, YCR.uadd_sat(YCR)) && !YCR.isAllNegative())
return false;
IRBuilder<> B(Instr);
diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/urem.ll b/llvm/test/Transforms/CorrelatedValuePropagation/urem.ll
index ec6461e29f1917..e69deaa73d73bb 100644
--- a/llvm/test/Transforms/CorrelatedValuePropagation/urem.ll
+++ b/llvm/test/Transforms/CorrelatedValuePropagation/urem.ll
@@ -462,4 +462,13 @@ join:
ret i8 %res
}
+define i1 @urem_i1() {
+; CHECK-LABEL: @urem_i1(
+; CHECK-NEXT: [[REM:%.*]] = urem i1 false, false
+; CHECK-NEXT: ret i1 [[REM]]
+;
+ %rem = urem i1 false, false
+ ret i1 %rem
+}
+
declare void @use(i1)
More information about the llvm-commits
mailing list