diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h --- a/llvm/include/llvm/CodeGen/MachineFunction.h +++ b/llvm/include/llvm/CodeGen/MachineFunction.h @@ -144,6 +144,8 @@ // operands, this also means that all generic virtual registers have been // constrained to virtual registers (assigned to register classes) and that // all sizes attached to them have been eliminated. + // RewriteTied: The twoaddressinstruction pass will set this flag, it means + // that tied-def have been rewritten to meet the RegConstraint. enum class Property : unsigned { IsSSA, NoPHIs, @@ -153,7 +155,8 @@ Legalized, RegBankSelected, Selected, - LastProperty = Selected, + RewriteTied, + LastProperty = RewriteTied, }; bool hasProperty(Property P) const { diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -98,6 +98,7 @@ case P::RegBankSelected: return "RegBankSelected"; case P::Selected: return "Selected"; case P::TracksLiveness: return "TracksLiveness"; + case P::RewriteTied: return "RewriteTied"; } llvm_unreachable("Invalid machine function property"); } diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp --- a/llvm/lib/CodeGen/MachineVerifier.cpp +++ b/llvm/lib/CodeGen/MachineVerifier.cpp @@ -1654,10 +1654,11 @@ } } - // Verify two-address constraints after leaving SSA form. + // Verify two-address constraints after the twoaddressinstruction pass. unsigned DefIdx; - if (!MRI->isSSA() && MO->isUse() && - MI->isRegTiedToDefOperand(MONum, &DefIdx) && + if (MF->getProperties().hasProperty( + MachineFunctionProperties::Property::RewriteTied) && + MO->isUse() && MI->isRegTiedToDefOperand(MONum, &DefIdx) && Reg != MI->getOperand(DefIdx).getReg()) report("Two-address instruction operands must be identical", MO, MONum); diff --git a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp --- a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp +++ b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp @@ -1687,6 +1687,9 @@ // This pass takes the function out of SSA form. MRI->leaveSSA(); + // This pass will rewrite the tied-def to meet the RegConstraint. + MF->getProperties().set(MachineFunctionProperties::Property::RewriteTied); + TiedOperandMap TiedOperands; for (MachineFunction::iterator MBBI = MF->begin(), MBBE = MF->end(); MBBI != MBBE; ++MBBI) { diff --git a/llvm/test/CodeGen/PowerPC/two-address-crash.mir b/llvm/test/CodeGen/PowerPC/two-address-crash.mir --- a/llvm/test/CodeGen/PowerPC/two-address-crash.mir +++ b/llvm/test/CodeGen/PowerPC/two-address-crash.mir @@ -1,5 +1,5 @@ -# RUN: not --crash llc -mtriple=ppc32-- %s -run-pass=phi-node-elimination \ -# RUN: -verify-machineinstrs -o /dev/null 2>&1 | FileCheck %s +# RUN: llc -mtriple=ppc32-- %s -run-pass=phi-node-elimination \ +# RUN: -verify-machineinstrs -o /dev/null 2>&1 --- | define void @VerifyTwoAddressCrash(i16 %div.0.i.i.i.i, i32 %L_num.0.i.i.i.i, i32 %tmp1.i.i206.i.i, i16* %P) { @@ -36,10 +36,13 @@ BLR implicit $lr, implicit $rm ... - -# CHECK-LABEL: Bad machine code: Two-address instruction operands must be identical -# CHECK-NEXT: - function: VerifyTwoAddressCrash -# CHECK-NEXT: - basic block: %bb.0 -# CHECK-NEXT: - instruction: %10:gprc = RLWIMI killed %9:gprc(tied-def 0), killed %3:gprc, 1, 0, 30 -# CHECK-NEXT: - operand 1: killed %9:gprc(tied-def 0) -# CHECK-NEXT: LLVM ERROR: Found 1 machine code errors. +# Used to result in +# +# Bad machine code: Two-address instruction operands must be identical +# - function: VerifyTwoAddressCrash +# - basic block: %bb.0 +# - instruction: %10:gprc = RLWIMI killed %9:gprc(tied-def 0), killed %3:gprc, 1, 0, 30 +# - operand 1: killed %9:gprc(tied-def 0) +# LLVM ERROR: Found 1 machine code errors. +# +# Just verify that we do not crash (or get verifier error).