[llvm] b583327 - AMDGPU: Fix assert on inline asm on gfx90a

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 23 06:00:34 PDT 2021


Author: Matt Arsenault
Date: 2021-04-23T09:00:25-04:00
New Revision: b58332774f85efc1d7b88cd7985a93b63bf8de74

URL: https://github.com/llvm/llvm-project/commit/b58332774f85efc1d7b88cd7985a93b63bf8de74
DIFF: https://github.com/llvm/llvm-project/commit/b58332774f85efc1d7b88cd7985a93b63bf8de74.diff

LOG: AMDGPU: Fix assert on inline asm on gfx90a

This was assuming all mayLoad instructions have one def.

Added: 
    llvm/test/CodeGen/AMDGPU/swdev282079.ll

Modified: 
    llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
    llvm/test/CodeGen/AMDGPU/swdev282079.mir

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
index f89bd759d2aaa..92721043be10e 100644
--- a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
+++ b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
@@ -1655,7 +1655,7 @@ bool SIFoldOperands::tryFoldLCSSAPhi(MachineInstr &PHI) {
 // Attempt to convert VGPR load to an AGPR load.
 bool SIFoldOperands::tryFoldLoad(MachineInstr &MI) {
   assert(MI.mayLoad());
-  if (!ST->hasGFX90AInsts() || !MI.getNumOperands())
+  if (!ST->hasGFX90AInsts() || MI.getNumExplicitDefs() != 1)
     return false;
 
   MachineOperand &Def = MI.getOperand(0);

diff  --git a/llvm/test/CodeGen/AMDGPU/swdev282079.ll b/llvm/test/CodeGen/AMDGPU/swdev282079.ll
new file mode 100644
index 0000000000000..b8a0c8616193d
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/swdev282079.ll
@@ -0,0 +1,13 @@
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a < %s
+
+define protected amdgpu_kernel void @foo(i64 addrspace(1)* %arg, i64 addrspace(1)* %arg1) {
+bb:
+  %tmp = addrspacecast i64* addrspace(5)* null to i64**
+  %tmp2 = call i64 @eggs(i64* undef) #1
+  %tmp3 = load i64*, i64** %tmp, align 8
+  %tmp4 = getelementptr inbounds i64, i64* %tmp3, i64 undef
+  store i64 %tmp2, i64* %tmp4, align 8
+  ret void
+}
+
+declare hidden i64 @eggs(i64*)

diff  --git a/llvm/test/CodeGen/AMDGPU/swdev282079.mir b/llvm/test/CodeGen/AMDGPU/swdev282079.mir
index 820190cf943b5..d1761697d9b22 100644
--- a/llvm/test/CodeGen/AMDGPU/swdev282079.mir
+++ b/llvm/test/CodeGen/AMDGPU/swdev282079.mir
@@ -100,3 +100,18 @@ body:             |
     S_ENDPGM 0
 
 ...
+
+# This would crash looking for a def in any mayLoad instruction
+---
+name: fold_inlineasm_def
+tracksRegLiveness: true
+body:             |
+  bb.0:
+
+    ; CHECK-LABEL: name: fold_inlineasm_def
+    ; CHECK: INLINEASM &"s_waitcnt vmcnt($0)", 41 /* sideeffect mayload isconvergent attdialect */, 13 /* imm */, 0
+    ; CHECK: S_ENDPGM 0
+    INLINEASM &"s_waitcnt vmcnt($0)", 41 /* sideeffect mayload isconvergent attdialect */, 13 /* imm */, 0
+    S_ENDPGM 0
+
+...


        


More information about the llvm-commits mailing list