Home | History | Annotate | Download | only in InstCombine
      1 ; RUN: opt < %s -instcombine -S | FileCheck %s
      2 
      3 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
      4 target triple = "x86_64-apple-macosx10.10.0"
      5 
      6 define zeroext i8 @f_u8(i8 zeroext %a) {
      7 ; CHECK-LABEL: @f_u8
      8 ; CHECK-NEXT: %[[A:.*]] = call i8 @llvm.bitreverse.i8(i8 %a)
      9 ; CHECK-NEXT: ret i8 %[[A]]
     10   %1 = shl i8 %a, 7
     11   %2 = shl i8 %a, 5
     12   %3 = and i8 %2, 64
     13   %4 = shl i8 %a, 3
     14   %5 = and i8 %4, 32
     15   %6 = shl i8 %a, 1
     16   %7 = and i8 %6, 16
     17   %8 = lshr i8 %a, 1
     18   %9 = and i8 %8, 8
     19   %10 = lshr i8 %a, 3
     20   %11 = and i8 %10, 4
     21   %12 = lshr i8 %a, 5
     22   %13 = and i8 %12, 2
     23   %14 = lshr i8 %a, 7
     24   %15 = or i8 %14, %1
     25   %16 = or i8 %15, %3
     26   %17 = or i8 %16, %5
     27   %18 = or i8 %17, %7
     28   %19 = or i8 %18, %9
     29   %20 = or i8 %19, %11
     30   %21 = or i8 %20, %13
     31   ret i8 %21
     32 }
     33 
     34 ; The ANDs with 32 and 64 have been swapped here, so the sequence does not
     35 ; completely match a bitreverse.
     36 define zeroext i8 @f_u8_fail(i8 zeroext %a) {
     37 ; CHECK-LABEL: @f_u8_fail
     38 ; CHECK-NOT: call
     39 ; CHECK: ret i8
     40   %1 = shl i8 %a, 7
     41   %2 = shl i8 %a, 5
     42   %3 = and i8 %2, 32
     43   %4 = shl i8 %a, 3
     44   %5 = and i8 %4, 64
     45   %6 = shl i8 %a, 1
     46   %7 = and i8 %6, 16
     47   %8 = lshr i8 %a, 1
     48   %9 = and i8 %8, 8
     49   %10 = lshr i8 %a, 3
     50   %11 = and i8 %10, 4
     51   %12 = lshr i8 %a, 5
     52   %13 = and i8 %12, 2
     53   %14 = lshr i8 %a, 7
     54   %15 = or i8 %14, %1
     55   %16 = or i8 %15, %3
     56   %17 = or i8 %16, %5
     57   %18 = or i8 %17, %7
     58   %19 = or i8 %18, %9
     59   %20 = or i8 %19, %11
     60   %21 = or i8 %20, %13
     61   ret i8 %21
     62 }
     63 
     64 define zeroext i16 @f_u16(i16 zeroext %a) {
     65 ; CHECK-LABEL: @f_u16
     66 ; CHECK-NEXT: %[[A:.*]] = call i16 @llvm.bitreverse.i16(i16 %a)
     67 ; CHECK-NEXT: ret i16 %[[A]]
     68   %1 = shl i16 %a, 15
     69   %2 = shl i16 %a, 13
     70   %3 = and i16 %2, 16384
     71   %4 = shl i16 %a, 11
     72   %5 = and i16 %4, 8192
     73   %6 = shl i16 %a, 9
     74   %7 = and i16 %6, 4096
     75   %8 = shl i16 %a, 7
     76   %9 = and i16 %8, 2048
     77   %10 = shl i16 %a, 5
     78   %11 = and i16 %10, 1024
     79   %12 = shl i16 %a, 3
     80   %13 = and i16 %12, 512
     81   %14 = shl i16 %a, 1
     82   %15 = and i16 %14, 256
     83   %16 = lshr i16 %a, 1
     84   %17 = and i16 %16, 128
     85   %18 = lshr i16 %a, 3
     86   %19 = and i16 %18, 64
     87   %20 = lshr i16 %a, 5
     88   %21 = and i16 %20, 32
     89   %22 = lshr i16 %a, 7
     90   %23 = and i16 %22, 16
     91   %24 = lshr i16 %a, 9
     92   %25 = and i16 %24, 8
     93   %26 = lshr i16 %a, 11
     94   %27 = and i16 %26, 4
     95   %28 = lshr i16 %a, 13
     96   %29 = and i16 %28, 2
     97   %30 = lshr i16 %a, 15
     98   %31 = or i16 %30, %1
     99   %32 = or i16 %31, %3
    100   %33 = or i16 %32, %5
    101   %34 = or i16 %33, %7
    102   %35 = or i16 %34, %9
    103   %36 = or i16 %35, %11
    104   %37 = or i16 %36, %13
    105   %38 = or i16 %37, %15
    106   %39 = or i16 %38, %17
    107   %40 = or i16 %39, %19
    108   %41 = or i16 %40, %21
    109   %42 = or i16 %41, %23
    110   %43 = or i16 %42, %25
    111   %44 = or i16 %43, %27
    112   %45 = or i16 %44, %29
    113   ret i16 %45
    114 }