Skip to content

Commit 545a55c

Browse files
committed
Use Promote for i32 lzcnt
Created using spr 1.3.5
2 parents 8e944dd + a4deacf commit 545a55c

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

llvm/lib/Target/Sparc/SparcISelLowering.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1817,7 +1817,8 @@ SparcTargetLowering::SparcTargetLowering(const TargetMachine &TM,
18171817
setOperationAction(ISD::FREM , MVT::f32, Expand);
18181818
setOperationAction(ISD::FMA , MVT::f32, Expand);
18191819
setOperationAction(ISD::CTTZ , MVT::i32, Expand);
1820-
setOperationAction(ISD::CTLZ, MVT::i32, Subtarget->isVIS3() ? Legal : Expand);
1820+
setOperationAction(ISD::CTLZ, MVT::i32,
1821+
Subtarget->isVIS3() ? Promote : Expand);
18211822
setOperationAction(ISD::ROTL , MVT::i32, Expand);
18221823
setOperationAction(ISD::ROTR , MVT::i32, Expand);
18231824
setOperationAction(ISD::BSWAP, MVT::i32, Expand);
@@ -1990,6 +1991,11 @@ SparcTargetLowering::SparcTargetLowering(const TargetMachine &TM,
19901991
if (Subtarget->hasLeonCycleCounter())
19911992
setOperationAction(ISD::READCYCLECOUNTER, MVT::i64, Custom);
19921993

1994+
if (Subtarget->isVIS3()) {
1995+
setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i32, Promote);
1996+
setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i64, Legal);
1997+
}
1998+
19931999
setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
19942000

19952001
setMinFunctionAlignment(Align(4));

llvm/lib/Target/Sparc/SparcInstrVIS.td

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,12 @@ def : Pat<(i64 (mulhu i64:$lhs, i64:$rhs)), (UMULXHI $lhs, $rhs)>;
299299
// Signed "MULXHI".
300300
// Based on the formula presented in OSA2011 §7.140, but with bitops to select
301301
// the values to be added.
302+
// TODO: This expansion should probably be moved to DAG legalization phase.
302303
def : Pat<(i64 (mulhs i64:$lhs, i64:$rhs)),
303304
(SUBrr (UMULXHI $lhs, $rhs),
304305
(ADDrr (ANDrr (SRAXri $lhs, 63), $rhs),
305306
(ANDrr (SRAXri $rhs, 63), $lhs)))>;
306307

307308
def : Pat<(i64 (ctlz i64:$src)), (LZCNT $src)>;
308-
// 32-bit LZCNT.
309-
// The zero extension will leave us with 32 extra leading zeros,
310-
// so we need to compensate for it.
311-
def : Pat<(i32 (ctlz i32:$src)), (ADDri (LZCNT (SRLri $src, 0)), (i32 -32))>;
309+
def : Pat<(i64 (ctlz_zero_undef i64:$src)), (LZCNT $src)>;
312310
} // Predicates = [HasVIS3]

llvm/test/CodeGen/SPARC/ctlz.ll

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ define i32 @i32_nopoison(i32 %x) nounwind {
7777
; VIS3-NEXT: be %icc, .LBB0_2
7878
; VIS3-NEXT: nop
7979
; VIS3-NEXT: ! %bb.1: ! %cond.false
80-
; VIS3-NEXT: srl %o0, 0, %o0
81-
; VIS3-NEXT: lzcnt %o0, %o0
80+
; VIS3-NEXT: sllx %o0, 32, %o0
8281
; VIS3-NEXT: retl
83-
; VIS3-NEXT: add %o0, -32, %o0
82+
; VIS3-NEXT: lzcnt %o0, %o0
8483
; VIS3-NEXT: .LBB0_2:
8584
; VIS3-NEXT: retl
8685
; VIS3-NEXT: mov 32, %o0
@@ -144,10 +143,9 @@ define i32 @i32_poison(i32 %x) nounwind {
144143
;
145144
; VIS3-LABEL: i32_poison:
146145
; VIS3: ! %bb.0:
147-
; VIS3-NEXT: srl %o0, 0, %o0
148-
; VIS3-NEXT: lzcnt %o0, %o0
146+
; VIS3-NEXT: sllx %o0, 32, %o0
149147
; VIS3-NEXT: retl
150-
; VIS3-NEXT: add %o0, -32, %o0
148+
; VIS3-NEXT: lzcnt %o0, %o0
151149
%ret = call i32 @llvm.ctlz.i32(i32 %x, i1 true)
152150
ret i32 %ret
153151
}

0 commit comments

Comments
 (0)