Home | History | Annotate | Download | only in InstCombine
      1 ; This test makes sure that shift instructions are properly eliminated
      2 ; even with arbitrary precision integers.
      3 ; RUN: opt < %s -instcombine -S | FileCheck %s
      4 
      5 ; CHECK-LABEL: @test1(
      6 ; CHECK-NOT: sh
      7 define i47 @test1(i47 %A) {
      8 	%B = shl i47 %A, 0		; <i47> [#uses=1]
      9 	ret i47 %B
     10 }
     11 
     12 ; CHECK-LABEL: @test2(
     13 ; CHECK-NOT: sh
     14 define i41 @test2(i7 %X) {
     15 	%A = zext i7 %X to i41		; <i41> [#uses=1]
     16 	%B = shl i41 0, %A		; <i41> [#uses=1]
     17 	ret i41 %B
     18 }
     19 
     20 ; CHECK-LABEL: @test3(
     21 ; CHECK-NOT: sh
     22 define i41 @test3(i41 %A) {
     23 	%B = ashr i41 %A, 0		; <i41> [#uses=1]
     24 	ret i41 %B
     25 }
     26 
     27 ; CHECK-LABEL: @test4(
     28 ; CHECK-NOT: sh
     29 define i39 @test4(i7 %X) {
     30 	%A = zext i7 %X to i39		; <i39> [#uses=1]
     31 	%B = ashr i39 0, %A		; <i39> [#uses=1]
     32 	ret i39 %B
     33 }
     34 
     35 ; CHECK-LABEL: @test5(
     36 ; CHECK-NOT: sh
     37 define i55 @test5(i55 %A) {
     38 	%B = lshr i55 %A, 55		; <i55> [#uses=1]
     39 	ret i55 %B
     40 }
     41 
     42 ; CHECK-LABEL: @test5a(
     43 ; CHECK-NOT: sh
     44 define i32 @test5a(i32 %A) {
     45 	%B = shl i32 %A, 32		; <i32> [#uses=1]
     46 	ret i32 %B
     47 }
     48 
     49 ; CHECK-LABEL: @test6(
     50 ; CHECK: mul i55 %A, 6
     51 define i55 @test6(i55 %A) {
     52 	%B = shl i55 %A, 1		; <i55> [#uses=1]
     53 	%C = mul i55 %B, 3		; <i55> [#uses=1]
     54 	ret i55 %C
     55 }
     56 
     57 ; CHECK-LABEL: @test6a(
     58 ; CHECK: mul i55 %A, 6
     59 define i55 @test6a(i55 %A) {
     60 	%B = mul i55 %A, 3		; <i55> [#uses=1]
     61 	%C = shl i55 %B, 1		; <i55> [#uses=1]
     62 	ret i55 %C
     63 }
     64 
     65 ; CHECK-LABEL: @test7(
     66 ; CHECK-NOT: sh
     67 define i29 @test7(i8 %X) {
     68 	%A = zext i8 %X to i29		; <i29> [#uses=1]
     69 	%B = ashr i29 -1, %A		; <i29> [#uses=1]
     70 	ret i29 %B
     71 }
     72 
     73 ; CHECK-LABEL: @test8(
     74 ; CHECK-NOT: sh
     75 define i7 @test8(i7 %A) {
     76 	%B = shl i7 %A, 4		; <i7> [#uses=1]
     77 	%C = shl i7 %B, 3		; <i7> [#uses=1]
     78 	ret i7 %C
     79 }
     80 
     81 ; CHECK-LABEL: @test9(
     82 ; CHECK-NOT: sh
     83 define i17 @test9(i17 %A) {
     84 	%B = shl i17 %A, 16		; <i17> [#uses=1]
     85 	%C = lshr i17 %B, 16		; <i17> [#uses=1]
     86 	ret i17 %C
     87 }
     88 
     89 ; CHECK-LABEL: @test10(
     90 ; CHECK-NOT: sh
     91 define i19 @test10(i19 %A) {
     92 	%B = lshr i19 %A, 18		; <i19> [#uses=1]
     93 	%C = shl i19 %B, 18		; <i19> [#uses=1]
     94 	ret i19 %C
     95 }
     96 
     97 ; CHECK-LABEL: @test11(
     98 ; Don't hide the shl from scalar evolution. DAGCombine will get it.
     99 ; CHECK: shl
    100 define i23 @test11(i23 %A) {
    101 	%a = mul i23 %A, 3		; <i23> [#uses=1]
    102 	%B = lshr i23 %a, 11		; <i23> [#uses=1]
    103 	%C = shl i23 %B, 12		; <i23> [#uses=1]
    104 	ret i23 %C
    105 }
    106 
    107 ; CHECK-LABEL: @test12(
    108 ; CHECK-NOT: sh
    109 define i47 @test12(i47 %A) {
    110 	%B = ashr i47 %A, 8		; <i47> [#uses=1]
    111 	%C = shl i47 %B, 8		; <i47> [#uses=1]
    112 	ret i47 %C
    113 }
    114 
    115 ; CHECK-LABEL: @test13(
    116 ; Don't hide the shl from scalar evolution. DAGCombine will get it.
    117 ; CHECK: shl
    118 define i18 @test13(i18 %A) {
    119 	%a = mul i18 %A, 3		; <i18> [#uses=1]
    120 	%B = ashr i18 %a, 8		; <i18> [#uses=1]
    121 	%C = shl i18 %B, 9		; <i18> [#uses=1]
    122 	ret i18 %C
    123 }
    124 
    125 ; CHECK-LABEL: @test14(
    126 ; CHECK-NOT: sh
    127 define i35 @test14(i35 %A) {
    128 	%B = lshr i35 %A, 4		; <i35> [#uses=1]
    129 	%C = or i35 %B, 1234		; <i35> [#uses=1]
    130 	%D = shl i35 %C, 4		; <i35> [#uses=1]
    131 	ret i35 %D
    132 }
    133 
    134 ; CHECK-LABEL: @test14a(
    135 ; CHECK-NOT: sh
    136 define i79 @test14a(i79 %A) {
    137 	%B = shl i79 %A, 4		; <i79> [#uses=1]
    138 	%C = and i79 %B, 1234		; <i79> [#uses=1]
    139 	%D = lshr i79 %C, 4		; <i79> [#uses=1]
    140 	ret i79 %D
    141 }
    142 
    143 ; CHECK-LABEL: @test15(
    144 ; CHECK-NOT: sh
    145 define i45 @test15(i1 %C) {
    146 	%A = select i1 %C, i45 3, i45 1	; <i45> [#uses=1]
    147 	%V = shl i45 %A, 2		; <i45> [#uses=1]
    148 	ret i45 %V
    149 }
    150 
    151 ; CHECK-LABEL: @test15a(
    152 ; CHECK-NOT: sh
    153 define i53 @test15a(i1 %X) {
    154 	%A = select i1 %X, i8 3, i8 1	; <i8> [#uses=1]
    155 	%B = zext i8 %A to i53		; <i53> [#uses=1]
    156 	%V = shl i53 64, %B		; <i53> [#uses=1]
    157 	ret i53 %V
    158 }
    159 
    160 ; CHECK-LABEL: @test16(
    161 ; CHECK-NOT: sh
    162 define i1 @test16(i84 %X) {
    163 	%tmp.3 = ashr i84 %X, 4		; <i84> [#uses=1]
    164 	%tmp.6 = and i84 %tmp.3, 1	; <i84> [#uses=1]
    165 	%tmp.7 = icmp ne i84 %tmp.6, 0	; <i1> [#uses=1]
    166 	ret i1 %tmp.7
    167 }
    168 
    169 ; CHECK-LABEL: @test17(
    170 ; CHECK-NOT: sh
    171 define i1 @test17(i106 %A) {
    172 	%B = lshr i106 %A, 3		; <i106> [#uses=1]
    173 	%C = icmp eq i106 %B, 1234	; <i1> [#uses=1]
    174 	ret i1 %C
    175 }
    176 
    177 ; CHECK-LABEL: @test18(
    178 ; CHECK-NOT: sh
    179 define i1 @test18(i11 %A) {
    180 	%B = lshr i11 %A, 10		; <i11> [#uses=1]
    181 	%C = icmp eq i11 %B, 123	; <i1> [#uses=1]
    182 	ret i1 %C
    183 }
    184 
    185 ; CHECK-LABEL: @test19(
    186 ; CHECK-NOT: sh
    187 define i1 @test19(i37 %A) {
    188 	%B = ashr i37 %A, 2		; <i37> [#uses=1]
    189 	%C = icmp eq i37 %B, 0		; <i1> [#uses=1]
    190 	ret i1 %C
    191 }
    192 
    193 ; CHECK-LABEL: @test19a(
    194 ; CHECK-NOT: sh
    195 define i1 @test19a(i39 %A) {
    196 	%B = ashr i39 %A, 2		; <i39> [#uses=1]
    197 	%C = icmp eq i39 %B, -1		; <i1> [#uses=1]
    198 	ret i1 %C
    199 }
    200 
    201 ; CHECK-LABEL: @test20(
    202 ; CHECK-NOT: sh
    203 define i1 @test20(i13 %A) {
    204 	%B = ashr i13 %A, 12		; <i13> [#uses=1]
    205 	%C = icmp eq i13 %B, 123	; <i1> [#uses=1]
    206 	ret i1 %C
    207 }
    208 
    209 ; CHECK-LABEL: @test21(
    210 ; CHECK-NOT: sh
    211 define i1 @test21(i12 %A) {
    212 	%B = shl i12 %A, 6		; <i12> [#uses=1]
    213 	%C = icmp eq i12 %B, -128		; <i1> [#uses=1]
    214 	ret i1 %C
    215 }
    216 
    217 ; CHECK-LABEL: @test22(
    218 ; CHECK-NOT: sh
    219 define i1 @test22(i14 %A) {
    220 	%B = shl i14 %A, 7		; <i14> [#uses=1]
    221 	%C = icmp eq i14 %B, 0		; <i1> [#uses=1]
    222 	ret i1 %C
    223 }
    224 
    225 ; CHECK-LABEL: @test23(
    226 ; CHECK-NOT: sh
    227 define i11 @test23(i44 %A) {
    228 	%B = shl i44 %A, 33		; <i44> [#uses=1]
    229 	%C = ashr i44 %B, 33		; <i44> [#uses=1]
    230 	%D = trunc i44 %C to i11	; <i8> [#uses=1]
    231 	ret i11 %D
    232 }
    233 
    234 ; CHECK-LABEL: @test25(
    235 ; CHECK-NOT: sh
    236 define i37 @test25(i37 %tmp.2, i37 %AA) {
    237 	%x = lshr i37 %AA, 17		; <i37> [#uses=1]
    238 	%tmp.3 = lshr i37 %tmp.2, 17		; <i37> [#uses=1]
    239 	%tmp.5 = add i37 %tmp.3, %x		; <i37> [#uses=1]
    240 	%tmp.6 = shl i37 %tmp.5, 17		; <i37> [#uses=1]
    241 	ret i37 %tmp.6
    242 }
    243 
    244 ; CHECK-LABEL: @test26(
    245 ; CHECK-NOT: sh
    246 define i40 @test26(i40 %A) {
    247 	%B = lshr i40 %A, 1		; <i40> [#uses=1]
    248 	%C = bitcast i40 %B to i40		; <i40> [#uses=1]
    249 	%D = shl i40 %C, 1		; <i40> [#uses=1]
    250 	ret i40 %D
    251 }
    252