[PATCH] D147780: [AMDGPU][Global-ISel] reuse extension related patterns

ChenZheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 7 03:34:16 PDT 2023


shchenz created this revision.
shchenz added reviewers: arsenm, Pierre-vh.
shchenz added a project: LLVM.
Herald added subscribers: kosarev, foad, kerbowa, hiraditya, tpr, dstuttard, yaxunl, jvesely, kzhuravl.
Herald added a project: All.
shchenz requested review of this revision.
Herald added subscribers: llvm-commits, wdng.

With the change in the td file, there will be new rules for extension related patterns in AMDGPU global isel MatchTable.

But we can not use these patterns in global isel for now as there seems some bug/limitation in `selectImpl()`, the select function will create an illegal copy from VGPR to SGPR.

So this patch also tries not to use these new added rules for now. This patch is needed because of many other rules in D141247 <https://reviews.llvm.org/D141247>.

Fixes #61468


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147780

Files:
  llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
  llvm/lib/Target/AMDGPU/SIInstructions.td


Index: llvm/lib/Target/AMDGPU/SIInstructions.td
===================================================================
--- llvm/lib/Target/AMDGPU/SIInstructions.td
+++ llvm/lib/Target/AMDGPU/SIInstructions.td
@@ -2020,13 +2020,13 @@
 def : GCNPat <
   (i32 (sext i1:$src0)),
   (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
-                     /*src1mod*/(i32 0), /*src1*/(i32 -1), $src0)
+                     /*src1mod*/(i32 0), /*src1*/(i32 -1), i1:$src0)
 >;
 
 class Ext32Pat <SDNode ext> : GCNPat <
   (i32 (ext i1:$src0)),
   (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0),
-                     /*src1mod*/(i32 0), /*src1*/(i32 1), $src0)
+                     /*src1mod*/(i32 0), /*src1*/(i32 1), i1:$src0)
 >;
 
 def : Ext32Pat <zext>;
Index: llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
@@ -3417,7 +3417,11 @@
   case TargetOpcode::G_ZEXT:
   case TargetOpcode::G_ANYEXT:
   case TargetOpcode::G_SEXT_INREG:
-    if (selectImpl(I, *CoverageInfo))
+    // This is a workaround. For extension from type i1, `selectImpl()` uses
+    // patterns from TD file and generates an illegal VGPR to SGPR COPY as type
+    // i1 can only be hold in a SGPR class.
+    if (MRI->getType(I.getOperand(1).getReg()) != LLT::scalar(1) &&
+        selectImpl(I, *CoverageInfo))
       return true;
     return selectG_SZA_EXT(I);
   case TargetOpcode::G_BRCOND:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147780.511654.patch
Type: text/x-patch
Size: 1561 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230407/e9152cdb/attachment.bin>


More information about the llvm-commits mailing list