diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -10537,22 +10537,19 @@ } void SelectionDAGBuilder::visitFreeze(const FreezeInst &I) { - SDNodeFlags Flags; + SmallVector ValueVTs; + ComputeValueVTs(DAG.getTargetLoweringInfo(), DAG.getDataLayout(), I.getType(), + ValueVTs); + unsigned NumValues = ValueVTs.size(); + if (NumValues == 0) return; + SmallVector Values(NumValues); SDValue Op = getValue(I.getOperand(0)); - if (I.getOperand(0)->getType()->isAggregateType()) { - EVT VT = Op.getValueType(); - SmallVector Values; - for (unsigned i = 0; i < Op.getNumOperands(); ++i) { - SDValue Arg(Op.getNode(), i); - SDValue UnNodeValue = DAG.getNode(ISD::FREEZE, getCurSDLoc(), VT, Arg, Flags); - Values.push_back(UnNodeValue); - } - SDValue MergedValue = DAG.getMergeValues(Values, getCurSDLoc()); - setValue(&I, MergedValue); - } else { - SDValue UnNodeValue = DAG.getNode(ISD::FREEZE, getCurSDLoc(), Op.getValueType(), - Op, Flags); - setValue(&I, UnNodeValue); - } + + for (unsigned i = 0; i != NumValues; ++i) + Values[i] = DAG.getNode(ISD::FREEZE, getCurSDLoc(), ValueVTs[i], + SDValue(Op.getNode(), Op.getResNo() + i)); + + setValue(&I, DAG.getNode(ISD::MERGE_VALUES, getCurSDLoc(), + DAG.getVTList(ValueVTs), Values)); } diff --git a/llvm/test/CodeGen/X86/freeze.ll b/llvm/test/CodeGen/X86/freeze.ll --- a/llvm/test/CodeGen/X86/freeze.ll +++ b/llvm/test/CodeGen/X86/freeze.ll @@ -97,6 +97,20 @@ ret i32 %t1 } +define i32 @freeze_anonstruct2() { +; X86ASM-LABEL: freeze_anonstruct2: +; X86ASM: # %bb.0: +; X86ASM-NEXT: movzwl %ax, %eax +; X86ASM-NEXT: addl %eax, %eax +; X86ASM-NEXT: retq + %y1 = freeze {i32, i16} undef + %v1 = extractvalue {i32, i16} %y1, 0 + %v2 = extractvalue {i32, i16} %y1, 1 + %z2 = zext i16 %v2 to i32 + %t1 = add i32 %v1, %z2 + ret i32 %t1 +} + define i64 @freeze_array() { ; X86ASM-LABEL: freeze_array: ; X86ASM: # %bb.0: