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: [[CMP:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), [[X]](s32), [[ZERO]]
40 ; LIBCALLS: [[BITS:%[0-9]+]]:_(s32) = G_CONSTANT i32 32
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: [[X32:%[0-9]+]]:_(s32) = G_AND [[X]], [[BITMASK]]
102 %1(s16) = G_TRUNC %0(s32)
104 ; Check that the operation is performed for 32 bits
105 ; CLZ: [[COUNT:%[0-9]+]]:_(s32) = G_CTLZ [[X32]]
106 ; LIBCALLS-NOT: G_CTLZ
107 ; LIBCALLS: ADJCALLSTACKDOWN
108 ; LIBCALLS: $r0 = COPY [[X32]]
109 ; LIBCALLS: BL &__clzsi2, {{.*}}, implicit $r0, implicit-def $r0
110 ; LIBCALLS: [[UNDEFCOUNT:%[0-9]+]]:_(s32) = COPY $r0
111 ; LIBCALLS: ADJCALLSTACKUP
112 ; LIBCALLS-NOT: G_CTLZ
113 ; LIBCALLS: [[ZERO:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
114 ; LIBCALLS: [[CMP:%[0-9]+]]:_(s1) = G_ICMP intpred(eq), {{%[0-9]+}}(s32), [[ZERO]]
115 ; LIBCALLS: [[BITS:%[0-9]+]]:_(s32) = G_CONSTANT i32 32
116 ; LIBCALLS: [[COUNT:%[0-9]+]]:_(s32) = G_SELECT [[CMP]](s1), [[BITS]], [[UNDEFCOUNT]]
117 ; LIBCALLS-NOT: G_CTLZ
118 ; CHECK: [[BITDIFF:%[0-9]+]]:_(s32) = G_CONSTANT i32 16
119 ; CHECK: [[R32:%[0-9]+]]:_(s32) = G_SUB [[COUNT]], [[BITDIFF]]
122 ; CHECK: [[SHIFTEDR:%[0-9]+]]:_(s32) = G_SHL [[R32]], [[BITDIFF]]
123 ; CHECK: [[R:%[0-9]+]]:_(s32) = G_ASHR [[SHIFTEDR]], [[BITDIFF]]
124 ; CHECK: $r0 = COPY [[R]]
125 %3(s32) = G_SEXT %2(s16)
127 BX_RET 14, $noreg, implicit $r0
130 name: test_ctlz_zero_undef_s8
131 # CHECK-LABEL: name: test_ctlz_zero_undef_s8
133 # CHECK: legalized: true
134 regBankSelected: false
136 tracksRegLiveness: true
138 - { id: 0, class: _ }
139 - { id: 1, class: _ }
140 - { id: 2, class: _ }
141 - { id: 3, class: _ }
146 ; CHECK: [[X:%[0-9]+]]:_(s32) = COPY $r0
147 ; CHECK: [[BITMASK:%[0-9]+]]:_(s32) = G_CONSTANT i32 255
148 ; CHECK: [[X32:%[0-9]+]]:_(s32) = G_AND [[X]], [[BITMASK]]
150 %1(s8) = G_TRUNC %0(s32)
152 ; Check that the operation is performed for 32 bits
153 ; CLZ: [[COUNT:%[0-9]+]]:_(s32) = G_CTLZ
154 ; CLZ-NOT: G_CTLZ_ZERO_UNDEF
155 ; LIBCALLS-NOT: G_CTLZ
156 ; LIBCALLS: ADJCALLSTACKDOWN
157 ; LIBCALLS: $r0 = COPY [[X32]]
158 ; LIBCALLS: BL &__clzsi2, {{.*}}, implicit $r0, implicit-def $r0
159 ; LIBCALLS: [[COUNT:%[0-9]+]]:_(s32) = COPY $r0
160 ; LIBCALLS: ADJCALLSTACKUP
161 ; LIBCALLS-NOT: G_CTLZ
162 ; CHECK: [[BITDIFF:%[0-9]+]]:_(s32) = G_CONSTANT i32 24
163 ; CHECK: [[R32:%[0-9]+]]:_(s32) = G_SUB [[COUNT]], [[BITDIFF]]
164 %2(s8) = G_CTLZ_ZERO_UNDEF %1
166 ; CHECK: [[SHIFTEDR:%[0-9]+]]:_(s32) = G_SHL [[R32]], [[BITDIFF]]
167 ; CHECK: [[R:%[0-9]+]]:_(s32) = G_ASHR [[SHIFTEDR]], [[BITDIFF]]
168 ; CHECK: $r0 = COPY [[R]]
169 %3(s32) = G_SEXT %2(s8)
171 BX_RET 14, $noreg, implicit $r0