[llvm] 7a7a426 - [LVI] Fix insertelement of constexpr
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 2 01:21:17 PST 2024
Author: Nikita Popov
Date: 2024-12-02T10:21:09+01:00
New Revision: 7a7a426188eea0b181738436205759e13ad6fd7b
URL: https://github.com/llvm/llvm-project/commit/7a7a426188eea0b181738436205759e13ad6fd7b
DIFF: https://github.com/llvm/llvm-project/commit/7a7a426188eea0b181738436205759e13ad6fd7b.diff
LOG: [LVI] Fix insertelement of constexpr
Bail out when evaluating an insertelement of a constant expression.
Unlike other ValueLattice kinds, these don't have implicit splat
semantics and we end up with type mismatches. If we actually wanted
to handle these, we should actually evaluate the insertion via
constant folding. I'm not bothering with that, as these should
get constant folded on construction already.
Added:
Modified:
llvm/lib/Analysis/LazyValueInfo.cpp
llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp
index 42b04046ce10d3..c9849b86b664c8 100644
--- a/llvm/lib/Analysis/LazyValueInfo.cpp
+++ b/llvm/lib/Analysis/LazyValueInfo.cpp
@@ -1005,6 +1005,13 @@ LazyValueInfoImpl::solveBlockValueInsertElement(InsertElementInst *IEI,
if (!OptVecVal)
return std::nullopt;
+ // Bail out if the inserted element is a constant expression. Unlike other
+ // ValueLattice types, these are not considered an implicit splat when a
+ // vector type is used.
+ // We could call ConstantFoldInsertElementInstruction here to handle these.
+ if (OptEltVal->isConstant())
+ return ValueLatticeElement::getOverdefined();
+
Res.mergeIn(*OptVecVal);
return Res;
}
diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll b/llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll
index 5c6dead841b5b1..baf8f386a8cce3 100644
--- a/llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll
+++ b/llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll
@@ -352,3 +352,14 @@ define <2 x i1> @insertelement_fold2() {
%icmp1 = icmp slt <2 x i32> %ie1, <i32 1024, i32 1024>
ret <2 x i1> %icmp1
}
+
+ at g = external global i32
+
+define <2 x i16> @insertelement_constexpr() {
+; CHECK-LABEL: define <2 x i16> @insertelement_constexpr() {
+; CHECK-NEXT: [[INS:%.*]] = insertelement <2 x i16> poison, i16 ptrtoint (ptr @g to i16), i32 0
+; CHECK-NEXT: ret <2 x i16> [[INS]]
+;
+ %ins = insertelement <2 x i16> poison, i16 ptrtoint (ptr @g to i16), i32 0
+ ret <2 x i16> %ins
+}
More information about the llvm-commits
mailing list