diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 6d302f98f55f..6a8cd2eb3b16 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -3307,6 +3307,12 @@ void SelectionDAGBuilder::visitInsertValue(const InsertValueInst &I) { unsigned NumValValues = ValValueVTs.size(); SmallVector Values(NumAggValues); + // Ignore an insertvalue that produces an empty object + if (!NumAggValues) { + setValue(&I, DAG.getUNDEF(MVT(MVT::Other))); + return; + } + SDValue Agg = getValue(Op0); unsigned i = 0; // Copy the beginning value(s) from the original aggregate. diff --git a/llvm/test/CodeGen/Generic/empty-insertvalue.ll b/llvm/test/CodeGen/Generic/empty-insertvalue.ll new file mode 100644 index 000000000000..e4cc27c2ffcf --- /dev/null +++ b/llvm/test/CodeGen/Generic/empty-insertvalue.ll @@ -0,0 +1,7 @@ +; RUN: llc < %s + +define void @f() { +entry: + %0 = insertvalue { [0 x { i8*, i8* }], [0 x { i8*, i64 }] } undef, [0 x { i8*, i8* }] undef, 0 + ret void +}