Issue 122709
Summary [AMDGPU][GISel] GlobalISel doesn’t make use enough of _e64 instructions
Labels new issue
Assignees
Reporter tyb0807
    Given the input IR in [input_ir.txt](https://github.com/user-attachments/files/18397617/input_ir.txt), GISel is generating code using mostly `_e32` instructions, while SelectionDAG is able to make use of `_e64` instructions, which resulted in much more compact code:

```
 ; Function info: (SelectionDAG)
 ; codeLenInByte = 212
 ; NumSgprs: 38
 ; NumVgprs: 32
 ; NumAgprs: 0
 ; TotalNumVgprs: 32
 ; ScratchSize: 324
 ; MemoryBound: 0

 ; Function info: (GlobalISel)
 ; codeLenInByte = 292
 ; NumSgprs: 38
 ; NumVgprs: 32
 ; NumAgprs: 0
 ; TotalNumVgprs: 32
 ; ScratchSize: 324
 ; MemoryBound: 0
```

Using `llc -O3 -march=amdgcn -mcpu=gfx942  -print-after-all -mtriple amdgcn-amd-hmcsa --asm-verbose --asm-show-inst input_ir.txt -o seldag.s 2> seldag.mir` and `llc -O3 -march=amdgcn -mcpu=gfx942  -print-after-all -mtriple amdgcn-amd-hmcsa -global-isel --asm-verbose --asm-show-inst input_ir.txtl -o gisel.s 2> gisel.mir`, we can see from the final MIR that, for instance, to compute the value to be stored at `$vgpr12`:

SelectionDAG makes extensive use of `_e64` instructions
```
renamable $vgpr7 = V_MOV_B32_e32 0, implicit $exec
renamable $vgpr0 = V_AND_B32_e32 -2, killed $vgpr0, implicit $exec
renamable $vgpr2 = V_LSHRREV_B32_e32 2, $vgpr0, implicit $exec
$vgpr1 = V_MOV_B32_e32 $vgpr7, implicit $exec, implicit $exec
$vgpr5 = V_MOV_B32_e32 killed $sgpr0, implicit $exec, implicit $exec
renamable $vgpr48 = V_SUB_CO_U32_e32 killed $sgpr12, killed $vgpr2, implicit-def $vcc, implicit $exec

renamable $vgpr6 = V_AND_B32_e32 1023, $vgpr31, implicit $exec
renamable $vgpr0_vgpr1 = V_LSHLREV_B64_e64 5, killed $vgpr0_vgpr1, implicit $exec
renamable $vgpr49 = V_SUBBREV_U32_e32 0, killed $vgpr5, implicit-def dead $vcc, implicit killed $vcc, implicit $exec

renamable $vgpr48_vgpr49 = nsw V_LSHLREV_B64_e64 7, killed $vgpr48_vgpr49, implicit $exec
renamable $vgpr0_vgpr1 = V_LSHL_ADD_U64_e64 killed $vgpr0_vgpr1, 0, $vgpr6_vgpr7, implicit $exec

renamable $vgpr48_vgpr49 = V_LSHL_ADD_U64_e64 killed $vgpr0_vgpr1, 0, killed $vgpr48_vgpr49, implicit $exec

SCRATCH_STORE_DWORDX2 killed renamable $vgpr48_vgpr49, killed renamable $vgpr12, 0, 0, implicit $exec, implicit $flat_scr :: (store (s64) into %ir.i44.out, addrspace 5)
```

While GlobalISel does not and thus generates much more verbose code
```
 renamable $vgpr8 = V_AND_B32_e32 1023, $vgpr31, implicit $exec
   renamable $vgpr48 = V_ASHRREV_I32_e32 31, $vgpr8, implicit $exec
   renamable $vgpr49 = V_XOR_B32_e32 $vgpr48, $vgpr8, implicit $exec
   renamable $vgpr50 = V_ASHRREV_I32_e32 31, $vgpr49, implicit $exec
   renamable $vgpr6 = V_LSHRREV_B32_e32 26, $vgpr50, implicit $exec
   renamable $vgpr6 = V_ADD_U32_e32 $vgpr49, killed $vgpr6, implicit $exec
   renamable $vgpr6 = V_ASHRREV_I32_e32 6, killed $vgpr6, implicit $exec
   renamable $vgpr31 = V_BFE_U32_e64 killed $vgpr31, 10, 10, implicit $exec
   renamable $vgpr6 = V_XOR_B32_e32 killed $vgpr6, $vgpr48, implicit $exec
   renamable $vgpr5 = V_ASHRREV_I32_e32 31, $vgpr31, implicit $exec
   renamable $vgpr7 = V_ASHRREV_I32_e32 31, $vgpr6, implicit $exec
   renamable $vgpr33 = V_ADD_U32_e32 killed $vgpr7, killed $vgpr5, implicit $exec
   renamable $vgpr5 = V_ASHRREV_I32_e32 31, $vgpr33, implicit $exec
   renamable $vgpr6 = V_XOR_B32_e32 killed $vgpr6, $vgpr48, implicit $exec
   renamable $vgpr32 = nuw V_ADD_U32_e32 killed $vgpr6, $vgpr31, implicit $exec
   renamable $vgpr6 = V_SUB_CO_U32_e32 killed $vgpr32, $vgpr5, implicit-def $vcc, implicit $exec

   renamable $vgpr6_vgpr7 = nsw V_LSHLREV_B64_e64 5, killed $vgpr6_vgpr7, implicit $exec
   renamable $vgpr6 = V_ADD_CO_U32_e32 killed $vgpr6, $vgpr8, implicit-def $vcc, implicit $exec

   renamable $vgpr32_vgpr33 = nsw V_LSHLREV_B64_e64 7, killed $vgpr32_vgpr33, implicit $exec

   renamable $vgpr34 = V_ADD_CO_U32_e32 killed $vgpr6, killed $vgpr32, implicit-def $vcc, implicit $exec
 
   renamable $vgpr5 = V_LSHRREV_B32_e32 27, $vgpr50, implicit $exec
   renamable $vgpr5 = V_ADD_U32_e32 $vgpr49, killed $vgpr5, implicit $exec
   renamable $vgpr5 = V_ASHRREV_I32_e32 5, killed $vgpr5, implicit $exec
   renamable $vgpr5 = V_XOR_B32_e32 killed $vgpr5, $vgpr48, implicit $exec
   renamable $vgpr36 = V_ASHRREV_I32_e32 31, $vgpr5, implicit $exec
   renamable $vgpr7 = V_SUBB_U32_e32 killed $vgpr33, $vgpr36, implicit-def dead $vcc, implicit killed $vcc, implicit $exec

   renamable $vgpr6_vgpr7 = nsw V_LSHLREV_B64_e64 5, killed $vgpr6_vgpr7, implicit $exec
   renamable $vgpr7 = V_ADDC_U32_e32 killed $vgpr7, $vgpr48, implicit-def dead $vcc, implicit killed $vcc, implicit $exec
 
   renamable $vgpr7 = V_ADDC_U32_e32 0, killed $vgpr7, implicit-def dead $vcc, implicit killed $vcc, implicit $exec

   renamable $vgpr6_vgpr7 = V_ASHRREV_I64_e64 2, killed $vgpr6_vgpr7, implicit $exec
   renamable $vgpr35 = V_XOR_B32_e32 killed $vgpr7, killed $vgpr5, implicit $exec
   $vgpr33 = V_MOV_B32_e32 killed $sgpr1, implicit $exec, implicit $exec
   renamable $vgpr33 = V_SUBB_U32_e32 killed $vgpr33, killed $vgpr35, implicit-def dead $vcc, implicit killed $vcc, implicit $exec

   renamable $vgpr32_vgpr33 = nsw V_LSHLREV_B64_e64 7, killed $vgpr32_vgpr33, implicit $exec

   renamable $vgpr35 = V_ADDC_U32_e32 killed $vgpr7, killed $vgpr33, implicit-def dead $vcc, implicit killed $vcc, implicit $exec

   SCRATCH_STORE_DWORDX2 killed renamable $vgpr34_vgpr35, killed renamable $vgpr12, 0, 0, implicit $exec, implicit $flat_scr :: (store (s64) into %ir.i44.out, addrspace 5)
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to