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/unittests/MIR/MachineMetadata.cpp b/llvm/unittests/MIR/MachineMetadata.cpp --- a/llvm/unittests/MIR/MachineMetadata.cpp +++ b/llvm/unittests/MIR/MachineMetadata.cpp @@ -537,3 +537,65 @@ )"; EXPECT_TRUE(checkOutput(CheckString, Output)); } + +TEST_F(MachineMetadataTest, TiedOpsRewritten) { + auto TM = createTargetMachine(Triple::normalize("powerpc64--"), "", ""); + if (!TM) + GTEST_SKIP(); + StringRef MIRString = R"MIR( +--- +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 + +... +)MIR"; + MachineModuleInfo MMI(TM.get()); + M = parseMIR(*TM, MIRString, "foo", MMI); + ASSERT_TRUE(M); + auto *MF = MMI.getMachineFunction(*M->getFunction("foo")); + MachineFunctionProperties &Properties = MF->getProperties(); + ASSERT_TRUE(Properties.hasProperty( + MachineFunctionProperties::Property::TiedOpsRewritten)); +} + +TEST_F(MachineMetadataTest, NoTiedOpsRewritten) { + auto TM = createTargetMachine(Triple::normalize("powerpc64--"), "", ""); + if (!TM) + GTEST_SKIP(); + StringRef MIRString = R"MIR( +--- +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 + +... +)MIR"; + MachineModuleInfo MMI(TM.get()); + M = parseMIR(*TM, MIRString, "foo", MMI); + ASSERT_TRUE(M); + auto *MF = MMI.getMachineFunction(*M->getFunction("foo")); + MachineFunctionProperties &Properties = MF->getProperties(); + ASSERT_FALSE(Properties.hasProperty( + MachineFunctionProperties::Property::TiedOpsRewritten)); +}