1 # RUN: llc -O0 -mtriple arm-linux-gnueabi -mattr=+v5t -run-pass=legalizer %s -o - | FileCheck %s -check-prefixes=CHECK,CLZ
2 # RUN: llc -O0 -mtriple thumb-linux-gnueabi -mattr=+v6t2 -run-pass=legalizer %s -o - | FileCheck %s -check-prefixes=CHECK,CLZ
3 # RUN: llc -O0 -mtriple arm-linux-gnueabi -mattr=-v5t -run-pass=legalizer %s -o - | FileCheck %s -check-prefixes=CHECK,LIBCALLS
5 define void @test_ctlz_s32() { ret void }
6 define void @test_ctlz_zero_undef_s32() { ret void }
8 ; same as above but with extensions
9 define void @test_ctlz_s16() { ret void }
10 define void @test_ctlz_zero_undef_s8() { ret void }
14 # CHECK-LABEL: name: test_ctlz_s32
16 # CHECK: legalized: true
17 regBankSelected: false
19 tracksRegLiveness: true
27 ; CHECK: [[X:%[0-9]+]]:_(s32) = COPY $r0
30 ; CLZ: [[R:%[0-9]+]]:_(s32) = G_CTLZ [[X]]
31 ; LIBCALLS-NOT: G_CTLZ
32 ; LIBCALLS: ADJCALLSTACKDOWN
33 ; LIBCALLS: $r0 = COPY [[X]]
34 ; LIBCALLS: BL &__clzsi2, {{.*}}, implicit $r0, implicit-def $r0
35 ; LIBCALLS: [[COUNT:%[0-9]+]]:_(s32) = COPY $r0
36 ; LIBCALLS: ADJCALLSTACKUP
37 ; LIBCALLS-NOT: G_CTLZ
38 ; LIBCALLS: [[ZERO:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
39 ; LIBCALLS: [[BITS:%[0-9]+]]:_(s32) = G_CONSTANT i32 32
40 ; LIBCALLS: [[CMP:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[X]](s32), [[ZERO]]
41 ; LIBCALLS: [[R:%[0-9]+]]:_(s32) = G_SELECT [[CMP]](s1), [[BITS]], [[COUNT]]
42 ; LIBCALLS-NOT: G_CTLZ
45 ; CHECK: $r0 = COPY [[R]]
47 BX_RET 14, $noreg, implicit $r0
50 name: test_ctlz_zero_undef_s32
51 # CHECK-LABEL: name: test_ctlz_zero_undef_s32
53 # CHECK: legalized: true
54 regBankSelected: false
56 tracksRegLiveness: true
64 ; CHECK: [[X:%[0-9]+]]:_(s32) = COPY $r0
67 ; CLZ: [[R:%[0-9]+]]:_(s32) = G_CTLZ [[X]]
68 ; LIBCALLS-NOT: G_CTLZ
69 ; LIBCALLS: ADJCALLSTACKDOWN
70 ; LIBCALLS: $r0 = COPY [[X]]
71 ; LIBCALLS: BL &__clzsi2, {{.*}}, implicit $r0, implicit-def $r0
72 ; LIBCALLS: [[R:%[0-9]+]]:_(s32) = COPY $r0
73 ; LIBCALLS: ADJCALLSTACKUP
74 ; LIBCALLS-NOT: G_CTLZ
75 %1(s32) = G_CTLZ_ZERO_UNDEF %0
77 ; CHECK: $r0 = COPY [[R]]
79 BX_RET 14, $noreg, implicit $r0
83 # CHECK-LABEL: name: test_ctlz_s16
85 # CHECK: legalized: true
86 regBankSelected: false
88 tracksRegLiveness: true
98 ; CHECK: [[X:%[0-9]+]]:_(s32) = COPY $r0
99 ; CHECK: [[BITMASK:%[0-9]+]]:_(s32) = G_CONSTANT i32 65535
100 ; CHECK: [[XAGAIN:%[0-9]+]]:_(s32) = COPY [[X]]
101 ; CHECK: [[X32:%[0-9]+]]:_(s32) = G_AND [[XAGAIN]], [[BITMASK]]
103 %1(s16) = G_TRUNC %0(s32)
105 ; Check that the operation is performed for 32 bits
106 ; CLZ: [[COUNT:%[0-9]+]]:_(s32) = G_CTLZ [[X32]]
107 ; LIBCALLS-NOT: G_CTLZ
108 ; LIBCALLS: ADJCALLSTACKDOWN
109 ; LIBCALLS: $r0 = COPY [[X32]]
110 ; LIBCALLS: BL &__clzsi2, {{.*}}, implicit $r0, implicit-def $r0
111 ; LIBCALLS: [[UNDEFCOUNT:%[0-9]+]]:_(s32) = COPY $r0
112 ; LIBCALLS: ADJCALLSTACKUP
113 ; LIBCALLS-NOT: G_CTLZ
114 ; LIBCALLS: [[ZERO:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
115 ; LIBCALLS: [[BITS:%[0-9]+]]:_(s32) = G_CONSTANT i32 32
116 ; LIBCALLS: [[CMP:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), {{%[0-9]+}}(s32), [[ZERO]]
117 ; LIBCALLS: [[COUNT:%[0-9]+]]:_(s32) = G_SELECT [[CMP]](s1), [[BITS]], [[UNDEFCOUNT]]
118 ; LIBCALLS-NOT: G_CTLZ
119 ; CHECK: [[BITDIFF:%[0-9]+]]:_(s32) = G_CONSTANT i32 16
120 ; CHECK: [[R32:%[0-9]+]]:_(s32) = G_SUB [[COUNT]], [[BITDIFF]]
123 ; CHECK: [[RAGAIN:%[0-9]+]]:_(s32) = COPY [[R32]]
124 ; CHECK: [[SHIFTEDR:%[0-9]+]]:_(s32) = G_SHL [[RAGAIN]], [[BITDIFF]]
125 ; CHECK: [[R:%[0-9]+]]:_(s32) = G_ASHR [[SHIFTEDR]], [[BITDIFF]]
126 ; CHECK: $r0 = COPY [[R]]
127 %3(s32) = G_SEXT %2(s16)
129 BX_RET 14, $noreg, implicit $r0
132 name: test_ctlz_zero_undef_s8
133 # CHECK-LABEL: name: test_ctlz_zero_undef_s8
135 # CHECK: legalized: true
136 regBankSelected: false
138 tracksRegLiveness: true
140 - { id: 0, class: _ }
141 - { id: 1, class: _ }
142 - { id: 2, class: _ }
143 - { id: 3, class: _ }
148 ; CHECK: [[X:%[0-9]+]]:_(s32) = COPY $r0
149 ; CHECK: [[BITMASK:%[0-9]+]]:_(s32) = G_CONSTANT i32 255
150 ; CHECK: [[XAGAIN:%[0-9]+]]:_(s32) = COPY [[X]]
151 ; CHECK: [[X32:%[0-9]+]]:_(s32) = G_AND [[XAGAIN]], [[BITMASK]]
153 %1(s8) = G_TRUNC %0(s32)
155 ; Check that the operation is performed for 32 bits
156 ; CLZ: [[COUNT:%[0-9]+]]:_(s32) = G_CTLZ
157 ; CLZ-NOT: G_CTLZ_ZERO_UNDEF
158 ; LIBCALLS-NOT: G_CTLZ
159 ; LIBCALLS: ADJCALLSTACKDOWN
160 ; LIBCALLS: $r0 = COPY [[X32]]
161 ; LIBCALLS: BL &__clzsi2, {{.*}}, implicit $r0, implicit-def $r0
162 ; LIBCALLS: [[COUNT:%[0-9]+]]:_(s32) = COPY $r0
163 ; LIBCALLS: ADJCALLSTACKUP
164 ; LIBCALLS-NOT: G_CTLZ
165 ; CHECK: [[BITDIFF:%[0-9]+]]:_(s32) = G_CONSTANT i32 24
166 ; CHECK: [[R32:%[0-9]+]]:_(s32) = G_SUB [[COUNT]], [[BITDIFF]]
167 %2(s8) = G_CTLZ_ZERO_UNDEF %1
169 ; CHECK: [[RAGAIN:%[0-9]+]]:_(s32) = COPY [[R32]]
170 ; CHECK: [[SHIFTEDR:%[0-9]+]]:_(s32) = G_SHL [[RAGAIN]], [[BITDIFF]]
171 ; CHECK: [[R:%[0-9]+]]:_(s32) = G_ASHR [[SHIFTEDR]], [[BITDIFF]]
172 ; CHECK: $r0 = COPY [[R]]
173 %3(s32) = G_SEXT %2(s8)
175 BX_RET 14, $noreg, implicit $r0