Home | History | Annotate | Download | only in InstCombine
      1 ; RUN: opt < %s -instcombine -S | FileCheck %s
      2 
      3 ; FIXME: Some of these tests belong in InstSimplify.
      4 
      5 ; Integer BitWidth <= 64 && BitWidth % 8 != 0.
      6 
      7 define i39 @test0(i39 %A) {
      8 ; CHECK-LABEL: @test0(
      9 ; CHECK-NEXT:    ret i39 0
     10 ;
     11   %B = and i39 %A, 0 ; zero result
     12   ret i39 %B
     13 }
     14 
     15 define i15 @test2(i15 %x) {
     16 ; CHECK-LABEL: @test2(
     17 ; CHECK-NEXT:    ret i15 %x
     18 ;
     19   %tmp.2 = and i15 %x, -1 ; noop
     20   ret i15 %tmp.2
     21 }
     22 
     23 define i23 @test3(i23 %x) {
     24 ; CHECK-LABEL: @test3(
     25 ; CHECK-NEXT:    ret i23 0
     26 ;
     27   %tmp.0 = and i23 %x, 127
     28   %tmp.2 = and i23 %tmp.0, 128
     29   ret i23 %tmp.2
     30 }
     31 
     32 define i1 @test4(i37 %x) {
     33 ; CHECK-LABEL: @test4(
     34 ; CHECK-NEXT:    [[B:%.*]] = icmp ugt i37 %x, 2147483647
     35 ; CHECK-NEXT:    ret i1 [[B]]
     36 ;
     37   %A = and i37 %x, -2147483648
     38   %B = icmp ne i37 %A, 0
     39   ret i1 %B
     40 }
     41 
     42 define i7 @test5(i7 %A, i7* %P) {
     43 ; CHECK-LABEL: @test5(
     44 ; CHECK-NEXT:    [[B:%.*]] = or i7 %A, 3
     45 ; CHECK-NEXT:    [[C:%.*]] = xor i7 [[B]], 12
     46 ; CHECK-NEXT:    store i7 [[C]], i7* %P, align 1
     47 ; CHECK-NEXT:    ret i7 3
     48 ;
     49   %B = or i7 %A, 3
     50   %C = xor i7 %B, 12
     51   store i7 %C, i7* %P
     52   %r = and i7 %C, 3
     53   ret i7 %r
     54 }
     55 
     56 define i47 @test7(i47 %A) {
     57 ; CHECK-LABEL: @test7(
     58 ; CHECK-NEXT:    [[TMP1:%.*]] = lshr i47 %A, 39
     59 ; CHECK-NEXT:    ret i47 [[TMP1]]
     60 ;
     61   %X = ashr i47 %A, 39 ;; sign extend
     62   %C1 = and i47 %X, 255
     63   ret i47 %C1
     64 }
     65 
     66 ; Integer BitWidth > 64 && BitWidth <= 1024.
     67 
     68 define i999 @test8(i999 %A) {
     69 ; CHECK-LABEL: @test8(
     70 ; CHECK-NEXT:    ret i999 0
     71 ;
     72   %B = and i999 %A, 0 ; zero result
     73   ret i999 %B
     74 }
     75 
     76 define i1005 @test9(i1005 %x) {
     77 ; CHECK-LABEL: @test9(
     78 ; CHECK-NEXT:    ret i1005 %x
     79 ;
     80   %tmp.2 = and i1005 %x, -1 ; noop
     81   ret i1005 %tmp.2
     82 }
     83 
     84 define i123 @test10(i123 %x) {
     85 ; CHECK-LABEL: @test10(
     86 ; CHECK-NEXT:    ret i123 0
     87 ;
     88   %tmp.0 = and i123 %x, 127
     89   %tmp.2 = and i123 %tmp.0, 128
     90   ret i123 %tmp.2
     91 }
     92 
     93 define i1 @test11(i737 %x) {
     94 ; CHECK-LABEL: @test11(
     95 ; CHECK-NEXT:    [[B:%.*]] = icmp ugt i737 %x, 2147483647
     96 ; CHECK-NEXT:    ret i1 [[B]]
     97 ;
     98   %A = and i737 %x, -2147483648
     99   %B = icmp ne i737 %A, 0
    100   ret i1 %B
    101 }
    102 
    103 define i117 @test12(i117 %A, i117* %P) {
    104 ; CHECK-LABEL: @test12(
    105 ; CHECK-NEXT:    [[B:%.*]] = or i117 %A, 3
    106 ; CHECK-NEXT:    [[C:%.*]] = xor i117 [[B]], 12
    107 ; CHECK-NEXT:    store i117 [[C]], i117* %P, align 4
    108 ; CHECK-NEXT:    ret i117 3
    109 ;
    110   %B = or i117 %A, 3
    111   %C = xor i117 %B, 12
    112   store i117 %C, i117* %P
    113   %r = and i117 %C, 3
    114   ret i117 %r
    115 }
    116 
    117 define i1024 @test13(i1024 %A) {
    118 ; CHECK-LABEL: @test13(
    119 ; CHECK-NEXT:    [[TMP1:%.*]] = lshr i1024 %A, 1016
    120 ; CHECK-NEXT:    ret i1024 [[TMP1]]
    121 ;
    122   %X = ashr i1024 %A, 1016 ;; sign extend
    123   %C1 = and i1024 %X, 255
    124   ret i1024 %C1
    125 }
    126 
    127