Skip to content

Commit 3c8bc54

Browse files
committed
Extend tests
Further changes: - Add debug output for missing carry-in def.
1 parent af365ee commit 3c8bc54

File tree

4 files changed

+329
-50
lines changed

4 files changed

+329
-50
lines changed

llvm/lib/Target/AMDGPU/SIPeepholeSDWA.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,16 +1084,18 @@ void SIPeepholeSDWA::convertVcndmaskToVOP2(MachineInstr &MI,
10841084
*TII->getNamedOperand(MI, AMDGPU::OpName::src2);
10851085
Register CarryReg = CarryIn.getReg();
10861086
MachineInstr *CarryDef = MRI->getVRegDef(CarryReg);
1087-
if (!CarryDef)
1087+
if (!CarryDef) {
1088+
LLVM_DEBUG(dbgs() << "Missing carry-in operand definition\n");
10881089
return;
1090+
}
10891091

10901092
// Make sure VCC or its subregs are dead before MI.
10911093
MCRegister Vcc = TRI->getVCC();
10921094
MachineBasicBlock &MBB = *MI.getParent();
10931095
MachineBasicBlock::LivenessQueryResult Liveness =
10941096
MBB.computeRegisterLiveness(TRI, Vcc, MI);
10951097
if (Liveness != MachineBasicBlock::LQR_Dead) {
1096-
LLVM_DEBUG(dbgs() << "VCC not known to be dead before instruction.\n");
1098+
LLVM_DEBUG(dbgs() << "VCC not known to be dead before instruction\n");
10971099
return;
10981100
}
10991101

llvm/test/CodeGen/AMDGPU/sdwa-peephole-cndmask-vop2.mir

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
2-
# RUN: llc -mtriple=amdgcn-amd-amdhsa -run-pass=si-peephole-sdwa -mcpu=gfx803 -o - %s | FileCheck -check-prefix=gfx8 %s
3-
# RUN: llc -mtriple=amdgcn-amd-amdhsa -run-pass=si-peephole-sdwa -mcpu=gfx1100 -o - %s | FileCheck -check-prefix=gfx11 %s
2+
# RUN: llc -mtriple=amdgcn-amd-amdhsa -run-pass=si-peephole-sdwa -mcpu=gfx803 -o - %s | FileCheck -check-prefix=GFX8 %s
3+
# RUN: llc -mtriple=amdgcn-amd-amdhsa -run-pass=si-peephole-sdwa -mcpu=gfx1100 -o - %s | FileCheck -check-prefix=GFX11 %s
44

55
---
66
name: v_cndmask_b32_test
@@ -9,27 +9,27 @@ body: |
99
bb.0:
1010
liveins: $vgpr0, $vgpr1, $vcc
1111
12-
; gfx8-LABEL: name: v_cndmask_b32_test
13-
; gfx8: liveins: $vgpr0, $vgpr1, $vcc
14-
; gfx8-NEXT: {{ $}}
15-
; gfx8-NEXT: [[COPY:%[0-9]+]]:vgpr_32 = COPY $vgpr1
16-
; gfx8-NEXT: [[COPY1:%[0-9]+]]:vgpr_32 = COPY $vgpr0
17-
; gfx8-NEXT: [[V_LSHRREV_B32_e64_:%[0-9]+]]:vgpr_32 = V_LSHRREV_B32_e64 16, [[COPY]], implicit $exec
18-
; gfx8-NEXT: [[V_LSHRREV_B32_e64_1:%[0-9]+]]:vgpr_32 = V_LSHRREV_B32_e64 16, [[COPY1]], implicit $exec
19-
; gfx8-NEXT: [[V_CNDMASK_B32_sdwa:%[0-9]+]]:vgpr_32 = V_CNDMASK_B32_sdwa 0, [[COPY]], 0, [[COPY1]], 0, 6, 0, 5, 5, implicit $vcc, implicit $exec
20-
; gfx8-NEXT: $vgpr0 = COPY [[V_CNDMASK_B32_sdwa]]
21-
; gfx8-NEXT: SI_RETURN implicit $vgpr0
12+
; GFX8-LABEL: name: v_cndmask_b32_test
13+
; GFX8: liveins: $vgpr0, $vgpr1, $vcc
14+
; GFX8-NEXT: {{ $}}
15+
; GFX8-NEXT: [[COPY:%[0-9]+]]:vgpr_32 = COPY $vgpr1
16+
; GFX8-NEXT: [[COPY1:%[0-9]+]]:vgpr_32 = COPY $vgpr0
17+
; GFX8-NEXT: [[V_LSHRREV_B32_e64_:%[0-9]+]]:vgpr_32 = V_LSHRREV_B32_e64 16, [[COPY]], implicit $exec
18+
; GFX8-NEXT: [[V_LSHRREV_B32_e64_1:%[0-9]+]]:vgpr_32 = V_LSHRREV_B32_e64 16, [[COPY1]], implicit $exec
19+
; GFX8-NEXT: [[V_CNDMASK_B32_sdwa:%[0-9]+]]:vgpr_32 = V_CNDMASK_B32_sdwa 0, [[COPY]], 0, [[COPY1]], 0, 6, 0, 5, 5, implicit $vcc, implicit $exec
20+
; GFX8-NEXT: $vgpr0 = COPY [[V_CNDMASK_B32_sdwa]]
21+
; GFX8-NEXT: SI_RETURN implicit $vgpr0
2222
;
23-
; gfx11-LABEL: name: v_cndmask_b32_test
24-
; gfx11: liveins: $vgpr0, $vgpr1, $vcc
25-
; gfx11-NEXT: {{ $}}
26-
; gfx11-NEXT: [[COPY:%[0-9]+]]:vgpr_32 = COPY $vgpr1
27-
; gfx11-NEXT: [[COPY1:%[0-9]+]]:vgpr_32 = COPY $vgpr0
28-
; gfx11-NEXT: [[V_LSHRREV_B32_e64_:%[0-9]+]]:vgpr_32 = V_LSHRREV_B32_e64 16, [[COPY]], implicit $exec
29-
; gfx11-NEXT: [[V_LSHRREV_B32_e64_1:%[0-9]+]]:vgpr_32 = V_LSHRREV_B32_e64 16, [[COPY1]], implicit $exec
30-
; gfx11-NEXT: [[V_CNDMASK_B32_e32_:%[0-9]+]]:vgpr_32 = V_CNDMASK_B32_e32 killed [[V_LSHRREV_B32_e64_]], killed [[V_LSHRREV_B32_e64_1]], implicit $exec, implicit $vcc_lo
31-
; gfx11-NEXT: $vgpr0 = COPY [[V_CNDMASK_B32_e32_]]
32-
; gfx11-NEXT: SI_RETURN implicit $vgpr0
23+
; GFX11-LABEL: name: v_cndmask_b32_test
24+
; GFX11: liveins: $vgpr0, $vgpr1, $vcc
25+
; GFX11-NEXT: {{ $}}
26+
; GFX11-NEXT: [[COPY:%[0-9]+]]:vgpr_32 = COPY $vgpr1
27+
; GFX11-NEXT: [[COPY1:%[0-9]+]]:vgpr_32 = COPY $vgpr0
28+
; GFX11-NEXT: [[V_LSHRREV_B32_e64_:%[0-9]+]]:vgpr_32 = V_LSHRREV_B32_e64 16, [[COPY]], implicit $exec
29+
; GFX11-NEXT: [[V_LSHRREV_B32_e64_1:%[0-9]+]]:vgpr_32 = V_LSHRREV_B32_e64 16, [[COPY1]], implicit $exec
30+
; GFX11-NEXT: [[V_CNDMASK_B32_e32_:%[0-9]+]]:vgpr_32 = V_CNDMASK_B32_e32 killed [[V_LSHRREV_B32_e64_]], killed [[V_LSHRREV_B32_e64_1]], implicit $exec, implicit $vcc_lo
31+
; GFX11-NEXT: $vgpr0 = COPY [[V_CNDMASK_B32_e32_]]
32+
; GFX11-NEXT: SI_RETURN implicit $vgpr0
3333
%1:vgpr_32 = COPY $vgpr1
3434
%2:vgpr_32 = COPY $vgpr0
3535
%3:vgpr_32 = V_LSHRREV_B32_e64 16, %1, implicit $exec
Lines changed: 150 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,172 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
22
# RUN: llc %s -mtriple=amdgcn -mcpu=gfx1030 -run-pass=si-peephole-sdwa -o - | FileCheck %s
33

4+
---
5+
name: change-compare-to-vopc # carry-in def is a comparison that can be changed to VOPC
6+
tracksRegLiveness: true
7+
body: |
8+
bb.0:
9+
liveins: $vgpr0
10+
11+
; CHECK-LABEL: name: change-compare-to-vopc
12+
; CHECK: liveins: $vgpr0
13+
; CHECK-NEXT: {{ $}}
14+
; CHECK-NEXT: [[DEF:%[0-9]+]]:sreg_32_xm0_xexec = IMPLICIT_DEF
15+
; CHECK-NEXT: [[DEF1:%[0-9]+]]:vgpr_32 = IMPLICIT_DEF
16+
; CHECK-NEXT: $vcc_lo = V_CMP_EQ_U32_e64 undef [[DEF]], 1, implicit $exec
17+
; CHECK-NEXT: [[V_LSHRREV_B32_e64_:%[0-9]+]]:vgpr_32 = V_LSHRREV_B32_e64 16, undef [[DEF1]], implicit $exec
18+
; CHECK-NEXT: [[V_MOV_B32_e32_:%[0-9]+]]:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
19+
; CHECK-NEXT: [[V_CNDMASK_B32_sdwa:%[0-9]+]]:vgpr_32 = V_CNDMASK_B32_sdwa 0, [[V_MOV_B32_e32_]], 0, undef [[DEF1]], 0, 6, 0, 6, 5, implicit $vcc_lo, implicit $exec
20+
; CHECK-NEXT: $vgpr0 = COPY [[V_CNDMASK_B32_sdwa]]
21+
; CHECK-NEXT: SI_RETURN implicit $vgpr0
22+
%0:sreg_32_xm0_xexec = IMPLICIT_DEF
23+
%1:vgpr_32 = IMPLICIT_DEF
24+
%2:sreg_32_xm0_xexec = V_CMP_EQ_U32_e64 undef %0, 1, implicit $exec
25+
%3:vgpr_32 = V_LSHRREV_B32_e64 16, undef %1, implicit $exec
26+
%4:vgpr_32 = V_CNDMASK_B32_e64 0, 0, 0, %3, killed %2, implicit $exec
27+
$vgpr0 = COPY %4
28+
SI_RETURN implicit $vgpr0
29+
...
30+
431
...
532
---
6-
name: v_maximum_v2f16
33+
name: carry-copy-non-compare # copy of carry-in necessary because def. instr. cannot be changed to write to VCC
734
tracksRegLiveness: true
835
body: |
936
bb.0:
1037
liveins: $vgpr0
1138
12-
; CHECK-LABEL: name: v_maximum_v2f16
39+
; CHECK-LABEL: name: carry-copy-non-compare
1340
; CHECK: liveins: $vgpr0
1441
; CHECK-NEXT: {{ $}}
1542
; CHECK-NEXT: [[DEF:%[0-9]+]]:sreg_32_xm0_xexec = IMPLICIT_DEF
1643
; CHECK-NEXT: [[DEF1:%[0-9]+]]:vgpr_32 = IMPLICIT_DEF
1744
; CHECK-NEXT: [[V_PK_MAX_F16_:%[0-9]+]]:vgpr_32 = V_PK_MAX_F16 8, undef [[DEF1]], 8, undef [[DEF1]], 0, 0, 0, 0, 0, implicit $mode, implicit $exec
18-
; CHECK-NEXT: [[V_LSHRREV_B32_e64_:%[0-9]+]]:vgpr_32 = V_LSHRREV_B32_e64 16, undef [[V_PK_MAX_F16_]], implicit $exec
45+
; CHECK-NEXT: [[V_LSHRREV_B32_e64_:%[0-9]+]]:vgpr_32 = V_LSHRREV_B32_e64 16, [[V_PK_MAX_F16_]], implicit $exec
1946
; CHECK-NEXT: $vcc_lo = COPY killed undef [[DEF]]
20-
; CHECK-NEXT: [[V_MOV_B32_e32_:%[0-9]+]]:vgpr_32 = V_MOV_B32_e32 32256, implicit $exec
21-
; CHECK-NEXT: [[V_CNDMASK_B32_sdwa:%[0-9]+]]:vgpr_32 = V_CNDMASK_B32_sdwa 0, [[V_MOV_B32_e32_]], 0, undef [[V_PK_MAX_F16_]], 0, 6, 0, 6, 5, implicit $vcc_lo, implicit $exec
47+
; CHECK-NEXT: [[V_MOV_B32_e32_:%[0-9]+]]:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
48+
; CHECK-NEXT: [[V_CNDMASK_B32_sdwa:%[0-9]+]]:vgpr_32 = V_CNDMASK_B32_sdwa 0, [[V_MOV_B32_e32_]], 0, [[V_PK_MAX_F16_]], 0, 6, 0, 6, 5, implicit $vcc_lo, implicit $exec
2249
; CHECK-NEXT: $vgpr0 = COPY [[V_CNDMASK_B32_sdwa]]
2350
; CHECK-NEXT: SI_RETURN implicit $vgpr0
24-
%1:sreg_32_xm0_xexec = IMPLICIT_DEF
51+
%0:sreg_32_xm0_xexec = IMPLICIT_DEF
52+
%1:vgpr_32 = IMPLICIT_DEF
53+
%2:vgpr_32 = V_PK_MAX_F16 8, undef %1, 8, undef %1, 0, 0, 0, 0, 0, implicit $mode, implicit $exec
54+
%3:vgpr_32 = V_LSHRREV_B32_e64 16, %2, implicit $exec
55+
%4:vgpr_32 = V_CNDMASK_B32_e64 0, 0, 0, undef %3, killed undef %0, implicit $exec
56+
$vgpr0 = COPY %4
57+
SI_RETURN implicit $vgpr0
58+
...
59+
60+
...
61+
---
62+
name: carry-copy-multiuse # copy of carry-in necessary because of second use
63+
tracksRegLiveness: true
64+
body: |
65+
bb.0:
66+
liveins: $vgpr0, $vgpr1
67+
68+
; CHECK-LABEL: name: carry-copy-multiuse
69+
; CHECK: liveins: $vgpr0, $vgpr1
70+
; CHECK-NEXT: {{ $}}
71+
; CHECK-NEXT: [[DEF:%[0-9]+]]:sreg_32_xm0_xexec = IMPLICIT_DEF
72+
; CHECK-NEXT: [[DEF1:%[0-9]+]]:vgpr_32 = IMPLICIT_DEF
73+
; CHECK-NEXT: [[V_PK_MAX_F16_:%[0-9]+]]:vgpr_32 = V_PK_MAX_F16 8, undef [[DEF1]], 8, undef [[DEF1]], 0, 0, 0, 0, 0, implicit $mode, implicit $exec
74+
; CHECK-NEXT: [[V_LSHRREV_B32_e64_:%[0-9]+]]:vgpr_32 = V_LSHRREV_B32_e64 16, [[V_PK_MAX_F16_]], implicit $exec
75+
; CHECK-NEXT: $vcc_lo = COPY killed undef [[DEF]]
76+
; CHECK-NEXT: [[V_MOV_B32_e32_:%[0-9]+]]:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
77+
; CHECK-NEXT: [[V_CNDMASK_B32_sdwa:%[0-9]+]]:vgpr_32 = V_CNDMASK_B32_sdwa 0, [[V_MOV_B32_e32_]], 0, [[V_PK_MAX_F16_]], 0, 6, 0, 6, 5, implicit $vcc_lo, implicit $exec
78+
; CHECK-NEXT: $vgpr0 = COPY [[V_CNDMASK_B32_sdwa]]
79+
; CHECK-NEXT: $vgpr1 = COPY [[DEF]]
80+
; CHECK-NEXT: SI_RETURN implicit $vgpr0
81+
%0:sreg_32_xm0_xexec = IMPLICIT_DEF
82+
%1:vgpr_32 = IMPLICIT_DEF
83+
%2:vgpr_32 = V_PK_MAX_F16 8, undef %1, 8, undef %1, 0, 0, 0, 0, 0, implicit $mode, implicit $exec
84+
%3:vgpr_32 = V_LSHRREV_B32_e64 16, %2, implicit $exec
85+
%4:vgpr_32 = V_CNDMASK_B32_e64 0, 0, 0, %3, killed undef %0, implicit $exec
86+
$vgpr0 = COPY %4
87+
$vgpr1 = COPY %0
88+
SI_RETURN implicit $vgpr0
89+
...
90+
91+
...
92+
---
93+
name: live-vcc # cannot convert because of live VCC
94+
tracksRegLiveness: true
95+
body: |
96+
bb.0:
97+
liveins: $vgpr0
98+
99+
; CHECK-LABEL: name: live-vcc
100+
; CHECK: liveins: $vgpr0
101+
; CHECK-NEXT: {{ $}}
102+
; CHECK-NEXT: [[DEF:%[0-9]+]]:sreg_32_xm0_xexec = IMPLICIT_DEF
103+
; CHECK-NEXT: [[DEF1:%[0-9]+]]:vgpr_32 = IMPLICIT_DEF
104+
; CHECK-NEXT: [[V_CMP_EQ_U32_e64_:%[0-9]+]]:sreg_32_xm0_xexec = V_CMP_EQ_U32_e64 undef [[DEF]], 1, implicit $exec
105+
; CHECK-NEXT: [[V_LSHRREV_B32_e64_:%[0-9]+]]:vgpr_32 = V_LSHRREV_B32_e64 16, undef [[DEF1]], implicit $exec
106+
; CHECK-NEXT: V_CMP_EQ_U32_e32 1, undef [[DEF1]], implicit-def $vcc_lo, implicit $exec
107+
; CHECK-NEXT: [[V_CNDMASK_B32_e64_:%[0-9]+]]:vgpr_32 = V_CNDMASK_B32_e64 0, 0, 0, [[V_LSHRREV_B32_e64_]], [[V_CMP_EQ_U32_e64_]], implicit $exec
108+
; CHECK-NEXT: [[V_CNDMASK_B32_e32_:%[0-9]+]]:vgpr_32 = V_CNDMASK_B32_e32 killed [[V_LSHRREV_B32_e64_]], killed [[V_LSHRREV_B32_e64_]], implicit $vcc_lo, implicit $exec
109+
; CHECK-NEXT: $vgpr0 = COPY [[V_CNDMASK_B32_e64_]]
110+
; CHECK-NEXT: SI_RETURN implicit $vgpr0
111+
%0:sreg_32_xm0_xexec = IMPLICIT_DEF
25112
%2:vgpr_32 = IMPLICIT_DEF
26-
%3:vgpr_32 = V_PK_MAX_F16 8, undef %2, 8, undef %2, 0, 0, 0, 0, 0, implicit $mode, implicit $exec
27-
%4:vgpr_32 = V_LSHRREV_B32_e64 16, undef %3, implicit $exec
28-
%5:vgpr_32 = V_CNDMASK_B32_e64 0, 32256, 0, undef %4, killed undef %1, implicit $exec
29-
$vgpr0 = COPY %5
113+
%3:sreg_32_xm0_xexec = V_CMP_EQ_U32_e64 undef %0, 1, implicit $exec
114+
%5:vgpr_32 = V_LSHRREV_B32_e64 16, undef %2, implicit $exec
115+
V_CMP_EQ_U32_e32 1, undef %2, implicit-def $vcc, implicit $exec
116+
%6:vgpr_32 = V_CNDMASK_B32_e64 0, 0, 0, %5, %3, implicit $exec
117+
%7:vgpr_32 = V_CNDMASK_B32_e32 killed %5, killed %5, implicit $vcc, implicit $exec
118+
$vgpr0 = COPY %6
119+
SI_RETURN implicit $vgpr0
120+
...
121+
122+
...
123+
---
124+
name: cannot-shrink-source-mdoes # cannot shrink because of source modifiers
125+
tracksRegLiveness: true
126+
body: |
127+
bb.0:
128+
liveins: $vgpr0
129+
130+
; CHECK-LABEL: name: cannot-shrink-source-mdoes
131+
; CHECK: liveins: $vgpr0
132+
; CHECK-NEXT: {{ $}}
133+
; CHECK-NEXT: [[DEF:%[0-9]+]]:sreg_32_xm0_xexec = IMPLICIT_DEF
134+
; CHECK-NEXT: [[DEF1:%[0-9]+]]:vgpr_32 = IMPLICIT_DEF
135+
; CHECK-NEXT: [[V_CMP_EQ_U32_e64_:%[0-9]+]]:sreg_32_xm0_xexec = V_CMP_EQ_U32_e64 undef [[DEF]], 0, implicit $exec
136+
; CHECK-NEXT: [[V_LSHRREV_B32_e64_:%[0-9]+]]:vgpr_32 = V_LSHRREV_B32_e64 16, undef [[DEF1]], implicit $exec
137+
; CHECK-NEXT: [[V_CNDMASK_B32_e64_:%[0-9]+]]:vgpr_32 = V_CNDMASK_B32_e64 1, 0, 0, [[V_LSHRREV_B32_e64_]], killed [[V_CMP_EQ_U32_e64_]], implicit $exec
138+
; CHECK-NEXT: $vgpr0 = COPY [[V_CNDMASK_B32_e64_]]
139+
; CHECK-NEXT: SI_RETURN implicit $vgpr0
140+
%0:sreg_32_xm0_xexec = IMPLICIT_DEF
141+
%1:vgpr_32 = IMPLICIT_DEF
142+
%2:sreg_32_xm0_xexec = V_CMP_EQ_U32_e64 undef %0, 0, implicit $exec
143+
%3:vgpr_32 = V_LSHRREV_B32_e64 16, undef %1, implicit $exec
144+
%4:vgpr_32 = V_CNDMASK_B32_e64 1, 0, 0, %3, killed %2, implicit $exec
145+
$vgpr0 = COPY %4
30146
SI_RETURN implicit $vgpr0
31147
...
32148

149+
...
150+
---
151+
name: missing-carry-def
152+
tracksRegLiveness: true
153+
registers:
154+
- { id: 0, class: sreg_32_xm0_xexec }
155+
body: |
156+
bb.0:
157+
liveins: $vgpr0
158+
159+
; CHECK-LABEL: name: missing-carry-def
160+
; CHECK: liveins: $vgpr0
161+
; CHECK-NEXT: {{ $}}
162+
; CHECK-NEXT: [[DEF:%[0-9]+]]:vgpr_32 = IMPLICIT_DEF
163+
; CHECK-NEXT: [[V_LSHRREV_B32_e64_:%[0-9]+]]:vgpr_32 = V_LSHRREV_B32_e64 16, undef [[DEF]], implicit $exec
164+
; CHECK-NEXT: [[V_CNDMASK_B32_e64_:%[0-9]+]]:vgpr_32 = V_CNDMASK_B32_e64 0, 0, 0, [[V_LSHRREV_B32_e64_]], undef %0:sreg_32_xm0_xexec, implicit $exec
165+
; CHECK-NEXT: $vgpr0 = COPY [[V_CNDMASK_B32_e64_]]
166+
; CHECK-NEXT: SI_RETURN implicit $vgpr0
167+
%1:vgpr_32 = IMPLICIT_DEF
168+
%2:vgpr_32 = V_LSHRREV_B32_e64 16, undef %1, implicit $exec
169+
%3:vgpr_32 = V_CNDMASK_B32_e64 0, 0, 0, %2, undef %0, implicit $exec
170+
$vgpr0 = COPY %3
171+
SI_RETURN implicit $vgpr0
172+
...

0 commit comments

Comments
 (0)