Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / test / CodeGen / AMDGPU / s_or_saveexec_xor_combine.mir
blobc5d667158afdf2489eedac8b63e1107ba8e27335
1 # RUN: llc -march=amdgcn -mcpu=gfx1010 -mattr=+wavefrontsize32 -run-pass=si-optimize-exec-masking -verify-machineinstrs %s -o - | FileCheck --check-prefixes=GCN,WAVE32 %s
2 # RUN: llc -march=amdgcn -mcpu=gfx1010 -mattr=-wavefrontsize32,+wavefrontsize64 -run-pass=si-optimize-exec-masking -verify-machineinstrs %s -o - | FileCheck --check-prefixes=GCN,WAVE64 %s
4 ---
6 # After the Optimize exec masking (post-RA) pass, codegen can end up with the following sequence:
7 # s_or_saveexec_b32 s0, s0
8 # s_xor_b32 exec_lo, exec_lo, s0
10 # This can be combined into one instruction:
11 # s_andn2_saveexec_b32 s0, s0
13 # Ensure the transformation gets applied in the b32 case.
14 # GCN-LABEL: name: s_or_saveexec_xor_combine_b32
15 # WAVE32: S_ANDN2_SAVEEXEC_B32
16 name: s_or_saveexec_xor_combine_b32
17 tracksRegLiveness: true
18 body: |
19   bb.0:
20     liveins: $sgpr0
21     renamable $sgpr0 = S_OR_SAVEEXEC_B32 killed renamable $sgpr0, implicit-def $exec, implicit-def $scc, implicit $exec
22     $exec_lo = S_XOR_B32 $exec_lo, renamable $sgpr0, implicit-def $scc
23 ...
25 ---
27 # Ensure the transformation gets applied in the b64 case.
28 # GCN-LABEL: name: s_or_saveexec_xor_combine_b64
29 # WAVE64: S_ANDN2_SAVEEXEC_B64
30 name: s_or_saveexec_xor_combine_b64
31 tracksRegLiveness: true
32 body: |
33   bb.0:
34     liveins: $sgpr0_sgpr1
35     renamable $sgpr0_sgpr1 = S_OR_SAVEEXEC_B64 killed renamable $sgpr0_sgpr1, implicit-def $exec, implicit-def $scc, implicit $exec
36     $exec = S_XOR_B64 $exec, renamable $sgpr0_sgpr1, implicit-def $scc
37 ...
39 ---
41 # Ensure the transformation does get applied even if the operands are swapped.
42 # GCN-LABEL: name: s_or_saveexec_xor_combine_b32_swap
43 # WAVE32: S_ANDN2_SAVEEXEC_B32
44 name: s_or_saveexec_xor_combine_b32_swap
45 tracksRegLiveness: true
46 body: |
47   bb.0:
48     liveins: $sgpr0
49     renamable $sgpr0 = S_OR_SAVEEXEC_B32 killed renamable $sgpr0, implicit-def $exec, implicit-def $scc, implicit $exec
50     $exec_lo = S_XOR_B32 renamable $sgpr0, $exec_lo, implicit-def $scc
51 ...
53 ---
55 # Ensure the transformation does get applied if source and dest operand for s_or_saveeexec are not equal.
56 # GCN-LABEL: name: s_or_saveexec_xor_combine_b32_inequal_operands
57 # WAVE32: S_ANDN2_SAVEEXEC
58 name: s_or_saveexec_xor_combine_b32_inequal_operands
59 tracksRegLiveness: true
60 body: |
61   bb.0:
62     liveins: $sgpr0, $sgpr1
63     renamable $sgpr0 = S_OR_SAVEEXEC_B32 killed renamable $sgpr1, implicit-def $exec, implicit-def $scc, implicit $exec
64     $exec_lo = S_XOR_B32 $exec_lo, renamable $sgpr0, implicit-def $scc
65 ...
67 ---
69 # Ensure the transformation does not get applied if s_xor does not use the dest as input operand.
70 # GCN-LABEL: name: s_or_saveexec_xor_combine_b32_wrong_input
71 # WAVE32: S_OR_SAVEEXEC
72 # WAVE32: S_XOR_B32
73 name: s_or_saveexec_xor_combine_b32_wrong_input
74 tracksRegLiveness: true
75 body: |
76   bb.0:
77     liveins: $sgpr0, $sgpr1
78     renamable $sgpr0 = S_OR_SAVEEXEC_B32 killed renamable $sgpr0, implicit-def $exec, implicit-def $scc, implicit $exec
79     $exec_lo = S_XOR_B32 $exec_lo, renamable $sgpr1, implicit-def $scc
80 ...
82 ---
85 # Ensure the transformation does not get applied if the instructions don't appear sequentially.
86 # GCN-LABEL: name: s_or_saveexec_xor_combine_b32_non_sequence
87 # WAVE32: S_OR_SAVEEXEC
88 # WAVE32: S_MOV_B32
89 # WAVE32: S_XOR_B32
90 name: s_or_saveexec_xor_combine_b32_non_sequence
91 tracksRegLiveness: true
92 body: |
93   bb.0:
94     liveins: $sgpr0, $sgpr1
95     renamable $sgpr0 = S_OR_SAVEEXEC_B32 killed renamable $sgpr0, implicit-def $exec, implicit-def $scc, implicit $exec
96     renamable $sgpr1 = S_MOV_B32 renamable $sgpr0
97     $exec_lo = S_XOR_B32 $exec_lo, renamable $sgpr1, implicit-def $scc
98 ...
102 # Don't apply the transformation if the basic block only has a single instruction.
104 # GCN-LABEL: name: s_or_saveexec_xor_combine_b32_last_inst
105 # WAVE32: S_OR_SAVEEXEC
106 name: s_or_saveexec_xor_combine_b32_last_inst
107 tracksRegLiveness: true
108 body: |
109   bb.0:
110     liveins: $sgpr0
111     renamable $sgpr0 = S_OR_SAVEEXEC_B32 killed renamable $sgpr0, implicit-def $exec, implicit-def $scc, implicit $exec
116 # Don't apply the transformation if the basic block ends with an S_OR_SAVEEXEC_B32 instruction.
118 # GCN-LABEL: name: s_or_saveexec_xor_combine_b32_or_saveexec_terminator
119 # WAVE32: S_MOV_B32
120 # WAVE32: S_OR_SAVEEXEC
121 name: s_or_saveexec_xor_combine_b32_or_saveexec_terminator
122 tracksRegLiveness: true
123 body: |
124   bb.0:
125     liveins: $sgpr0, $sgpr1
126     renamable $sgpr1 = S_MOV_B32 renamable $sgpr0
127     renamable $sgpr0 = S_OR_SAVEEXEC_B32 killed renamable $sgpr0, implicit-def $exec, implicit-def $scc, implicit $exec