diff --git a/lib/IR/Constants.cpp b/lib/IR/Constants.cpp index 6c75085a667..1e72cb4d3a6 100644 --- a/lib/IR/Constants.cpp +++ b/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/test/Transforms/InstSimplify/ConstProp/vecreduce.ll b/test/Transforms/InstSimplify/ConstProp/vecreduce.ll index e27180b1a89..b407c908cf2 100644 --- a/test/Transforms/InstSimplify/ConstProp/vecreduce.ll +++ b/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