Skip to content

Commit

Permalink
[IR] Handle constant expressions in containsUndefinedElement()
Browse files Browse the repository at this point in the history
If the constant is a constant expression, then getAggregateElement()
will return null. Guard against this before calling HasFn().

(cherry picked from commit af382b9)
  • Loading branch information
nikic authored and tstellar committed Sep 10, 2021
1 parent 84a3be8 commit 1ff9aa2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 5 additions & 3 deletions llvm/lib/IR/Constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,11 @@ containsUndefinedElement(const Constant *C,
return false;

for (unsigned i = 0, e = cast<FixedVectorType>(VTy)->getNumElements();
i != e; ++i)
if (HasFn(C->getAggregateElement(i)))
return true;
i != e; ++i) {
if (Constant *Elem = C->getAggregateElement(i))
if (HasFn(Elem))
return true;
}
}

return false;
Expand Down
9 changes: 9 additions & 0 deletions llvm/test/Transforms/InstSimplify/ConstProp/vecreduce.ll
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ define i32 @add_poison1() {
ret i32 %x
}

define i32 @add_constexpr() {
; CHECK-LABEL: @add_constexpr(
; 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>))
; CHECK-NEXT: ret i32 [[X]]
;
%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>))
ret i32 %x
}

define i32 @mul_0() {
; CHECK-LABEL: @mul_0(
; CHECK-NEXT: ret i32 0
Expand Down

0 comments on commit 1ff9aa2

Please sign in to comment.