diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp --- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp @@ -350,12 +350,22 @@ bool HasPHI = false; bool HasInlineAsm = false; + bool AllTiedOpsRewritten = true; for (const MachineBasicBlock &MBB : MF) { for (const MachineInstr &MI : MBB) { if (MI.isPHI()) HasPHI = true; if (MI.isInlineAsm()) HasInlineAsm = true; + for (unsigned I = 0; I < MI.getNumOperands(); ++I) { + unsigned DefIdx; + const MachineOperand &MO = MI.getOperand(I); + if (!MO.isReg() || !MO.getReg()) + continue; + if (MO.isUse() && MI.isRegTiedToDefOperand(I, &DefIdx) && + MO.getReg() != MI.getOperand(DefIdx).getReg()) + AllTiedOpsRewritten = false; + } } } if (!HasPHI) @@ -364,8 +374,11 @@ if (isSSA(MF)) Properties.set(MachineFunctionProperties::Property::IsSSA); - else + else { Properties.reset(MachineFunctionProperties::Property::IsSSA); + if (AllTiedOpsRewritten) + Properties.set(MachineFunctionProperties::Property::TiedOpsRewritten); + } const MachineRegisterInfo &MRI = MF.getRegInfo(); if (MRI.getNumVirtRegs() == 0) diff --git a/llvm/test/CodeGen/PowerPC/tied-ops-rewritten-prop-fail.mir b/llvm/test/CodeGen/PowerPC/tied-ops-rewritten-prop-fail.mir new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/PowerPC/tied-ops-rewritten-prop-fail.mir @@ -0,0 +1,21 @@ +# RUN: not --crash llc -verify-machineinstrs -mtriple=powerpc64-unknown-unknown \ +# RUN: -start-after=twoaddressinstruction -regalloc=fast %s -o - 2>&1 | FileCheck %s + +# Expect register allocator unable to handle tied-ops to fail in this test. +--- +name: foo +alignment: 16 +tracksRegLiveness: true +frameInfo: + maxAlignment: 16 +machineFunctionInfo: {} +body: | + bb.0: + liveins: $r3 + %0:gprc = COPY $r3 + %1:gprc = RLWIMI killed %0, $r3, 1, 0, 30 + $r3 = COPY %1 + BLR8 implicit $r3, implicit $lr8, implicit $rm + +... +# CHECK: !MO.isTied() && "tied op should be allocated" diff --git a/llvm/test/CodeGen/PowerPC/tied-ops-rewritten-prop.mir b/llvm/test/CodeGen/PowerPC/tied-ops-rewritten-prop.mir new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/PowerPC/tied-ops-rewritten-prop.mir @@ -0,0 +1,23 @@ +# RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-unknown \ +# RUN: -start-after=twoaddressinstruction -regalloc=fast %s -o - | FileCheck %s + +--- +name: foo +alignment: 16 +tracksRegLiveness: true +frameInfo: + maxAlignment: 16 +machineFunctionInfo: {} +body: | + bb.0: + liveins: $r3 + %0:gprc = COPY $r3 + %0 = RLWIMI killed %0, $r3, 1, 0, 30 + $r3 = COPY %0 + BLR8 implicit $r3, implicit $lr8, implicit $rm + +... + +# CHECK-LABEL: foo +# CHECK: rlwimi 4, 3, 1, 0, 30 +# CHECK: blr