[llvm] [CodeGen][NFC] Guard copy propagation in machine CSE against undefs (PR #97413)

Vikram Hegde via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 7 23:31:37 PDT 2024


================
@@ -0,0 +1,21 @@
+# RUN: llc -mtriple=amdgcn -run-pass=machine-cse -verify-machineinstrs -o - %s | FileCheck %s
+
+# Test to ensure that this does not crash on undefs
+# CHECK-LABEL: name: machine-cse-copyprop
+# CHECK: IMPLICIT_DEF
+# CHECK-NOT: COPY
+# CHECK: S_ADD_I32
+---
+name: machine-cse-copyprop
+tracksRegLiveness: true
+body:               |
+  bb.0:
+    %0:sreg_32 = IMPLICIT_DEF
+    %1:sreg_32 = IMPLICIT_DEF
+    %2:sreg_32 = COPY %0
+    %3:sreg_32 = COPY %1
+    %4:sreg_64 = REG_SEQUENCE undef %10:sreg_32, %subreg.sub0, %2:sreg_32, %subreg.sub1
+    %5:sreg_64 = REG_SEQUENCE undef %11:sreg_32, %subreg.sub0, %3:sreg_32, %subreg.sub1
----------------
vikramRH wrote:

here is a usecase (which is also the behaviour seen with new atomic optimizer changes). DPP combine translates following code 
```
  %20:vreg_64 = V_SET_INACTIVE_B64 killed %106:vreg_64, 0, implicit-def dead $scc, implicit $exec
  %187:vgpr_32 = V_MOV_B32_dpp %19.sub0:vreg_64(tied-def 0), %20.sub0:vreg_64, 273, 15, 15, 0, implicit $exec
  %188:vgpr_32 = V_MOV_B32_dpp %19.sub1:vreg_64(tied-def 0), %20.sub1:vreg_64, 273, 15, 15, 0, implicit $exec
  %21:vreg_64 = REG_SEQUENCE %187:vgpr_32, %subreg.sub0, %188:vgpr_32, %subreg.sub1
  %111:vgpr_32, %113:sreg_64_xexec = V_ADD_CO_U32_e64 %20.sub0:vreg_64, %21.sub0:vreg_64, 0, implicit $exec
  %112:vgpr_32, dead %114:sreg_64_xexec = V_ADDC_U32_e64 %20.sub1:vreg_64, %21.sub1:vreg_64, killed %113:sreg_64_xexec, 0, implicit $exec
```

to

```
  %19:vreg_64 = V_SET_INACTIVE_B64 killed %105:vreg_64, 0, implicit-def dead $scc, implicit $exec
  %187:vgpr_32 = V_MOV_B32_dpp %18.sub1:vreg_64(tied-def 0), %19.sub1:vreg_64, 273, 15, 15, 0, implicit $exec
  %20:vreg_64 = REG_SEQUENCE undef %186:vgpr_32, %subreg.sub0, %187:vgpr_32, %subreg.sub1
  %110:vgpr_32, %112:sreg_64_xexec = V_ADD_CO_U32_e64_dpp %188:vgpr_32(tied-def 0), %19.sub0:vreg_64, %19.sub0:vreg_64, 0, 273, 15, 15, 1, implicit $exec
  %111:vgpr_32, dead %113:sreg_64_xexec = V_ADDC_U32_e64 %19.sub1:vreg_64, %20.sub1:vreg_64, killed %112:sreg_64_xexec, 0, implicit $exec
```

https://github.com/llvm/llvm-project/pull/97413


More information about the llvm-commits mailing list