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 4--- | 5 define void @test_ctlz_s32() { ret void } 6 define void @test_ctlz_zero_undef_s32() { ret void } 7 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 } 11... 12--- 13name: test_ctlz_s32 14# CHECK-LABEL: name: test_ctlz_s32 15legalized: false 16# CHECK: legalized: true 17regBankSelected: false 18selected: false 19tracksRegLiveness: true 20registers: 21 - { id: 0, class: _ } 22 - { id: 1, class: _ } 23body: | 24 bb.0: 25 liveins: $r0 26 27 ; CHECK: [[X:%[0-9]+]]:_(s32) = COPY $r0 28 %0(s32) = COPY $r0 29 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 43 %1(s32) = G_CTLZ %0 44 45 ; CHECK: $r0 = COPY [[R]] 46 $r0 = COPY %1(s32) 47 BX_RET 14, $noreg, implicit $r0 48... 49--- 50name: test_ctlz_zero_undef_s32 51# CHECK-LABEL: name: test_ctlz_zero_undef_s32 52legalized: false 53# CHECK: legalized: true 54regBankSelected: false 55selected: false 56tracksRegLiveness: true 57registers: 58 - { id: 0, class: _ } 59 - { id: 1, class: _ } 60body: | 61 bb.0: 62 liveins: $r0 63 64 ; CHECK: [[X:%[0-9]+]]:_(s32) = COPY $r0 65 %0(s32) = COPY $r0 66 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 76 77 ; CHECK: $r0 = COPY [[R]] 78 $r0 = COPY %1(s32) 79 BX_RET 14, $noreg, implicit $r0 80... 81--- 82name: test_ctlz_s16 83# CHECK-LABEL: name: test_ctlz_s16 84legalized: false 85# CHECK: legalized: true 86regBankSelected: false 87selected: false 88tracksRegLiveness: true 89registers: 90 - { id: 0, class: _ } 91 - { id: 1, class: _ } 92 - { id: 2, class: _ } 93 - { id: 3, class: _ } 94body: | 95 bb.0: 96 liveins: $r0 97 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]] 101 %0(s32) = COPY $r0 102 %1(s16) = G_TRUNC %0(s32) 103 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]] 120 %2(s16) = G_CTLZ %1 121 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) 126 $r0 = COPY %3(s32) 127 BX_RET 14, $noreg, implicit $r0 128... 129--- 130name: test_ctlz_zero_undef_s8 131# CHECK-LABEL: name: test_ctlz_zero_undef_s8 132legalized: false 133# CHECK: legalized: true 134regBankSelected: false 135selected: false 136tracksRegLiveness: true 137registers: 138 - { id: 0, class: _ } 139 - { id: 1, class: _ } 140 - { id: 2, class: _ } 141 - { id: 3, class: _ } 142body: | 143 bb.0: 144 liveins: $r0 145 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]] 149 %0(s32) = COPY $r0 150 %1(s8) = G_TRUNC %0(s32) 151 152 ; Check that the operation is performed for 32 bits 153 ; CHECK: [[BITDIFF:%[0-9]+]]:_(s32) = G_CONSTANT i32 24 154 ; CHECK: [[R32:%[0-9]+]]:_(s32) = G_SHL [[X32]], [[BITDIFF]] 155 ; LIBCALLS-NOT: G_CTLZ 156 ; LIBCALLS: ADJCALLSTACKDOWN 157 ; LIBCALLS: $r0 = COPY [[R32]] 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 ; CLZ: [[COUNT:%[0-9]+]]:_(s32) = G_CTLZ [[R32]] 163 ; CLZ-NOT: G_CTLZ_ZERO_UNDEF 164 %2(s8) = G_CTLZ_ZERO_UNDEF %1 165 166 ; LIBCALLS: [[SHIFTEDR:%[0-9]+]]:_(s32) = G_SHL [[COUNT]], [[BITDIFF]] 167 ; LIBCALLS: [[R:%[0-9]+]]:_(s32) = G_ASHR [[SHIFTEDR]], [[BITDIFF]] 168 ; CLZ: $r0 = COPY [[COUNT]] 169 ; LIBCALLS: $r0 = COPY [[R]] 170 %3(s32) = G_SEXT %2(s8) 171 $r0 = COPY %3(s32) 172 BX_RET 14, $noreg, implicit $r0 173... 174