Index: lib/CodeGen/ExpandPostRAPseudos.cpp =================================================================== --- lib/CodeGen/ExpandPostRAPseudos.cpp +++ lib/CodeGen/ExpandPostRAPseudos.cpp @@ -142,8 +142,9 @@ MachineOperand &DstMO = MI->getOperand(0); MachineOperand &SrcMO = MI->getOperand(1); - if (SrcMO.getReg() == DstMO.getReg()) { - DEBUG(dbgs() << "identity copy: " << *MI); + bool IdentityCopy = (SrcMO.getReg() == DstMO.getReg()); + if (IdentityCopy || SrcMO.isUndef()) { + DEBUG(dbgs() << (IdentityCopy ? "identity copy: " : "undef copy: ") << *MI); // No need to insert an identity copy instruction, but replace with a KILL // if liveness is changed. if (SrcMO.isUndef() || MI->getNumOperands() > 2) { Index: test/CodeGen/SystemZ/lower-copy-undef-src.ll =================================================================== --- /dev/null +++ test/CodeGen/SystemZ/lower-copy-undef-src.ll @@ -0,0 +1,43 @@ +; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z13 -join-liveintervals=false -verify-machineinstrs | FileCheck %s +; +; Test that a COPY with an undef source operand gets handled like an identity +; copy rather than lowered into a target instruction with the undef flag +; dropped. + +define void @autogen_SD13338(i8*, i32*, i64*, i32, i64, i8) { +; CHECK: .text +BB: + %L5 = load <4 x i32>, <4 x i32>* undef + %L30 = load i8, i8* %0 + %B42 = sdiv i64 undef, undef + %L45 = load <4 x i32>, <4 x i32>* undef + br label %CF284 + +CF284: ; preds = %CF284, %BB + %L52 = load i8, i8* %0 + %B56 = udiv i64 %B42, %4 + %Sl57 = select i1 true, i1 undef, i1 undef + br i1 %Sl57, label %CF284, label %CF294 + +CF294: ; preds = %CF284 + br label %CF + +CF: ; preds = %CF, %CF294 + %L94 = load i8, i8* %0 + store i8 0, i8* %0 + %B127 = urem <4 x i32> %L5, %L45 + %E132 = extractelement <4 x i1> zeroinitializer, i32 0 + br i1 %E132, label %CF, label %CF273 + +CF273: ; preds = %CF + %B150 = lshr i64 undef, %B56 + %B212 = xor <4 x i32> %L5, %B127 + %PC = bitcast i64* %2 to i8* + store i8 %L30, i8* %PC + store i8 %L94, i8* %PC + br label %CF275 + +CF275: ; preds = %CF275, %CF273 + store i8 %L52, i8* %PC + br label %CF275 +}