diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 6c75085a6678dc..1e72cb4d3a6684 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -315,9 +315,11 @@ containsUndefinedElement(const Constant *C, return false; for (unsigned i = 0, e = cast(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; diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/vecreduce.ll b/llvm/test/Transforms/InstSimplify/ConstProp/vecreduce.ll index e27180b1a8909d..b407c908cf2a28 100644 --- a/llvm/test/Transforms/InstSimplify/ConstProp/vecreduce.ll +++ b/llvm/test/Transforms/InstSimplify/ConstProp/vecreduce.ll @@ -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> to <8 x i32>)) +; CHECK-NEXT: ret i32 [[X]] +; + %x = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> bitcast (<4 x i64> to <8 x i32>)) + ret i32 %x +} + define i32 @mul_0() { ; CHECK-LABEL: @mul_0( ; CHECK-NEXT: ret i32 0