From e995e34469be69d867dcf67935faead59feee9b1 Mon Sep 17 00:00:00 2001 From: David Green Date: Sun, 19 Jun 2022 18:55:19 +0100 Subject: [MachinePipeliner] Handle failing constrainRegClass The included test hits a verifier problems as one of the instructions: ``` %113:tgpreven, %114:tgprodd = MVE_VMLSLDAVas16 %12:tgpreven(tied-def 0), %11:tgprodd(tied-def 1), %7:mqpr, %8:mqpr, 0, $noreg, $noreg ``` Has two inputs that come from different PHIs with the same base reg, but conflicting regclasses: ``` %11:tgprodd = PHI %103:gpr, %bb.1, %16:gpr, %bb.2 %12:tgpreven = PHI %103:gpr, %bb.1, %17:gpr, %bb.2 ``` The MachinePipeliner would attempt to use %103 for both the %11 and %12 operands in the prolog, constraining the register class to the common subset of both. Unfortunately there are no registers that are both odd and even, so the second constrainRegClass fails. Fix this situation by inserting a COPY for the second if the call to constrainRegClass fails. The register allocation can then fold that extra copy away. The register allocation of Q regs changed with this test, but the R regs were the same and no new instructions are needed in the final assembly. Differential Revision: https://reviews.llvm.org/D127971 --- llvm/lib/CodeGen/MachineLoopUtils.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'llvm/lib/CodeGen/MachineLoopUtils.cpp') diff --git a/llvm/lib/CodeGen/MachineLoopUtils.cpp b/llvm/lib/CodeGen/MachineLoopUtils.cpp index 6d0f90f8af1e..bf7d26dda985 100644 --- a/llvm/lib/CodeGen/MachineLoopUtils.cpp +++ b/llvm/lib/CodeGen/MachineLoopUtils.cpp @@ -63,7 +63,10 @@ MachineBasicBlock *llvm::PeelSingleBlockLoop(LoopPeelDirection Direction, if (Use.getParent()->getParent() != Loop) Uses.push_back(&Use); for (auto *Use : Uses) { - MRI.constrainRegClass(R, MRI.getRegClass(Use->getReg())); + const TargetRegisterClass *ConstrainRegClass = + MRI.constrainRegClass(R, MRI.getRegClass(Use->getReg())); + assert(ConstrainRegClass && + "Expected a valid constrained register class!"); Use->setReg(R); } } -- cgit v1.2.3