[llvm] 5ddfedc - [AMDGPU] Fix deleting of move-immediate instructions after folding

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 2 08:11:24 PST 2022


Author: Jay Foad
Date: 2022-03-02T16:11:16Z
New Revision: 5ddfedc9569fbeca0a70e0fda0863ee43f830599

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

LOG: [AMDGPU] Fix deleting of move-immediate instructions after folding

SIInstrInfo::FoldImmediate tried to delete move-immediate instructions
after folding them into their only use. This did not work because it was
checking hasOneNonDBGUse after doing the fold, at which point there
should be no uses. This seems to have no effect on codegen, it just
means less stuff for DCE to clean up later.

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

Added: 
    

Modified: 
    llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
    llvm/test/CodeGen/AMDGPU/madak-inline-constant.mir

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index 96168fa2f4748..547256f311339 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -3000,7 +3000,7 @@ bool SIInstrInfo::FoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI,
       removeModOperands(UseMI);
       UseMI.setDesc(get(NewOpc));
 
-      bool DeleteDef = MRI->hasOneNonDBGUse(Reg);
+      bool DeleteDef = MRI->use_nodbg_empty(Reg);
       if (DeleteDef)
         DefMI.eraseFromParent();
 
@@ -3083,7 +3083,7 @@ bool SIInstrInfo::FoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI,
       // constant and SGPR are illegal.
       legalizeOperands(UseMI);
 
-      bool DeleteDef = MRI->hasOneNonDBGUse(Reg);
+      bool DeleteDef = MRI->use_nodbg_empty(Reg);
       if (DeleteDef)
         DefMI.eraseFromParent();
 

diff  --git a/llvm/test/CodeGen/AMDGPU/madak-inline-constant.mir b/llvm/test/CodeGen/AMDGPU/madak-inline-constant.mir
index 935e91a3a864b..2b57f2b45f353 100644
--- a/llvm/test/CodeGen/AMDGPU/madak-inline-constant.mir
+++ b/llvm/test/CodeGen/AMDGPU/madak-inline-constant.mir
@@ -2,7 +2,6 @@
 
 
 # GCN-LABEL: bb.0:
-# GCN:  V_MOV_B32_e32 1092616192
 # GCN:  S_MOV_B32 1082130432
 # GCN:  %3:vgpr_32 = V_MADAK_F32 1082130432, killed %0, 1092616192, implicit $mode, implicit $exec
 
@@ -21,7 +20,6 @@ body:             |
 
 
 # GCN-LABEL: bb.0:
-# GCN:  V_MOV_B32_e32 1092616192
 # GCN:  S_MOV_B32 1082130432
 # GCN:  %3:vgpr_32 = V_MADAK_F32 1082130432, killed %0, 1092616192, implicit $mode, implicit $exec
 
@@ -39,7 +37,6 @@ body:             |
 ...
 
 # GCN-LABEL: bb.0:
-# GCN:  V_MOV_B32_e32 1092616192
 # GCN:  S_MOV_B32 1082130432
 # GCN:  %3:vgpr_32 = V_MADAK_F32 killed %0, killed %0, 1092616192, implicit $mode, implicit $exec
 
@@ -57,7 +54,6 @@ body:             |
 ...
 
 # GCN-LABEL: bb.0:
-# GCN:  V_MOV_B32_e32 1092616192
 # GCN:  V_MOV_B32_e32 1082130432
 # GCN:  %3:vgpr_32 = V_MADAK_F32 1082130432, killed %0, 1092616192, implicit $mode, implicit $exec
 
@@ -76,7 +72,6 @@ body:             |
 
 
 # GCN-LABEL: bb.0:
-# GCN:  V_MOV_B32_e32 1092616192
 # GCN:  V_MOV_B32_e32 1082130432
 # GCN:  %3:vgpr_32 = V_MADAK_F32 1082130432, killed %0, 1092616192, implicit $mode, implicit $exec
 
@@ -94,7 +89,6 @@ body:             |
 ...
 
 # GCN-LABEL: bb.0:
-# GCN:  V_MOV_B32_e32 1092616192, implicit $exec
 # GCN:  S_MOV_B32 1082130432
 # GCN:  V_MADAK_F32 1082130432, killed $vgpr1, 1092616192, implicit $mode, implicit $exec
 
@@ -113,7 +107,6 @@ body:             |
 ...
 
 # GCN-LABEL: bb.0:
-# GCN:  V_MOV_B32_e32 1092616192, implicit $exec
 # GCN:  S_MOV_B32 1082130432
 # GCN:  V_MADAK_F32 1082130432, killed $vgpr0, 1092616192, implicit $mode, implicit $exec
 
@@ -166,7 +159,6 @@ body:             |
 ...
 
 # GCN-LABEL: bb.0:
-# GCN:  V_MOV_B32_e32 1092616192, implicit $exec
 # GCN:  $sgpr2 = S_MOV_B32 1082130432
 # GCN:  V_MADAK_F32 1082130432, killed %0, 1092616192, implicit $mode, implicit $exec
 


        


More information about the llvm-commits mailing list