Skip to content

Commit 7a7a426

Browse files
committed
[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.
1 parent 5100307 commit 7a7a426

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,13 @@ LazyValueInfoImpl::solveBlockValueInsertElement(InsertElementInst *IEI,
10051005
if (!OptVecVal)
10061006
return std::nullopt;
10071007

1008+
// Bail out if the inserted element is a constant expression. Unlike other
1009+
// ValueLattice types, these are not considered an implicit splat when a
1010+
// vector type is used.
1011+
// We could call ConstantFoldInsertElementInstruction here to handle these.
1012+
if (OptEltVal->isConstant())
1013+
return ValueLatticeElement::getOverdefined();
1014+
10081015
Res.mergeIn(*OptVecVal);
10091016
return Res;
10101017
}

llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,14 @@ define <2 x i1> @insertelement_fold2() {
352352
%icmp1 = icmp slt <2 x i32> %ie1, <i32 1024, i32 1024>
353353
ret <2 x i1> %icmp1
354354
}
355+
356+
@g = external global i32
357+
358+
define <2 x i16> @insertelement_constexpr() {
359+
; CHECK-LABEL: define <2 x i16> @insertelement_constexpr() {
360+
; CHECK-NEXT: [[INS:%.*]] = insertelement <2 x i16> poison, i16 ptrtoint (ptr @g to i16), i32 0
361+
; CHECK-NEXT: ret <2 x i16> [[INS]]
362+
;
363+
%ins = insertelement <2 x i16> poison, i16 ptrtoint (ptr @g to i16), i32 0
364+
ret <2 x i16> %ins
365+
}

0 commit comments

Comments
 (0)