Skip to content

Commit 1ff9aa2

Browse files
nikictstellar
authored andcommitted
[IR] Handle constant expressions in containsUndefinedElement()
If the constant is a constant expression, then getAggregateElement() will return null. Guard against this before calling HasFn(). (cherry picked from commit af382b9)
1 parent 84a3be8 commit 1ff9aa2

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

llvm/lib/IR/Constants.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,11 @@ containsUndefinedElement(const Constant *C,
315315
return false;
316316

317317
for (unsigned i = 0, e = cast<FixedVectorType>(VTy)->getNumElements();
318-
i != e; ++i)
319-
if (HasFn(C->getAggregateElement(i)))
320-
return true;
318+
i != e; ++i) {
319+
if (Constant *Elem = C->getAggregateElement(i))
320+
if (HasFn(Elem))
321+
return true;
322+
}
321323
}
322324

323325
return false;

llvm/test/Transforms/InstSimplify/ConstProp/vecreduce.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ define i32 @add_poison1() {
8787
ret i32 %x
8888
}
8989

90+
define i32 @add_constexpr() {
91+
; CHECK-LABEL: @add_constexpr(
92+
; CHECK-NEXT: [[X:%.*]] = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> bitcast (<4 x i64> <i64 0, i64 1, i64 2, i64 3> to <8 x i32>))
93+
; CHECK-NEXT: ret i32 [[X]]
94+
;
95+
%x = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> bitcast (<4 x i64> <i64 0, i64 1, i64 2, i64 3> to <8 x i32>))
96+
ret i32 %x
97+
}
98+
9099
define i32 @mul_0() {
91100
; CHECK-LABEL: @mul_0(
92101
; CHECK-NEXT: ret i32 0

0 commit comments

Comments
 (0)