[llvm] r336041 - AMDGPU/GlobalISel: Make IMPLICIT_DEF of all sizes < 512 legal.

Tom Stellard via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 29 21:09:44 PDT 2018


Author: tstellar
Date: Fri Jun 29 21:09:44 2018
New Revision: 336041

URL: http://llvm.org/viewvc/llvm-project?rev=336041&view=rev
Log:
AMDGPU/GlobalISel: Make IMPLICIT_DEF of all sizes < 512 legal.

Summary:
We could split sizes that are not power of two into smaller sized
G_IMPLICIT_DEF instructions, but this ends up generating
G_MERGE_VALUES instructions which we then have to handle in the instruction
selector.  Since G_IMPLICIT_DEF is really a no-op it's easier just to
keep everything that can fit into a register legal.

Reviewers: arsenm

Reviewed By: arsenm

Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, dstuttard, tpr, t-tye, llvm-commits

Differential Revision: https://reviews.llvm.org/D48777

Added:
    llvm/trunk/test/CodeGen/AMDGPU/GlobalISel/legalize-implicit-def.mir
Modified:
    llvm/trunk/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp

Modified: llvm/trunk/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp?rev=336041&r1=336040&r2=336041&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp Fri Jun 29 21:09:44 2018
@@ -39,6 +39,7 @@ AMDGPULegalizerInfo::AMDGPULegalizerInfo
 
   const LLT S32 = LLT::scalar(32);
   const LLT S64 = LLT::scalar(64);
+  const LLT S512 = LLT::scalar(512);
 
   const LLT GlobalPtr = GetAddrSpacePtr(AMDGPUAS::GLOBAL_ADDRESS);
   const LLT ConstantPtr = GetAddrSpacePtr(AMDGPUAS::CONSTANT_ADDRESS);
@@ -70,9 +71,16 @@ AMDGPULegalizerInfo::AMDGPULegalizerInfo
 
   getActionDefinitionsBuilder(G_FCONSTANT)
     .legalFor({S32, S64});
+
+  // G_IMPLICIT_DEF is a no-op so we can make it legal for any value type that
+  // can fit in a register.
+  // FIXME: We need to legalize several more operations before we can add
+  // a test case for size > 512.
   getActionDefinitionsBuilder(G_IMPLICIT_DEF)
-    .legalFor({S1, S32, S64,
-               GlobalPtr, ConstantPtr, LocalPtr, FlatPtr, PrivatePtr});
+    .legalIf([=](const LegalityQuery &Query) {
+        return Query.Types[0].getSizeInBits() <= 512;
+    })
+    .clampScalar(0, S1, S512);
 
   getActionDefinitionsBuilder(G_CONSTANT)
     .legalFor({S1, S32, S64});

Added: llvm/trunk/test/CodeGen/AMDGPU/GlobalISel/legalize-implicit-def.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AMDGPU/GlobalISel/legalize-implicit-def.mir?rev=336041&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/AMDGPU/GlobalISel/legalize-implicit-def.mir (added)
+++ llvm/trunk/test/CodeGen/AMDGPU/GlobalISel/legalize-implicit-def.mir Fri Jun 29 21:09:44 2018
@@ -0,0 +1,20 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+# RUN: llc -mtriple=amdgcn-mesa-mesa3d -run-pass=legalizer %s -o - | FileCheck %s
+
+# FIXME: Need to add test for IMPLICIT_DEF > 512 once all the operations used
+# to legalize IMPLICIT_DEF are leagl.
+
+---
+name:            test_implicit_def
+body: |
+  bb.0:
+    liveins: $vgpr0, $vgpr1
+
+    ; CHECK-LABEL: name: test_implicit_def
+    ; CHECK: [[DEF:%[0-9]+]]:_(s448) = G_IMPLICIT_DEF
+    ; CHECK: [[EXTRACT:%[0-9]+]]:_(s32) = G_EXTRACT [[DEF]](s448), 0
+    ; CHECK: $vgpr0 = COPY [[EXTRACT]](s32)
+    %0:_(s448) = G_IMPLICIT_DEF
+    %1:_(s32) = G_EXTRACT %0, 0
+    $vgpr0 = COPY %1
+...




More information about the llvm-commits mailing list