[AMDGPU] Fix deleting of move-immediate instructions after folding
authorJay Foad <jay.foad@amd.com>
Wed, 2 Mar 2022 15:18:30 +0000 (15:18 +0000)
committerJay Foad <jay.foad@amd.com>
Wed, 2 Mar 2022 16:11:16 +0000 (16:11 +0000)
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

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

index 96168fa..547256f 100644 (file)
@@ -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();
 
index 935e91a..2b57f2b 100644 (file)
@@ -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