Home | History | Annotate | Download | only in SystemZ
      1 ; Test 32-bit rotates left.
      2 ;
      3 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
      4 
      5 ; Check the low end of the RLL range.
      6 define i32 @f1(i32 %a) {
      7 ; CHECK-LABEL: f1:
      8 ; CHECK: rll %r2, %r2, 1
      9 ; CHECK: br %r14
     10   %parta = shl i32 %a, 1
     11   %partb = lshr i32 %a, 31
     12   %or = or i32 %parta, %partb
     13   ret i32 %or
     14 }
     15 
     16 ; Check the high end of the defined RLL range.
     17 define i32 @f2(i32 %a) {
     18 ; CHECK-LABEL: f2:
     19 ; CHECK: rll %r2, %r2, 31
     20 ; CHECK: br %r14
     21   %parta = shl i32 %a, 31
     22   %partb = lshr i32 %a, 1
     23   %or = or i32 %parta, %partb
     24   ret i32 %or
     25 }
     26 
     27 ; We don't generate shifts by out-of-range values.
     28 define i32 @f3(i32 %a) {
     29 ; CHECK-LABEL: f3:
     30 ; CHECK-NOT: rll
     31 ; CHECK: br %r14
     32   %parta = shl i32 %a, 32
     33   %partb = lshr i32 %a, 0
     34   %or = or i32 %parta, %partb
     35   ret i32 %or
     36 }
     37 
     38 ; Check variable shifts.
     39 define i32 @f4(i32 %a, i32 %amt) {
     40 ; CHECK-LABEL: f4:
     41 ; CHECK: rll %r2, %r2, 0(%r3)
     42 ; CHECK: br %r14
     43   %amtb = sub i32 32, %amt
     44   %parta = shl i32 %a, %amt
     45   %partb = lshr i32 %a, %amtb
     46   %or = or i32 %parta, %partb
     47   ret i32 %or
     48 }
     49 
     50 ; Check shift amounts that have a constant term.
     51 define i32 @f5(i32 %a, i32 %amt) {
     52 ; CHECK-LABEL: f5:
     53 ; CHECK: rll %r2, %r2, 10(%r3)
     54 ; CHECK: br %r14
     55   %add = add i32 %amt, 10
     56   %sub = sub i32 32, %add
     57   %parta = shl i32 %a, %add
     58   %partb = lshr i32 %a, %sub
     59   %or = or i32 %parta, %partb
     60   ret i32 %or
     61 }
     62 
     63 ; ...and again with a truncated 64-bit shift amount.
     64 define i32 @f6(i32 %a, i64 %amt) {
     65 ; CHECK-LABEL: f6:
     66 ; CHECK: rll %r2, %r2, 10(%r3)
     67 ; CHECK: br %r14
     68   %add = add i64 %amt, 10
     69   %addtrunc = trunc i64 %add to i32
     70   %sub = sub i32 32, %addtrunc
     71   %parta = shl i32 %a, %addtrunc
     72   %partb = lshr i32 %a, %sub
     73   %or = or i32 %parta, %partb
     74   ret i32 %or
     75 }
     76 
     77 ; ...and again with a different truncation representation.
     78 define i32 @f7(i32 %a, i64 %amt) {
     79 ; CHECK-LABEL: f7:
     80 ; CHECK: rll %r2, %r2, 10(%r3)
     81 ; CHECK: br %r14
     82   %add = add i64 %amt, 10
     83   %sub = sub i64 32, %add
     84   %addtrunc = trunc i64 %add to i32
     85   %subtrunc = trunc i64 %sub to i32
     86   %parta = shl i32 %a, %addtrunc
     87   %partb = lshr i32 %a, %subtrunc
     88   %or = or i32 %parta, %partb
     89   ret i32 %or
     90 }
     91 
     92 ; Check shift amounts that have the largest in-range constant term.  We could
     93 ; mask the amount instead.
     94 define i32 @f8(i32 %a, i32 %amt) {
     95 ; CHECK-LABEL: f8:
     96 ; CHECK: rll %r2, %r2, 524287(%r3)
     97 ; CHECK: br %r14
     98   %add = add i32 %amt, 524287
     99   %sub = sub i32 32, %add
    100   %parta = shl i32 %a, %add
    101   %partb = lshr i32 %a, %sub
    102   %or = or i32 %parta, %partb
    103   ret i32 %or
    104 }
    105 
    106 ; Check the next value up, which without masking must use a separate
    107 ; addition.
    108 define i32 @f9(i32 %a, i32 %amt) {
    109 ; CHECK-LABEL: f9:
    110 ; CHECK: afi %r3, 524288
    111 ; CHECK: rll %r2, %r2, 0(%r3)
    112 ; CHECK: br %r14
    113   %add = add i32 %amt, 524288
    114   %sub = sub i32 32, %add
    115   %parta = shl i32 %a, %add
    116   %partb = lshr i32 %a, %sub
    117   %or = or i32 %parta, %partb
    118   ret i32 %or
    119 }
    120 
    121 ; Check cases where 1 is subtracted from the shift amount.
    122 define i32 @f10(i32 %a, i32 %amt) {
    123 ; CHECK-LABEL: f10:
    124 ; CHECK: rll %r2, %r2, -1(%r3)
    125 ; CHECK: br %r14
    126   %suba = sub i32 %amt, 1
    127   %subb = sub i32 32, %suba
    128   %parta = shl i32 %a, %suba
    129   %partb = lshr i32 %a, %subb
    130   %or = or i32 %parta, %partb
    131   ret i32 %or
    132 }
    133 
    134 ; Check the lowest value that can be subtracted from the shift amount.
    135 ; Again, we could mask the shift amount instead.
    136 define i32 @f11(i32 %a, i32 %amt) {
    137 ; CHECK-LABEL: f11:
    138 ; CHECK: rll %r2, %r2, -524288(%r3)
    139 ; CHECK: br %r14
    140   %suba = sub i32 %amt, 524288
    141   %subb = sub i32 32, %suba
    142   %parta = shl i32 %a, %suba
    143   %partb = lshr i32 %a, %subb
    144   %or = or i32 %parta, %partb
    145   ret i32 %or
    146 }
    147 
    148 ; Check the next value down, which without masking must use a separate
    149 ; addition.
    150 define i32 @f12(i32 %a, i32 %amt) {
    151 ; CHECK-LABEL: f12:
    152 ; CHECK: afi %r3, -524289
    153 ; CHECK: rll %r2, %r2, 0(%r3)
    154 ; CHECK: br %r14
    155   %suba = sub i32 %amt, 524289
    156   %subb = sub i32 32, %suba
    157   %parta = shl i32 %a, %suba
    158   %partb = lshr i32 %a, %subb
    159   %or = or i32 %parta, %partb
    160   ret i32 %or
    161 }
    162 
    163 ; Check that we don't try to generate "indexed" shifts.
    164 define i32 @f13(i32 %a, i32 %b, i32 %c) {
    165 ; CHECK-LABEL: f13:
    166 ; CHECK: ar {{%r3, %r4|%r4, %r3}}
    167 ; CHECK: rll %r2, %r2, 0({{%r[34]}})
    168 ; CHECK: br %r14
    169   %add = add i32 %b, %c
    170   %sub = sub i32 32, %add
    171   %parta = shl i32 %a, %add
    172   %partb = lshr i32 %a, %sub
    173   %or = or i32 %parta, %partb
    174   ret i32 %or
    175 }
    176 
    177 ; Check that the shift amount uses an address register.  It cannot be in %r0.
    178 define i32 @f14(i32 %a, i32 *%ptr) {
    179 ; CHECK-LABEL: f14:
    180 ; CHECK: l %r1, 0(%r3)
    181 ; CHECK: rll %r2, %r2, 0(%r1)
    182 ; CHECK: br %r14
    183   %amt = load i32 , i32 *%ptr
    184   %amtb = sub i32 32, %amt
    185   %parta = shl i32 %a, %amt
    186   %partb = lshr i32 %a, %amtb
    187   %or = or i32 %parta, %partb
    188   ret i32 %or
    189 }
    190 
    191 ; Check another form of f5, which is the one produced by running f5 through
    192 ; instcombine.
    193 define i32 @f15(i32 %a, i32 %amt) {
    194 ; CHECK-LABEL: f15:
    195 ; CHECK: rll %r2, %r2, 10(%r3)
    196 ; CHECK: br %r14
    197   %add = add i32 %amt, 10
    198   %sub = sub i32 22, %amt
    199   %parta = shl i32 %a, %add
    200   %partb = lshr i32 %a, %sub
    201   %or = or i32 %parta, %partb
    202   ret i32 %or
    203 }
    204 
    205 ; Likewise for f7.
    206 define i32 @f16(i32 %a, i64 %amt) {
    207 ; CHECK-LABEL: f16:
    208 ; CHECK: rll %r2, %r2, 10(%r3)
    209 ; CHECK: br %r14
    210   %add = add i64 %amt, 10
    211   %sub = sub i64 22, %amt
    212   %addtrunc = trunc i64 %add to i32
    213   %subtrunc = trunc i64 %sub to i32
    214   %parta = shl i32 %a, %addtrunc
    215   %partb = lshr i32 %a, %subtrunc
    216   %or = or i32 %parta, %partb
    217   ret i32 %or
    218 }
    219 
    220 ; Check cases where (-x & 31) is used instead of 32 - x.
    221 define i32 @f17(i32 %x, i32 %y) {
    222 ; CHECK-LABEL: f17:
    223 ; CHECK: rll %r2, %r2, 0(%r3)
    224 ; CHECK: br %r14
    225 entry:
    226   %shl = shl i32 %x, %y
    227   %sub = sub i32 0, %y
    228   %and = and i32 %sub, 31
    229   %shr = lshr i32 %x, %and
    230   %or = or i32 %shr, %shl
    231   ret i32 %or
    232 }
    233 
    234 ; ...and again with ((32 - x) & 31).
    235 define i32 @f18(i32 %x, i32 %y) {
    236 ; CHECK-LABEL: f18:
    237 ; CHECK: rll %r2, %r2, 0(%r3)
    238 ; CHECK: br %r14
    239 entry:
    240   %shl = shl i32 %x, %y
    241   %sub = sub i32 32, %y
    242   %and = and i32 %sub, 31
    243   %shr = lshr i32 %x, %and
    244   %or = or i32 %shr, %shl
    245   ret i32 %or
    246 }
    247 
    248 ; This is not a rotation.
    249 define i32 @f19(i32 %x, i32 %y) {
    250 ; CHECK-LABEL: f19:
    251 ; CHECK-NOT: rll
    252 ; CHECK: br %r14
    253 entry:
    254   %shl = shl i32 %x, %y
    255   %sub = sub i32 16, %y
    256   %and = and i32 %sub, 31
    257   %shr = lshr i32 %x, %and
    258   %or = or i32 %shr, %shl
    259   ret i32 %or
    260 }
    261 
    262 ; Repeat f17 with an addition on the shift count.
    263 define i32 @f20(i32 %x, i32 %y) {
    264 ; CHECK-LABEL: f20:
    265 ; CHECK: rll %r2, %r2, 199(%r3)
    266 ; CHECK: br %r14
    267 entry:
    268   %add = add i32 %y, 199
    269   %shl = shl i32 %x, %add
    270   %sub = sub i32 0, %add
    271   %and = and i32 %sub, 31
    272   %shr = lshr i32 %x, %and
    273   %or = or i32 %shr, %shl
    274   ret i32 %or
    275 }
    276 
    277 ; ...and again with the InstCombine version.
    278 define i32 @f21(i32 %x, i32 %y) {
    279 ; CHECK-LABEL: f21:
    280 ; CHECK: rll %r2, %r2, 199(%r3)
    281 ; CHECK: br %r14
    282 entry:
    283   %add = add i32 %y, 199
    284   %shl = shl i32 %x, %add
    285   %sub = sub i32 -199, %y
    286   %and = and i32 %sub, 31
    287   %shr = lshr i32 %x, %and
    288   %or = or i32 %shr, %shl
    289   ret i32 %or
    290 }
    291