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

via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 29 13:21:40 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-globalisel

Author: Dávid Ferenc Szabó (dfszabo)

<details>
<summary>Changes</summary>

…ergeLike

---
Full diff: https://github.com/llvm/llvm-project/pull/83483.diff


1 Files Affected:

- (modified) llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h (+9) 


``````````diff
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,

``````````

</details>


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


More information about the llvm-commits mailing list