xref: /aosp_15_r20/external/llvm/test/CodeGen/X86/machine-copy-prop.mir (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker# RUN: llc -march=x86 -run-pass machine-cp -verify-machineinstrs -o - %s | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker--- |
4*9880d681SAndroid Build Coastguard Worker  declare void @foo()
5*9880d681SAndroid Build Coastguard Worker  define void @copyprop_remove_kill0() { ret void }
6*9880d681SAndroid Build Coastguard Worker  define void @copyprop_remove_kill1() { ret void }
7*9880d681SAndroid Build Coastguard Worker  define void @copyprop_remove_kill2() { ret void }
8*9880d681SAndroid Build Coastguard Worker  define void @copyprop0() { ret void }
9*9880d681SAndroid Build Coastguard Worker  define void @copyprop1() { ret void }
10*9880d681SAndroid Build Coastguard Worker  define void @copyprop2() { ret void }
11*9880d681SAndroid Build Coastguard Worker  define void @nocopyprop0() { ret void }
12*9880d681SAndroid Build Coastguard Worker  define void @nocopyprop1() { ret void }
13*9880d681SAndroid Build Coastguard Worker  define void @nocopyprop2() { ret void }
14*9880d681SAndroid Build Coastguard Worker  define void @nocopyprop3() { ret void }
15*9880d681SAndroid Build Coastguard Worker  define void @nocopyprop4() { ret void }
16*9880d681SAndroid Build Coastguard Worker  define void @nocopyprop5() { ret void }
17*9880d681SAndroid Build Coastguard Worker...
18*9880d681SAndroid Build Coastguard Worker---
19*9880d681SAndroid Build Coastguard Worker# The second copy is redundant and will be removed, check that we also remove
20*9880d681SAndroid Build Coastguard Worker# the kill flag of intermediate instructions.
21*9880d681SAndroid Build Coastguard Worker# CHECK-LABEL: name: copyprop_remove_kill0
22*9880d681SAndroid Build Coastguard Worker# CHECK: bb.0:
23*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: %rax = COPY %rdi
24*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: NOOP implicit %rdi
25*9880d681SAndroid Build Coastguard Worker# CHECK-NOT: COPY
26*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: NOOP implicit %rax, implicit %rdi
27*9880d681SAndroid Build Coastguard Workername: copyprop_remove_kill0
28*9880d681SAndroid Build Coastguard WorkerallVRegsAllocated: true
29*9880d681SAndroid Build Coastguard Workerbody: |
30*9880d681SAndroid Build Coastguard Worker  bb.0:
31*9880d681SAndroid Build Coastguard Worker    %rax = COPY %rdi
32*9880d681SAndroid Build Coastguard Worker    NOOP implicit killed %rdi
33*9880d681SAndroid Build Coastguard Worker    %rdi = COPY %rax
34*9880d681SAndroid Build Coastguard Worker    NOOP implicit %rax, implicit %rdi
35*9880d681SAndroid Build Coastguard Worker...
36*9880d681SAndroid Build Coastguard Worker---
37*9880d681SAndroid Build Coastguard Worker# The second copy is redundant and will be removed, check that we also remove
38*9880d681SAndroid Build Coastguard Worker# the kill flag of intermediate instructions.
39*9880d681SAndroid Build Coastguard Worker# CHECK-LABEL: name: copyprop_remove_kill1
40*9880d681SAndroid Build Coastguard Worker# CHECK: bb.0:
41*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: %rax = COPY %rdi
42*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: NOOP implicit %edi
43*9880d681SAndroid Build Coastguard Worker# CHECK-NOT: COPY
44*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: NOOP implicit %rax, implicit %rdi
45*9880d681SAndroid Build Coastguard Workername: copyprop_remove_kill1
46*9880d681SAndroid Build Coastguard WorkerallVRegsAllocated: true
47*9880d681SAndroid Build Coastguard Workerbody: |
48*9880d681SAndroid Build Coastguard Worker  bb.0:
49*9880d681SAndroid Build Coastguard Worker    %rax = COPY %rdi
50*9880d681SAndroid Build Coastguard Worker    NOOP implicit killed %edi
51*9880d681SAndroid Build Coastguard Worker    %rdi = COPY %rax
52*9880d681SAndroid Build Coastguard Worker    NOOP implicit %rax, implicit %rdi
53*9880d681SAndroid Build Coastguard Worker...
54*9880d681SAndroid Build Coastguard Worker---
55*9880d681SAndroid Build Coastguard Worker# The second copy is redundant and will be removed, check that we also remove
56*9880d681SAndroid Build Coastguard Worker# the kill flag of intermediate instructions.
57*9880d681SAndroid Build Coastguard Worker# CHECK-LABEL: name: copyprop_remove_kill2
58*9880d681SAndroid Build Coastguard Worker# CHECK: bb.0:
59*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: %ax = COPY %di
60*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: NOOP implicit %rdi
61*9880d681SAndroid Build Coastguard Worker# CHECK-NOT: COPY
62*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: NOOP implicit %rax, implicit %rdi
63*9880d681SAndroid Build Coastguard Workername: copyprop_remove_kill2
64*9880d681SAndroid Build Coastguard WorkerallVRegsAllocated: true
65*9880d681SAndroid Build Coastguard Workerbody: |
66*9880d681SAndroid Build Coastguard Worker  bb.0:
67*9880d681SAndroid Build Coastguard Worker    %ax = COPY %di
68*9880d681SAndroid Build Coastguard Worker    NOOP implicit killed %rdi
69*9880d681SAndroid Build Coastguard Worker    %di = COPY %ax
70*9880d681SAndroid Build Coastguard Worker    NOOP implicit %rax, implicit %rdi
71*9880d681SAndroid Build Coastguard Worker...
72*9880d681SAndroid Build Coastguard Worker---
73*9880d681SAndroid Build Coastguard Worker# The second copy is redundant; the call preserves the source and dest register.
74*9880d681SAndroid Build Coastguard Worker# CHECK-LABEL: name: copyprop0
75*9880d681SAndroid Build Coastguard Worker# CHECK: bb.0:
76*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: %rax = COPY %rdi
77*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: CALL64pcrel32 @foo, csr_64_rt_mostregs
78*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: NOOP implicit %edi
79*9880d681SAndroid Build Coastguard Worker# CHECK-NOT: COPY
80*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: NOOP implicit %rax, implicit %rdi
81*9880d681SAndroid Build Coastguard Workername: copyprop0
82*9880d681SAndroid Build Coastguard WorkerallVRegsAllocated: true
83*9880d681SAndroid Build Coastguard Workerbody: |
84*9880d681SAndroid Build Coastguard Worker  bb.0:
85*9880d681SAndroid Build Coastguard Worker    %rax = COPY %rdi
86*9880d681SAndroid Build Coastguard Worker    CALL64pcrel32 @foo, csr_64_rt_mostregs
87*9880d681SAndroid Build Coastguard Worker    NOOP implicit killed %edi
88*9880d681SAndroid Build Coastguard Worker    %rdi = COPY %rax
89*9880d681SAndroid Build Coastguard Worker    NOOP implicit %rax, implicit %rdi
90*9880d681SAndroid Build Coastguard Worker...
91*9880d681SAndroid Build Coastguard Worker---
92*9880d681SAndroid Build Coastguard Worker# The 2nd copy is redundant; The call preserves the source and dest register.
93*9880d681SAndroid Build Coastguard Worker# CHECK-LABEL: name: copyprop1
94*9880d681SAndroid Build Coastguard Worker# CHECK: bb.0:
95*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: %rax = COPY %rdi
96*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: NOOP implicit %rax
97*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: NOOP implicit %rax, implicit %rdi
98*9880d681SAndroid Build Coastguard Workername: copyprop1
99*9880d681SAndroid Build Coastguard WorkerallVRegsAllocated: true
100*9880d681SAndroid Build Coastguard Workerbody: |
101*9880d681SAndroid Build Coastguard Worker  bb.0:
102*9880d681SAndroid Build Coastguard Worker    %rax = COPY %rdi
103*9880d681SAndroid Build Coastguard Worker    NOOP implicit killed %rax
104*9880d681SAndroid Build Coastguard Worker    %rax = COPY %rdi
105*9880d681SAndroid Build Coastguard Worker    NOOP implicit %rax, implicit %rdi
106*9880d681SAndroid Build Coastguard Worker...
107*9880d681SAndroid Build Coastguard Worker---
108*9880d681SAndroid Build Coastguard Worker# CHECK-LABEL: name: copyprop2
109*9880d681SAndroid Build Coastguard Worker# CHECK: bb.0:
110*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: %rax = COPY %rdi
111*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: NOOP implicit %ax
112*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: CALL64pcrel32 @foo, csr_64_rt_mostregs
113*9880d681SAndroid Build Coastguard Worker# CHECK-NOT: %rax = COPY %rdi
114*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: NOOP implicit %rax, implicit %rdi
115*9880d681SAndroid Build Coastguard Workername: copyprop2
116*9880d681SAndroid Build Coastguard WorkerallVRegsAllocated: true
117*9880d681SAndroid Build Coastguard Workerbody: |
118*9880d681SAndroid Build Coastguard Worker  bb.0:
119*9880d681SAndroid Build Coastguard Worker    %rax = COPY %rdi
120*9880d681SAndroid Build Coastguard Worker    NOOP implicit killed %ax
121*9880d681SAndroid Build Coastguard Worker    CALL64pcrel32 @foo, csr_64_rt_mostregs
122*9880d681SAndroid Build Coastguard Worker    %rax = COPY %rdi
123*9880d681SAndroid Build Coastguard Worker    NOOP implicit %rax, implicit %rdi
124*9880d681SAndroid Build Coastguard Worker...
125*9880d681SAndroid Build Coastguard Worker---
126*9880d681SAndroid Build Coastguard Worker# The second copy is not redundant if the source register (%rax) is clobbered
127*9880d681SAndroid Build Coastguard Worker# even if the dest (%rbp) is not.
128*9880d681SAndroid Build Coastguard Worker# CHECK-LABEL: name: nocopyprop0
129*9880d681SAndroid Build Coastguard Worker# CHECK: bb.0:
130*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: %rax = COPY %rbp
131*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: CALL64pcrel32 @foo, csr_64, implicit %rax, implicit %rbp
132*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: %rbp = COPY %rax
133*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: NOOP implicit %rax, implicit %rbp
134*9880d681SAndroid Build Coastguard Workername: nocopyprop0
135*9880d681SAndroid Build Coastguard WorkerallVRegsAllocated: true
136*9880d681SAndroid Build Coastguard Workerbody: |
137*9880d681SAndroid Build Coastguard Worker  bb.0:
138*9880d681SAndroid Build Coastguard Worker    %rax = COPY %rbp
139*9880d681SAndroid Build Coastguard Worker    CALL64pcrel32 @foo, csr_64, implicit %rax, implicit %rbp
140*9880d681SAndroid Build Coastguard Worker    %rbp = COPY %rax
141*9880d681SAndroid Build Coastguard Worker    NOOP implicit %rax, implicit %rbp
142*9880d681SAndroid Build Coastguard Worker...
143*9880d681SAndroid Build Coastguard Worker---
144*9880d681SAndroid Build Coastguard Worker# The second copy is not redundant if the dest register (%rax) is clobbered
145*9880d681SAndroid Build Coastguard Worker# even if the source (%rbp) is not.
146*9880d681SAndroid Build Coastguard Worker# CHECK-LABEL: name: nocopyprop1
147*9880d681SAndroid Build Coastguard Worker# CHECK: bb.0:
148*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: %rbp = COPY %rax
149*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: CALL64pcrel32 @foo, csr_64, implicit %rax, implicit %rbp
150*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: %rax = COPY %rbp
151*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: NOOP implicit %rax, implicit %rbp
152*9880d681SAndroid Build Coastguard Workername: nocopyprop1
153*9880d681SAndroid Build Coastguard WorkerallVRegsAllocated: true
154*9880d681SAndroid Build Coastguard Workerbody: |
155*9880d681SAndroid Build Coastguard Worker  bb.0:
156*9880d681SAndroid Build Coastguard Worker    %rbp = COPY %rax
157*9880d681SAndroid Build Coastguard Worker    CALL64pcrel32 @foo, csr_64, implicit %rax, implicit %rbp
158*9880d681SAndroid Build Coastguard Worker    %rax = COPY %rbp
159*9880d681SAndroid Build Coastguard Worker    NOOP implicit %rax, implicit %rbp
160*9880d681SAndroid Build Coastguard Worker...
161*9880d681SAndroid Build Coastguard Worker---
162*9880d681SAndroid Build Coastguard Worker# The second copy is not redundant if the source register (%rax) is clobbered
163*9880d681SAndroid Build Coastguard Worker# even if the dest (%rbp) is not.
164*9880d681SAndroid Build Coastguard Worker# CHECK-LABEL: name: nocopyprop2
165*9880d681SAndroid Build Coastguard Worker# CHECK: bb.0:
166*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: %rax = COPY %rbp
167*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: CALL64pcrel32 @foo, csr_64, implicit %rax, implicit %rbp
168*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: %rax = COPY %rbp
169*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: NOOP implicit %rax, implicit %rbp
170*9880d681SAndroid Build Coastguard Workername: nocopyprop2
171*9880d681SAndroid Build Coastguard WorkerallVRegsAllocated: true
172*9880d681SAndroid Build Coastguard Workerbody: |
173*9880d681SAndroid Build Coastguard Worker  bb.0:
174*9880d681SAndroid Build Coastguard Worker    %rax = COPY %rbp
175*9880d681SAndroid Build Coastguard Worker    CALL64pcrel32 @foo, csr_64, implicit %rax, implicit %rbp
176*9880d681SAndroid Build Coastguard Worker    %rax = COPY %rbp
177*9880d681SAndroid Build Coastguard Worker    NOOP implicit %rax, implicit %rbp
178*9880d681SAndroid Build Coastguard Worker...
179*9880d681SAndroid Build Coastguard Worker---
180*9880d681SAndroid Build Coastguard Worker# The second copy is not redundant if the dest register (%rax) is clobbered
181*9880d681SAndroid Build Coastguard Worker# even if the source (%rbp) is not.
182*9880d681SAndroid Build Coastguard Worker# CHECK-LABEL: name: nocopyprop3
183*9880d681SAndroid Build Coastguard Worker# CHECK: bb.0:
184*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: %rbp = COPY %rax
185*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: CALL64pcrel32 @foo, csr_64, implicit %rax, implicit %rbp
186*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: %rbp = COPY %rax
187*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: NOOP implicit %rax, implicit %rbp
188*9880d681SAndroid Build Coastguard Workername: nocopyprop3
189*9880d681SAndroid Build Coastguard WorkerallVRegsAllocated: true
190*9880d681SAndroid Build Coastguard Workerbody: |
191*9880d681SAndroid Build Coastguard Worker  bb.0:
192*9880d681SAndroid Build Coastguard Worker    %rbp = COPY %rax
193*9880d681SAndroid Build Coastguard Worker    CALL64pcrel32 @foo, csr_64, implicit %rax, implicit %rbp
194*9880d681SAndroid Build Coastguard Worker    %rbp = COPY %rax
195*9880d681SAndroid Build Coastguard Worker    NOOP implicit %rax, implicit %rbp
196*9880d681SAndroid Build Coastguard Worker...
197*9880d681SAndroid Build Coastguard Worker---
198*9880d681SAndroid Build Coastguard Worker# A reserved register may change its value so the 2nd copy is not redundant.
199*9880d681SAndroid Build Coastguard Worker# CHECK-LABEL: name: nocopyprop4
200*9880d681SAndroid Build Coastguard Worker# CHECK: bb.0:
201*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: %rax = COPY %rip
202*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: NOOP implicit %rax
203*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: %rax = COPY %rip
204*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: NOOP implicit %rax
205*9880d681SAndroid Build Coastguard Workername: nocopyprop4
206*9880d681SAndroid Build Coastguard WorkerallVRegsAllocated: true
207*9880d681SAndroid Build Coastguard Workerbody: |
208*9880d681SAndroid Build Coastguard Worker  bb.0:
209*9880d681SAndroid Build Coastguard Worker    %rax = COPY %rip
210*9880d681SAndroid Build Coastguard Worker    NOOP implicit %rax
211*9880d681SAndroid Build Coastguard Worker    %rax = COPY %rip
212*9880d681SAndroid Build Coastguard Worker    NOOP implicit %rax
213*9880d681SAndroid Build Coastguard Worker...
214*9880d681SAndroid Build Coastguard Worker---
215*9880d681SAndroid Build Coastguard Worker# Writing to a reserved register may have additional effects (slightly illegal
216*9880d681SAndroid Build Coastguard Worker# testcase because writing to %rip like this should make the instruction a jump)
217*9880d681SAndroid Build Coastguard Worker# CHECK-LABEL: name: nocopyprop5
218*9880d681SAndroid Build Coastguard Worker# CHECK: bb.0:
219*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: %rip = COPY %rax
220*9880d681SAndroid Build Coastguard Worker# CHECK-NEXT: %rip = COPY %rax
221*9880d681SAndroid Build Coastguard Workername: nocopyprop5
222*9880d681SAndroid Build Coastguard WorkerallVRegsAllocated: true
223*9880d681SAndroid Build Coastguard Workerbody: |
224*9880d681SAndroid Build Coastguard Worker  bb.0:
225*9880d681SAndroid Build Coastguard Worker    %rip = COPY %rax
226*9880d681SAndroid Build Coastguard Worker    %rip = COPY %rax
227*9880d681SAndroid Build Coastguard Worker...
228