[llvm] 04c711c - [ConstraintElimination] Make sure the variable is available before use.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 30 10:09:23 PDT 2022
Author: Florian Hahn
Date: 2022-09-30T18:09:01+01:00
New Revision: 04c711c78d2d2c9239b7e0c65a7a3c07d3bd89ed
URL: https://github.com/llvm/llvm-project/commit/04c711c78d2d2c9239b7e0c65a7a3c07d3bd89ed
DIFF: https://github.com/llvm/llvm-project/commit/04c711c78d2d2c9239b7e0c65a7a3c07d3bd89ed.diff
LOG: [ConstraintElimination] Make sure the variable is available before use.
This fixes a crash when trying to access an index for a value where we
don't have a known index.
Fixes #58009.
Added:
Modified:
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
llvm/test/Transforms/ConstraintElimination/zext.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index f2751e06ab59b..bc51c3b90b798 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -409,7 +409,8 @@ ConstraintInfo::getConstraint(CmpInst::Predicate Pred, Value *Op0, Value *Op1,
// Add extra constraints for variables that are known positive.
for (auto &KV : KnownPositiveVariables) {
- if (!KV.second)
+ if (!KV.second || (Value2Index.find(KV.first) == Value2Index.end() &&
+ NewIndices.find(KV.first) == NewIndices.end()))
continue;
SmallVector<int64_t, 8> C(Value2Index.size() + NewIndices.size() + 1, 0);
C[GetOrAddIndex(KV.first)] = -1;
diff --git a/llvm/test/Transforms/ConstraintElimination/zext.ll b/llvm/test/Transforms/ConstraintElimination/zext.ll
index 3162149d64877..1101ce27ca1a8 100644
--- a/llvm/test/Transforms/ConstraintElimination/zext.ll
+++ b/llvm/test/Transforms/ConstraintElimination/zext.ll
@@ -264,3 +264,26 @@ bb2:
%r.6 = xor i1 %r.5, %c.6
ret i1 %r.6
}
+
+define i1 @test_pr58009_const_zext() {
+entry:
+ %ext.t.1 = zext i1 true to i16
+ %ext.t.2 = zext i1 true to i16
+ %t.1 = icmp uge i16 %ext.t.1, %ext.t.2
+ %f.1 = icmp ugt i16 %ext.t.1, %ext.t.2
+ %res.1 = xor i1 %t.1, %f.1
+
+ %ext.f.1 = zext i1 false to i16
+ %ext.f.2 = zext i1 false to i16
+ %t.2 = icmp uge i16 %ext.f.1, %ext.f.2
+ %f.2 = icmp ugt i16 %ext.f.1, %ext.f.2
+ %res.2 = xor i1 %res.1, %t.2
+ %res.3 = xor i1 %res.2, %f.2
+
+ %t.3 = icmp ult i16 %ext.f.1, %ext.t.2
+ %f.3 = icmp ugt i16 %ext.f.1, %ext.t.2
+ %res.4 = xor i1 %res.3, %t.3
+ %res.5 = xor i1 %res.4, %f.3
+
+ ret i1 %res.5
+}
More information about the llvm-commits
mailing list