[llvm] [GlobalISel] Disallow the creation of illegal UNMERGEs in tryCombineM… (PR #83483)

Dávid Ferenc Szabó via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 29 13:21:08 PST 2024


https://github.com/dfszabo created https://github.com/llvm/llvm-project/pull/83483

…ergeLike

>From 4a4cc9e92b8e40a851780d002d3316517759581b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?D=C3=A1vid=20Ferenc=20Szab=C3=B3?=
 <szabodavidferenc at gmail.com>
Date: Thu, 29 Feb 2024 21:22:34 +0100
Subject: [PATCH] [GlobalISel] Disallow the creation of illegal UNMERGEs in
 tryCombineMergeLike

---
 .../CodeGen/GlobalISel/LegalizationArtifactCombiner.h    | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h b/llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
index da330b517c2801..7c615976fbba81 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
@@ -988,6 +988,15 @@ class LegalizationArtifactCombiner {
                                    EltSize, false))
           return false;
         MIB.setInstrAndDebugLoc(MI);
+
+        // Do not build an unmerge if it would be illegal for the target.
+        // Avoiding this way endless loop of creating illegal unmerge from
+        // multiple legal ones, then lowering it back to multiple ones since it
+        // is illegal.
+        if (!LI.isLegal(
+                {TargetOpcode::G_UNMERGE_VALUES, {DstTy, UnmergeSrcTy}}))
+          return false;
+
         auto NewUnmerge = MIB.buildUnmerge(DstTy, Unmerge->getSourceReg());
         unsigned DstIdx = (Elt0UnmergeIdx * EltSize) / DstTy.getSizeInBits();
         replaceRegOrBuildCopy(Dst, NewUnmerge.getReg(DstIdx), MRI, MIB,



More information about the llvm-commits mailing list