llvm/llvm/test/CodeGen/AMDGPU/early-term.mir

# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -run-pass=si-late-branch-lowering -verify-machineinstrs  %s -o - | FileCheck -check-prefixes=GCN,GFX9 %s
# RUN: llc -mtriple=amdgcn -mcpu=gfx1010 -mattr=+wavefrontsize64 -run-pass=si-late-branch-lowering -verify-machineinstrs  %s -o - | FileCheck -check-prefixes=GCN,GFX10 %s
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=+wavefrontsize64 -run-pass=si-late-branch-lowering -verify-machineinstrs  %s -o - | FileCheck -check-prefixes=GCN,GFX11 %s

--- |
  define amdgpu_ps void @early_term_scc0_end_block() {
    ret void
  }

  define amdgpu_ps void @early_term_scc0_next_terminator() {
    ret void
  }

  define amdgpu_ps void @early_term_scc0_in_block() {
    ret void
  }

  define amdgpu_gs void @early_term_scc0_gs() {
    ret void
  }

  define amdgpu_cs void @early_term_scc0_cs() {
    ret void
  }

  define amdgpu_ps void @early_term_no_export() #0 {
    ret void
  }

  define amdgpu_ps void @early_term_depth_only() #1 {
    ret void
  }

  attributes #0 = { "amdgpu-color-export"="0" "amdgpu-depth-export"="0" }
  attributes #1 = { "amdgpu-color-export"="0" "amdgpu-depth-export"="1" }
...

---
name: early_term_scc0_end_block
tracksRegLiveness: true
liveins:
  - { reg: '$sgpr0' }
  - { reg: '$sgpr1' }
body: |
  ; GCN-LABEL: name: early_term_scc0_end_block
  ; GCN: bb.0:
  ; GCN:   successors: %bb.1(0x80000000), %bb.2(0x00000000)
  ; GCN:   liveins: $sgpr0, $sgpr1
  ; GCN:   $vgpr0 = V_MOV_B32_e32 0, implicit $exec
  ; GCN:   dead $sgpr0 = S_AND_B32 $sgpr0, killed $sgpr1, implicit-def $scc
  ; GCN:   S_CBRANCH_SCC0 %bb.2, implicit $scc
  ; GCN: bb.1:
  ; GCN:   liveins: $vgpr0
  ; GCN:   EXP_DONE 0, $vgpr0, $vgpr0, $vgpr0, $vgpr0, -1, -1, 15, implicit $exec
  ; GCN:   S_ENDPGM 0
  ; GCN: bb.2:
  ; GCN:   $exec = S_MOV_B64 0
  ; GFX9:  EXP_DONE 9, undef $vgpr0, undef $vgpr0, undef $vgpr0, undef $vgpr0, 1, 0, 0, implicit $exec
  ; GFX10: EXP_DONE 9, undef $vgpr0, undef $vgpr0, undef $vgpr0, undef $vgpr0, 1, 0, 0, implicit $exec
  ; GFX11: EXP_DONE 0, undef $vgpr0, undef $vgpr0, undef $vgpr0, undef $vgpr0, 1, 0, 0, implicit $exec
  ; GCN:   S_ENDPGM 0
  bb.0:
    liveins: $sgpr0, $sgpr1
    successors: %bb.1

    $vgpr0 = V_MOV_B32_e32 0, implicit $exec
    dead $sgpr0 = S_AND_B32 $sgpr0, killed $sgpr1, implicit-def $scc
    SI_EARLY_TERMINATE_SCC0 implicit $scc, implicit $exec

  bb.1:
    liveins: $vgpr0
    EXP_DONE 0, $vgpr0, $vgpr0, $vgpr0, $vgpr0, -1, -1, 15, implicit $exec
    S_ENDPGM 0
...

---
name: early_term_scc0_next_terminator
tracksRegLiveness: true
liveins:
  - { reg: '$sgpr0' }
  - { reg: '$sgpr1' }
body: |
  ; GCN-LABEL: name: early_term_scc0_next_terminator
  ; GCN: bb.0:
  ; GCN:   successors: %bb.2(0x80000000), %bb.3(0x00000000)
  ; GCN:   liveins: $sgpr0, $sgpr1
  ; GCN:   $vgpr0 = V_MOV_B32_e32 0, implicit $exec
  ; GCN:   dead $sgpr0 = S_AND_B32 $sgpr0, killed $sgpr1, implicit-def $scc
  ; GCN:   S_CBRANCH_SCC0 %bb.3, implicit $scc
  ; GCN:   S_BRANCH %bb.2
  ; GCN: bb.1:
  ; GCN:   successors: %bb.2(0x80000000)
  ; GCN:   $vgpr0 = V_MOV_B32_e32 1, implicit $exec
  ; GCN: bb.2:
  ; GCN:   liveins: $vgpr0
  ; GCN:   EXP_DONE 0, $vgpr0, $vgpr0, $vgpr0, $vgpr0, -1, -1, 15, implicit $exec
  ; GCN:   S_ENDPGM 0
  ; GCN: bb.3:
  ; GCN:   $exec = S_MOV_B64 0
  ; GFX9:  EXP_DONE 9, undef $vgpr0, undef $vgpr0, undef $vgpr0, undef $vgpr0, 1, 0, 0, implicit $exec
  ; GFX10: EXP_DONE 9, undef $vgpr0, undef $vgpr0, undef $vgpr0, undef $vgpr0, 1, 0, 0, implicit $exec
  ; GFX11: EXP_DONE 0, undef $vgpr0, undef $vgpr0, undef $vgpr0, undef $vgpr0, 1, 0, 0, implicit $exec
  ; GCN:   S_ENDPGM 0
  bb.0:
    liveins: $sgpr0, $sgpr1
    successors: %bb.2

    $vgpr0 = V_MOV_B32_e32 0, implicit $exec
    dead $sgpr0 = S_AND_B32 $sgpr0, killed $sgpr1, implicit-def $scc
    SI_EARLY_TERMINATE_SCC0 implicit $scc, implicit $exec
    S_BRANCH %bb.2

  bb.1:
    successors: %bb.2
    $vgpr0 = V_MOV_B32_e32 1, implicit $exec
    S_BRANCH %bb.2

  bb.2:
    liveins: $vgpr0
    EXP_DONE 0, $vgpr0, $vgpr0, $vgpr0, $vgpr0, -1, -1, 15, implicit $exec
    S_ENDPGM 0
...

---
name: early_term_scc0_in_block
tracksRegLiveness: true
liveins:
  - { reg: '$sgpr0' }
  - { reg: '$sgpr1' }
body: |
  ; GCN-LABEL: name: early_term_scc0_in_block
  ; GCN: bb.0:
  ; GCN:   successors: %bb.3(0x40000000), %bb.2(0x40000000)
  ; GCN:   liveins: $sgpr0, $sgpr1
  ; GCN:   $vgpr0 = V_MOV_B32_e32 0, implicit $exec
  ; GCN:   dead $sgpr0 = S_AND_B32 $sgpr0, killed $sgpr1, implicit-def $scc
  ; GCN:   S_CBRANCH_SCC0 %bb.2, implicit $scc
  ; GCN: bb.3:
  ; GCN:   successors: %bb.1(0x80000000)
  ; GCN:   liveins: $vgpr0, $scc
  ; GCN:   $vgpr1 = V_MOV_B32_e32 1, implicit $exec
  ; GCN: bb.1:
  ; GCN:   liveins: $vgpr0, $vgpr1
  ; GCN:   EXP 1, $vgpr1, $vgpr1, $vgpr1, $vgpr1, -1, -1, 15, implicit $exec
  ; GCN:   EXP_DONE 0, $vgpr0, $vgpr0, $vgpr0, $vgpr0, -1, -1, 15, implicit $exec
  ; GCN:   S_ENDPGM 0
  ; GCN: bb.2:
  ; GCN:   $exec = S_MOV_B64 0
  ; GFX9:  EXP_DONE 9, undef $vgpr0, undef $vgpr0, undef $vgpr0, undef $vgpr0, 1, 0, 0, implicit $exec
  ; GFX10: EXP_DONE 9, undef $vgpr0, undef $vgpr0, undef $vgpr0, undef $vgpr0, 1, 0, 0, implicit $exec
  ; GFX11: EXP_DONE 0, undef $vgpr0, undef $vgpr0, undef $vgpr0, undef $vgpr0, 1, 0, 0, implicit $exec
  ; GCN:   S_ENDPGM 0
  bb.0:
    liveins: $sgpr0, $sgpr1
    successors: %bb.1

    $vgpr0 = V_MOV_B32_e32 0, implicit $exec
    dead $sgpr0 = S_AND_B32 $sgpr0, killed $sgpr1, implicit-def $scc
    SI_EARLY_TERMINATE_SCC0 implicit $scc, implicit $exec
    $vgpr1 = V_MOV_B32_e32 1, implicit $exec

  bb.1:
    liveins: $vgpr0, $vgpr1
    EXP 1, $vgpr1, $vgpr1, $vgpr1, $vgpr1, -1, -1, 15, implicit $exec
    EXP_DONE 0, $vgpr0, $vgpr0, $vgpr0, $vgpr0, -1, -1, 15, implicit $exec
    S_ENDPGM 0
...

---
name: early_term_scc0_gs
tracksRegLiveness: true
liveins:
  - { reg: '$sgpr0' }
  - { reg: '$sgpr1' }
body: |
  ; GCN-LABEL: name: early_term_scc0_gs
  ; GCN: bb.0:
  ; GCN:   successors: %bb.1(0x80000000)
  ; GCN:   liveins: $sgpr0, $sgpr1
  ; GCN:   $vgpr0 = V_MOV_B32_e32 0, implicit $exec
  ; GCN:   dead $sgpr0 = S_AND_B32 $sgpr0, killed $sgpr1, implicit-def $scc
  ; GCN: bb.1:
  ; GCN:   liveins: $vgpr0
  ; GCN:   S_ENDPGM 0
  ; GCN: bb.2:
  ; GCN:   $exec = S_MOV_B64 0
  ; GCN:   S_ENDPGM 0
  bb.0:
    liveins: $sgpr0, $sgpr1
    successors: %bb.1

    $vgpr0 = V_MOV_B32_e32 0, implicit $exec
    dead $sgpr0 = S_AND_B32 $sgpr0, killed $sgpr1, implicit-def $scc
    SI_EARLY_TERMINATE_SCC0 implicit $scc, implicit $exec

  bb.1:
    liveins: $vgpr0
    S_ENDPGM 0
...

---
name: early_term_scc0_cs
tracksRegLiveness: true
liveins:
  - { reg: '$sgpr0' }
  - { reg: '$sgpr1' }
body: |
  ; GCN-LABEL: name: early_term_scc0_cs
  ; GCN: bb.0:
  ; GCN:   successors: %bb.1(0x80000000), %bb.2(0x00000000)
  ; GCN:   liveins: $sgpr0, $sgpr1
  ; GCN:   $vgpr0 = V_MOV_B32_e32 0, implicit $exec
  ; GCN:   dead $sgpr0 = S_AND_B32 $sgpr0, killed $sgpr1, implicit-def $scc
  ; GCN:   S_CBRANCH_SCC0 %bb.2, implicit $scc
  ; GCN: bb.1:
  ; GCN:   liveins: $vgpr0
  ; GCN:   S_ENDPGM 0
  ; GCN: bb.2:
  ; GCN:   $exec = S_MOV_B64 0
  ; GCN:   S_ENDPGM 0
  bb.0:
    liveins: $sgpr0, $sgpr1
    successors: %bb.1

    $vgpr0 = V_MOV_B32_e32 0, implicit $exec
    dead $sgpr0 = S_AND_B32 $sgpr0, killed $sgpr1, implicit-def $scc
    SI_EARLY_TERMINATE_SCC0 implicit $scc, implicit $exec

  bb.1:
    liveins: $vgpr0
    S_ENDPGM 0
...

---
name: early_term_no_export
tracksRegLiveness: true
liveins:
  - { reg: '$sgpr0' }
  - { reg: '$sgpr1' }
body: |
  ; GCN-LABEL: name: early_term_no_export
  ; GCN: bb.0:
  ; GCN:   successors: %bb.1(0x80000000), %bb.2(0x00000000)
  ; GCN:   liveins: $sgpr0, $sgpr1
  ; GCN:   $vgpr0 = V_MOV_B32_e32 0, implicit $exec
  ; GCN:   dead $sgpr0 = S_AND_B32 $sgpr0, killed $sgpr1, implicit-def $scc
  ; GCN:   S_CBRANCH_SCC0 %bb.2, implicit $scc
  ; GCN: bb.1:
  ; GCN:   liveins: $vgpr0
  ; GCN:   EXP_DONE 0, $vgpr0, $vgpr0, $vgpr0, $vgpr0, -1, -1, 15, implicit $exec
  ; GCN:   S_ENDPGM 0
  ; GCN: bb.2:
  ; GCN:   $exec = S_MOV_B64 0
  ; GFX9:  EXP_DONE 9, undef $vgpr0, undef $vgpr0, undef $vgpr0, undef $vgpr0, 1, 0, 0, implicit $exec
  ; GFX10-NOT: EXP_DONE
  ; GFX11-NOT: EXP_DONE
  ; GCN:   S_ENDPGM 0
  bb.0:
    liveins: $sgpr0, $sgpr1
    successors: %bb.1

    $vgpr0 = V_MOV_B32_e32 0, implicit $exec
    dead $sgpr0 = S_AND_B32 $sgpr0, killed $sgpr1, implicit-def $scc
    SI_EARLY_TERMINATE_SCC0 implicit $scc, implicit $exec

  bb.1:
    liveins: $vgpr0
    EXP_DONE 0, $vgpr0, $vgpr0, $vgpr0, $vgpr0, -1, -1, 15, implicit $exec
    S_ENDPGM 0
...

---
name: early_term_depth_only
tracksRegLiveness: true
liveins:
  - { reg: '$sgpr0' }
  - { reg: '$sgpr1' }
body: |
  ; GCN-LABEL: name: early_term_depth_only
  ; GCN: bb.0:
  ; GCN:   successors: %bb.1(0x80000000), %bb.2(0x00000000)
  ; GCN:   liveins: $sgpr0, $sgpr1
  ; GCN:   $vgpr0 = V_MOV_B32_e32 0, implicit $exec
  ; GCN:   dead $sgpr0 = S_AND_B32 $sgpr0, killed $sgpr1, implicit-def $scc
  ; GCN:   S_CBRANCH_SCC0 %bb.2, implicit $scc
  ; GCN: bb.1:
  ; GCN:   liveins: $vgpr0
  ; GCN:   EXP_DONE 8, $vgpr0, $vgpr0, $vgpr0, $vgpr0, -1, -1, 15, implicit $exec
  ; GCN:   S_ENDPGM 0
  ; GCN: bb.2:
  ; GCN:   $exec = S_MOV_B64 0
  ; GFX9:  EXP_DONE 9, undef $vgpr0, undef $vgpr0, undef $vgpr0, undef $vgpr0, 1, 0, 0, implicit $exec
  ; GFX10: EXP_DONE 9, undef $vgpr0, undef $vgpr0, undef $vgpr0, undef $vgpr0, 1, 0, 0, implicit $exec
  ; GFX11: EXP_DONE 8, undef $vgpr0, undef $vgpr0, undef $vgpr0, undef $vgpr0, 1, 0, 0, implicit $exec
  ; GCN:   S_ENDPGM 0
  bb.0:
    liveins: $sgpr0, $sgpr1
    successors: %bb.1

    $vgpr0 = V_MOV_B32_e32 0, implicit $exec
    dead $sgpr0 = S_AND_B32 $sgpr0, killed $sgpr1, implicit-def $scc
    SI_EARLY_TERMINATE_SCC0 implicit $scc, implicit $exec

  bb.1:
    liveins: $vgpr0
    EXP_DONE 8, $vgpr0, $vgpr0, $vgpr0, $vgpr0, -1, -1, 15, implicit $exec
    S_ENDPGM 0
...