[llvm] [GlobalISel] Support physical register inputs in nested patterns (PR #121239)

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 28 06:42:03 PST 2024


================
@@ -1412,15 +1412,18 @@ Expected<BuildMIAction &> GlobalISelEmitter::createAndImportInstructionRenderer(
   action_iterator InsertPt = InsertPtOrError.get();
   BuildMIAction &DstMIBuilder = *static_cast<BuildMIAction *>(InsertPt->get());
 
-  for (auto PhysInput : InsnMatcher.getPhysRegInputs()) {
-    InsertPt = M.insertAction<BuildMIAction>(
-        InsertPt, M.allocateOutputInsnID(),
-        &Target.getInstruction(RK.getDef("COPY")));
-    BuildMIAction &CopyToPhysRegMIBuilder =
-        *static_cast<BuildMIAction *>(InsertPt->get());
-    CopyToPhysRegMIBuilder.addRenderer<AddRegisterRenderer>(
-        Target, PhysInput.first, true);
-    CopyToPhysRegMIBuilder.addRenderer<CopyPhysRegRenderer>(PhysInput.first);
+  for (auto PhysOp : M.physoperands()) {
+    auto &OpInsnMatcher = PhysOp.second->getInstructionMatcher();
+    for (auto PhysInput : OpInsnMatcher.getPhysRegInputs()) {
----------------
s-barannikov wrote:

> So should we have initially tracked the uniqueness of physical registers?

Yes, probably. But, a) support has been limited to simple patterns and b) SelectionDAG doesn't seem to unique them either. Uniqueness wasn't my point, please see below.

> We need this loop because two copies are required

Do we need both loops? I didn't try it but it looks like only the outer loop is required (?). The inner loop iterates over the same set of registers as the outer loop, so it looks like we will end up with four registers added instead of two. Am I missing something here?


https://github.com/llvm/llvm-project/pull/121239


More information about the llvm-commits mailing list