Skip to content

Commit 5adbf7d

Browse files
committed
AMDGPU/GlobalISel: Make G_TRUNC legal
This is required to be legal. I'm not sure how we were getting away without defining any rules for it.
1 parent de25647 commit 5adbf7d

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,9 @@ AMDGPULegalizerInfo::AMDGPULegalizerInfo(const GCNSubtarget &ST_,
460460
FMad.scalarize(0)
461461
.lower();
462462

463+
getActionDefinitionsBuilder(G_TRUNC)
464+
.alwaysLegal();
465+
463466
getActionDefinitionsBuilder({G_SEXT, G_ZEXT, G_ANYEXT})
464467
.legalFor({{S64, S32}, {S32, S16}, {S64, S16},
465468
{S32, S1}, {S64, S1}, {S16, S1}})
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=fiji -run-pass=legalizer -global-isel-abort=0 -o - %s | FileCheck %s
3+
4+
---
5+
name: test_trunc_s64_to_s32
6+
body: |
7+
bb.0:
8+
liveins: $vgpr0_vgpr1
9+
10+
; CHECK-LABEL: name: test_trunc_s64_to_s32
11+
; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $vgpr0_vgpr1
12+
; CHECK: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[COPY]](s64)
13+
; CHECK: $vgpr0 = COPY [[TRUNC]](s32)
14+
%0:_(s64) = COPY $vgpr0_vgpr1
15+
%1:_(s32) = G_TRUNC %0
16+
$vgpr0 = COPY %1
17+
...
18+
19+
---
20+
name: test_trunc_s64_to_s16
21+
body: |
22+
bb.0:
23+
liveins: $vgpr0_vgpr1
24+
25+
; CHECK-LABEL: name: test_trunc_s64_to_s16
26+
; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $vgpr0_vgpr1
27+
; CHECK: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[COPY]](s64)
28+
; CHECK: S_ENDPGM 0, implicit [[TRUNC]](s16)
29+
%0:_(s64) = COPY $vgpr0_vgpr1
30+
%1:_(s16) = G_TRUNC %0
31+
S_ENDPGM 0, implicit %1
32+
...
33+
34+
---
35+
name: test_trunc_v2s32_to_v2s16
36+
body: |
37+
bb.0:
38+
liveins: $vgpr0_vgpr1
39+
40+
; CHECK-LABEL: name: test_trunc_v2s32_to_v2s16
41+
; CHECK: [[COPY:%[0-9]+]]:_(<2 x s32>) = COPY $vgpr0_vgpr1
42+
; CHECK: [[TRUNC:%[0-9]+]]:_(<2 x s16>) = G_TRUNC [[COPY]](<2 x s32>)
43+
; CHECK: $vgpr0 = COPY [[TRUNC]](<2 x s16>)
44+
%0:_(<2 x s32>) = COPY $vgpr0_vgpr1
45+
%1:_(<2 x s16>) = G_TRUNC %0
46+
$vgpr0 = COPY %1
47+
...
48+
49+
---
50+
name: test_trunc_v4s32_to_v4s16
51+
body: |
52+
bb.0:
53+
liveins: $vgpr0_vgpr1_vgpr2_vgpr3
54+
55+
; CHECK-LABEL: name: test_trunc_v4s32_to_v4s16
56+
; CHECK: [[COPY:%[0-9]+]]:_(<4 x s32>) = COPY $vgpr0_vgpr1_vgpr2_vgpr3
57+
; CHECK: [[TRUNC:%[0-9]+]]:_(<4 x s16>) = G_TRUNC [[COPY]](<4 x s32>)
58+
; CHECK: $vgpr0_vgpr1 = COPY [[TRUNC]](<4 x s16>)
59+
%0:_(<4 x s32>) = COPY $vgpr0_vgpr1_vgpr2_vgpr3
60+
%1:_(<4 x s16>) = G_TRUNC %0
61+
$vgpr0_vgpr1 = COPY %1
62+
...
63+
64+
---
65+
name: test_trunc_s64_to_s1
66+
body: |
67+
bb.0:
68+
liveins: $vgpr0_vgpr1
69+
70+
; CHECK-LABEL: name: test_trunc_s64_to_s1
71+
; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $vgpr0_vgpr1
72+
; CHECK: [[TRUNC:%[0-9]+]]:_(s1) = G_TRUNC [[COPY]](s64)
73+
; CHECK: S_ENDPGM 0, implicit [[TRUNC]](s1)
74+
%0:_(s64) = COPY $vgpr0_vgpr1
75+
%1:_(s1) = G_TRUNC %0
76+
S_ENDPGM 0, implicit %1
77+
...
78+
79+
---
80+
name: test_trunc_s32_to_s1
81+
body: |
82+
bb.0:
83+
liveins: $vgpr0
84+
85+
; CHECK-LABEL: name: test_trunc_s32_to_s1
86+
; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $vgpr0
87+
; CHECK: [[TRUNC:%[0-9]+]]:_(s1) = G_TRUNC [[COPY]](s32)
88+
; CHECK: S_ENDPGM 0, implicit [[TRUNC]](s1)
89+
%0:_(s32) = COPY $vgpr0
90+
%1:_(s1) = G_TRUNC %0
91+
S_ENDPGM 0, implicit %1
92+
...
93+
94+
---
95+
name: test_trunc_s16_to_s1
96+
body: |
97+
bb.0:
98+
liveins: $vgpr0
99+
100+
; CHECK-LABEL: name: test_trunc_s16_to_s1
101+
; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $vgpr0
102+
; CHECK: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[COPY]](s32)
103+
; CHECK: [[TRUNC1:%[0-9]+]]:_(s1) = G_TRUNC [[TRUNC]](s16)
104+
; CHECK: S_ENDPGM 0, implicit [[TRUNC1]](s1)
105+
%0:_(s32) = COPY $vgpr0
106+
%1:_(s16) = G_TRUNC %0
107+
%2:_(s1) = G_TRUNC %1
108+
S_ENDPGM 0, implicit %2
109+
...
110+
111+
---
112+
name: test_trunc_v4s32_to_v4s1
113+
body: |
114+
bb.0:
115+
liveins: $vgpr0_vgpr1_vgpr2_vgpr3
116+
117+
; CHECK-LABEL: name: test_trunc_v4s32_to_v4s1
118+
; CHECK: [[COPY:%[0-9]+]]:_(<4 x s32>) = COPY $vgpr0_vgpr1_vgpr2_vgpr3
119+
; CHECK: [[TRUNC:%[0-9]+]]:_(<4 x s1>) = G_TRUNC [[COPY]](<4 x s32>)
120+
; CHECK: S_ENDPGM 0, implicit [[TRUNC]](<4 x s1>)
121+
%0:_(<4 x s32>) = COPY $vgpr0_vgpr1_vgpr2_vgpr3
122+
%1:_(<4 x s1>) = G_TRUNC %0
123+
S_ENDPGM 0, implicit %1
124+
...

0 commit comments

Comments
 (0)