Skip to content

Commit 6e86581

Browse files
committed
Promote i32 CTLZ when we don't have VIS3 or POPC
Created using spr 1.3.5
1 parent 49e0e47 commit 6e86581

File tree

2 files changed

+35
-158
lines changed

2 files changed

+35
-158
lines changed

llvm/lib/Target/Sparc/SparcISelLowering.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,7 +1755,7 @@ SparcTargetLowering::SparcTargetLowering(const TargetMachine &TM,
17551755
Subtarget->usePopc() ? Legal : Expand);
17561756
setOperationAction(ISD::CTTZ , MVT::i64, Expand);
17571757
setOperationAction(ISD::CTLZ, MVT::i64,
1758-
Subtarget->isVIS3() ? Legal : LibCall);
1758+
Subtarget->isVIS3() ? Legal : Expand);
17591759
setOperationAction(ISD::BSWAP, MVT::i64, Expand);
17601760
setOperationAction(ISD::ROTL , MVT::i64, Expand);
17611761
setOperationAction(ISD::ROTR , MVT::i64, Expand);
@@ -1818,7 +1818,7 @@ SparcTargetLowering::SparcTargetLowering(const TargetMachine &TM,
18181818
setOperationAction(ISD::FMA , MVT::f32, Expand);
18191819
setOperationAction(ISD::CTTZ , MVT::i32, Expand);
18201820
setOperationAction(ISD::CTLZ, MVT::i32,
1821-
Subtarget->isVIS3() ? Promote : LibCall);
1821+
Subtarget->isVIS3() ? Promote : Expand);
18221822
setOperationAction(ISD::ROTL , MVT::i32, Expand);
18231823
setOperationAction(ISD::ROTR , MVT::i32, Expand);
18241824
setOperationAction(ISD::BSWAP, MVT::i32, Expand);
@@ -1992,6 +1992,13 @@ SparcTargetLowering::SparcTargetLowering(const TargetMachine &TM,
19921992
if (Subtarget->isVIS3()) {
19931993
setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i32, Promote);
19941994
setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i64, Legal);
1995+
} else if (Subtarget->usePopc()) {
1996+
setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i32, Expand);
1997+
setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i64, Expand);
1998+
} else {
1999+
setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i32,
2000+
Subtarget->is64Bit() ? Promote : LibCall);
2001+
setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i64, LibCall);
19952002
}
19962003

19972004
setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);

llvm/test/CodeGen/SPARC/ctlz.ll

Lines changed: 26 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,18 @@
66
define i32 @i32_nopoison(i32 %x) nounwind {
77
; V9-LABEL: i32_nopoison:
88
; V9: ! %bb.0:
9-
; V9-NEXT: cmp %o0, 0
9+
; V9-NEXT: save %sp, -176, %sp
10+
; V9-NEXT: cmp %i0, 0
1011
; V9-NEXT: be %icc, .LBB0_2
1112
; V9-NEXT: nop
1213
; V9-NEXT: ! %bb.1: ! %cond.false
13-
; V9-NEXT: srl %o0, 1, %o1
14-
; V9-NEXT: or %o0, %o1, %o0
15-
; V9-NEXT: srl %o0, 2, %o1
16-
; V9-NEXT: or %o0, %o1, %o0
17-
; V9-NEXT: srl %o0, 4, %o1
18-
; V9-NEXT: or %o0, %o1, %o0
19-
; V9-NEXT: srl %o0, 8, %o1
20-
; V9-NEXT: or %o0, %o1, %o0
21-
; V9-NEXT: srl %o0, 16, %o1
22-
; V9-NEXT: or %o0, %o1, %o0
23-
; V9-NEXT: xor %o0, -1, %o0
24-
; V9-NEXT: srl %o0, 1, %o1
25-
; V9-NEXT: sethi 1398101, %o2
26-
; V9-NEXT: or %o2, 341, %o2
27-
; V9-NEXT: and %o1, %o2, %o1
28-
; V9-NEXT: sub %o0, %o1, %o0
29-
; V9-NEXT: sethi 838860, %o1
30-
; V9-NEXT: or %o1, 819, %o1
31-
; V9-NEXT: and %o0, %o1, %o2
32-
; V9-NEXT: srl %o0, 2, %o0
33-
; V9-NEXT: and %o0, %o1, %o0
34-
; V9-NEXT: add %o2, %o0, %o0
35-
; V9-NEXT: srl %o0, 4, %o1
36-
; V9-NEXT: add %o0, %o1, %o0
37-
; V9-NEXT: sethi 246723, %o1
38-
; V9-NEXT: or %o1, 783, %o1
39-
; V9-NEXT: and %o0, %o1, %o0
40-
; V9-NEXT: sll %o0, 8, %o1
41-
; V9-NEXT: add %o0, %o1, %o0
42-
; V9-NEXT: sll %o0, 16, %o1
43-
; V9-NEXT: add %o0, %o1, %o0
44-
; V9-NEXT: retl
45-
; V9-NEXT: srl %o0, 24, %o0
14+
; V9-NEXT: call __clzdi2
15+
; V9-NEXT: sllx %i0, 32, %o0
16+
; V9-NEXT: ret
17+
; V9-NEXT: restore %g0, %o0, %o0
4618
; V9-NEXT: .LBB0_2:
47-
; V9-NEXT: retl
48-
; V9-NEXT: mov 32, %o0
19+
; V9-NEXT: ret
20+
; V9-NEXT: restore %g0, 32, %o0
4921
;
5022
; POPC-LABEL: i32_nopoison:
5123
; POPC: ! %bb.0:
@@ -90,39 +62,11 @@ define i32 @i32_nopoison(i32 %x) nounwind {
9062
define i32 @i32_poison(i32 %x) nounwind {
9163
; V9-LABEL: i32_poison:
9264
; V9: ! %bb.0:
93-
; V9-NEXT: srl %o0, 1, %o1
94-
; V9-NEXT: or %o0, %o1, %o0
95-
; V9-NEXT: srl %o0, 2, %o1
96-
; V9-NEXT: or %o0, %o1, %o0
97-
; V9-NEXT: srl %o0, 4, %o1
98-
; V9-NEXT: or %o0, %o1, %o0
99-
; V9-NEXT: srl %o0, 8, %o1
100-
; V9-NEXT: or %o0, %o1, %o0
101-
; V9-NEXT: srl %o0, 16, %o1
102-
; V9-NEXT: or %o0, %o1, %o0
103-
; V9-NEXT: xor %o0, -1, %o0
104-
; V9-NEXT: srl %o0, 1, %o1
105-
; V9-NEXT: sethi 1398101, %o2
106-
; V9-NEXT: or %o2, 341, %o2
107-
; V9-NEXT: and %o1, %o2, %o1
108-
; V9-NEXT: sub %o0, %o1, %o0
109-
; V9-NEXT: sethi 838860, %o1
110-
; V9-NEXT: or %o1, 819, %o1
111-
; V9-NEXT: and %o0, %o1, %o2
112-
; V9-NEXT: srl %o0, 2, %o0
113-
; V9-NEXT: and %o0, %o1, %o0
114-
; V9-NEXT: add %o2, %o0, %o0
115-
; V9-NEXT: srl %o0, 4, %o1
116-
; V9-NEXT: add %o0, %o1, %o0
117-
; V9-NEXT: sethi 246723, %o1
118-
; V9-NEXT: or %o1, 783, %o1
119-
; V9-NEXT: and %o0, %o1, %o0
120-
; V9-NEXT: sll %o0, 8, %o1
121-
; V9-NEXT: add %o0, %o1, %o0
122-
; V9-NEXT: sll %o0, 16, %o1
123-
; V9-NEXT: add %o0, %o1, %o0
124-
; V9-NEXT: retl
125-
; V9-NEXT: srl %o0, 24, %o0
65+
; V9-NEXT: save %sp, -176, %sp
66+
; V9-NEXT: call __clzdi2
67+
; V9-NEXT: sllx %i0, 32, %o0
68+
; V9-NEXT: ret
69+
; V9-NEXT: restore %g0, %o0, %o0
12670
;
12771
; POPC-LABEL: i32_poison:
12872
; POPC: ! %bb.0:
@@ -153,54 +97,17 @@ define i32 @i32_poison(i32 %x) nounwind {
15397
define i64 @i64_nopoison(i64 %x) nounwind {
15498
; V9-LABEL: i64_nopoison:
15599
; V9: ! %bb.0:
156-
; V9-NEXT: brz %o0, .LBB2_2
100+
; V9-NEXT: save %sp, -176, %sp
101+
; V9-NEXT: brz %i0, .LBB2_2
157102
; V9-NEXT: nop
158103
; V9-NEXT: ! %bb.1: ! %cond.false
159-
; V9-NEXT: srlx %o0, 1, %o1
160-
; V9-NEXT: or %o0, %o1, %o0
161-
; V9-NEXT: srlx %o0, 2, %o1
162-
; V9-NEXT: or %o0, %o1, %o0
163-
; V9-NEXT: srlx %o0, 4, %o1
164-
; V9-NEXT: or %o0, %o1, %o0
165-
; V9-NEXT: srlx %o0, 8, %o1
166-
; V9-NEXT: or %o0, %o1, %o0
167-
; V9-NEXT: srlx %o0, 16, %o1
168-
; V9-NEXT: or %o0, %o1, %o0
169-
; V9-NEXT: srlx %o0, 32, %o1
170-
; V9-NEXT: or %o0, %o1, %o0
171-
; V9-NEXT: xor %o0, -1, %o0
172-
; V9-NEXT: srlx %o0, 1, %o1
173-
; V9-NEXT: sethi 1398101, %o2
174-
; V9-NEXT: or %o2, 341, %o2
175-
; V9-NEXT: sllx %o2, 32, %o3
176-
; V9-NEXT: or %o3, %o2, %o2
177-
; V9-NEXT: and %o1, %o2, %o1
178-
; V9-NEXT: sub %o0, %o1, %o0
179-
; V9-NEXT: sethi 838860, %o1
180-
; V9-NEXT: or %o1, 819, %o1
181-
; V9-NEXT: sllx %o1, 32, %o2
182-
; V9-NEXT: or %o2, %o1, %o1
183-
; V9-NEXT: and %o0, %o1, %o2
184-
; V9-NEXT: srlx %o0, 2, %o0
185-
; V9-NEXT: and %o0, %o1, %o0
186-
; V9-NEXT: add %o2, %o0, %o0
187-
; V9-NEXT: srlx %o0, 4, %o1
188-
; V9-NEXT: add %o0, %o1, %o0
189-
; V9-NEXT: sethi 246723, %o1
190-
; V9-NEXT: or %o1, 783, %o1
191-
; V9-NEXT: sllx %o1, 32, %o2
192-
; V9-NEXT: or %o2, %o1, %o1
193-
; V9-NEXT: and %o0, %o1, %o0
194-
; V9-NEXT: sethi 16448, %o1
195-
; V9-NEXT: or %o1, 257, %o1
196-
; V9-NEXT: sllx %o1, 32, %o2
197-
; V9-NEXT: or %o2, %o1, %o1
198-
; V9-NEXT: mulx %o0, %o1, %o0
199-
; V9-NEXT: retl
200-
; V9-NEXT: srlx %o0, 56, %o0
104+
; V9-NEXT: call __clzdi2
105+
; V9-NEXT: mov %i0, %o0
106+
; V9-NEXT: ret
107+
; V9-NEXT: restore %g0, %o0, %o0
201108
; V9-NEXT: .LBB2_2:
202-
; V9-NEXT: retl
203-
; V9-NEXT: mov 64, %o0
109+
; V9-NEXT: ret
110+
; V9-NEXT: restore %g0, 64, %o0
204111
;
205112
; POPC-LABEL: i64_nopoison:
206113
; POPC: ! %bb.0:
@@ -243,48 +150,11 @@ define i64 @i64_nopoison(i64 %x) nounwind {
243150
define i64 @i64_poison(i64 %x) nounwind {
244151
; V9-LABEL: i64_poison:
245152
; V9: ! %bb.0:
246-
; V9-NEXT: srlx %o0, 1, %o1
247-
; V9-NEXT: or %o0, %o1, %o0
248-
; V9-NEXT: srlx %o0, 2, %o1
249-
; V9-NEXT: or %o0, %o1, %o0
250-
; V9-NEXT: srlx %o0, 4, %o1
251-
; V9-NEXT: or %o0, %o1, %o0
252-
; V9-NEXT: srlx %o0, 8, %o1
253-
; V9-NEXT: or %o0, %o1, %o0
254-
; V9-NEXT: srlx %o0, 16, %o1
255-
; V9-NEXT: or %o0, %o1, %o0
256-
; V9-NEXT: srlx %o0, 32, %o1
257-
; V9-NEXT: or %o0, %o1, %o0
258-
; V9-NEXT: xor %o0, -1, %o0
259-
; V9-NEXT: srlx %o0, 1, %o1
260-
; V9-NEXT: sethi 1398101, %o2
261-
; V9-NEXT: or %o2, 341, %o2
262-
; V9-NEXT: sllx %o2, 32, %o3
263-
; V9-NEXT: or %o3, %o2, %o2
264-
; V9-NEXT: and %o1, %o2, %o1
265-
; V9-NEXT: sub %o0, %o1, %o0
266-
; V9-NEXT: sethi 838860, %o1
267-
; V9-NEXT: or %o1, 819, %o1
268-
; V9-NEXT: sllx %o1, 32, %o2
269-
; V9-NEXT: or %o2, %o1, %o1
270-
; V9-NEXT: and %o0, %o1, %o2
271-
; V9-NEXT: srlx %o0, 2, %o0
272-
; V9-NEXT: and %o0, %o1, %o0
273-
; V9-NEXT: add %o2, %o0, %o0
274-
; V9-NEXT: srlx %o0, 4, %o1
275-
; V9-NEXT: add %o0, %o1, %o0
276-
; V9-NEXT: sethi 246723, %o1
277-
; V9-NEXT: or %o1, 783, %o1
278-
; V9-NEXT: sllx %o1, 32, %o2
279-
; V9-NEXT: or %o2, %o1, %o1
280-
; V9-NEXT: and %o0, %o1, %o0
281-
; V9-NEXT: sethi 16448, %o1
282-
; V9-NEXT: or %o1, 257, %o1
283-
; V9-NEXT: sllx %o1, 32, %o2
284-
; V9-NEXT: or %o2, %o1, %o1
285-
; V9-NEXT: mulx %o0, %o1, %o0
286-
; V9-NEXT: retl
287-
; V9-NEXT: srlx %o0, 56, %o0
153+
; V9-NEXT: save %sp, -176, %sp
154+
; V9-NEXT: call __clzdi2
155+
; V9-NEXT: mov %i0, %o0
156+
; V9-NEXT: ret
157+
; V9-NEXT: restore %g0, %o0, %o0
288158
;
289159
; POPC-LABEL: i64_poison:
290160
; POPC: ! %bb.0:

0 commit comments

Comments
 (0)