1# RUN: llc -march=amdgcn -run-pass si-fold-operands -verify-machineinstrs %s -o - | FileCheck -check-prefix=GCN %s
2
3# GCN-LABEL:       name: fold-imm-copy
4# GCN:             [[SREG:%[0-9+]]]:sreg_32_xm0 = S_MOV_B32 65535
5# GCN:             V_AND_B32_e32 [[SREG]]
6
7---
8name: fold-imm-copy
9tracksRegLiveness: true
10body:             |
11  bb.0:
12    liveins: $vgpr0, $sgpr0_sgpr1
13    %0:vgpr_32 = COPY $vgpr0
14    %1:sgpr_64 = COPY $sgpr0_sgpr1
15    %2:sgpr_128 = S_LOAD_DWORDX4_IMM %1, 9, 0, 0
16    %3:sreg_32_xm0 = S_MOV_B32 2
17    %4:vgpr_32 = V_LSHLREV_B32_e64 killed %3, %0, implicit $exec
18    %5:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
19    %6:vreg_64 = REG_SEQUENCE killed %4, %subreg.sub0, killed %5, %subreg.sub1
20    %7:vgpr_32 = BUFFER_LOAD_DWORD_ADDR64 %6, %2, 0, 4, 0, 0, 0, 0, 0, implicit $exec
21    %8:sreg_32_xm0 = S_MOV_B32 65535
22    %9:vgpr_32 = COPY %8
23    %10:vgpr_32 = V_AND_B32_e32 %7, %9, implicit $exec
24...
25
26---
27# GCN-LABEL:       name: no_extra_fold_on_same_opnd
28# The first XOR needs commuting to fold that immediate operand.
29# GCN:             V_XOR_B32_e32 0, %1
30# GCN:             V_XOR_B32_e32 %2, %4.sub0
31name: no_extra_fold_on_same_opnd
32tracksRegLiveness: true
33body:             |
34  bb.0:
35    %0:vgpr_32 = IMPLICIT_DEF
36    %1:vgpr_32 = IMPLICIT_DEF
37    %2:vgpr_32 = IMPLICIT_DEF
38    %3:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
39    %4:vreg_64 = REG_SEQUENCE killed %0, %subreg.sub0, killed %3, %subreg.sub1
40    %5:vgpr_32 = V_XOR_B32_e32 %1, %4.sub1, implicit $exec
41    %6:vgpr_32 = V_XOR_B32_e32 %2, %4.sub0, implicit $exec
42...
43
44---
45
46# Make sure the subreg index is not reinterpreted when folding
47# immediates
48#
49# GCN-LABEL: name: clear_subreg_imm_fold{{$}}
50# GCN: %1:sgpr_32 = S_MOV_B32 4294967288
51# GCN: %2:sgpr_32 = S_MOV_B32 4294967295
52name: clear_subreg_imm_fold
53tracksRegLiveness: true
54body:             |
55  bb.0:
56    %0:sreg_64 = S_MOV_B64 -8
57    %1:sgpr_32 = COPY %0.sub0
58    %2:sgpr_32 = COPY %0.sub1
59    S_ENDPGM 0, implicit %1, implicit %2
60
61...
62
63# GCN-LABEL: name: no_fold_imm_into_m0{{$}}
64# GCN: %0:sreg_32 = S_MOV_B32 -8
65# GCN-NEXT: $m0 = COPY %0
66
67---
68name: no_fold_imm_into_m0
69tracksRegLiveness: true
70body:             |
71  bb.0:
72    %0:sreg_32 = S_MOV_B32 -8
73    $m0 = COPY %0
74    S_ENDPGM 0, implicit $m0
75
76...
77
78# GCN-LABEL: name: fold_sgpr_imm_to_vgpr_copy{{$}}
79# GCN: $vgpr0 = V_MOV_B32_e32 -8, implicit $exec
80---
81name: fold_sgpr_imm_to_vgpr_copy
82tracksRegLiveness: true
83body:             |
84  bb.0:
85    %0:sreg_32 = S_MOV_B32 -8
86    $vgpr0 = COPY %0
87    S_ENDPGM 0, implicit $vgpr0
88
89...
90
91# The users of $vgpr1 should not be visited for further immediate
92# folding.
93
94# GCN-LABEL: name: no_fold_physreg_users_vgpr{{$}}
95# GCN: $vgpr1 = V_MOV_B32_e32 0, implicit $exec
96# GCN-NEXT: S_NOP 0, implicit-def $vgpr1
97# GCN-NEXT: %2:vgpr_32 = COPY $vgpr1
98# GCN-NEXT: $vgpr2 = COPY %2
99---
100name: no_fold_physreg_users_vgpr
101tracksRegLiveness: true
102body:             |
103  bb.0:
104    %0:sreg_32 = S_MOV_B32 0
105    %1:vgpr_32 = COPY %0
106    $vgpr1 = COPY %0
107    S_NOP 0, implicit-def $vgpr1
108    %2:vgpr_32 = COPY $vgpr1
109    $vgpr2 = COPY %2
110    S_ENDPGM 0
111
112...
113