Home | History | Annotate | Download | only in X86
      1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
      2 ; RUN: llc -mtriple=i686-unknown < %s | FileCheck %s --check-prefix=X32
      3 ; RUN: llc -mtriple=x86_64-unknown < %s | FileCheck %s --check-prefix=X64
      4 
      5 @array = weak global [4 x i32] zeroinitializer
      6 
      7 define i32 @test_lshr_and(i32 %x) {
      8 ; X32-LABEL: test_lshr_and:
      9 ; X32:       # %bb.0:
     10 ; X32-NEXT:    movl {{[0-9]+}}(%esp), %eax
     11 ; X32-NEXT:    andl $12, %eax
     12 ; X32-NEXT:    movl array(%eax), %eax
     13 ; X32-NEXT:    retl
     14 ;
     15 ; X64-LABEL: test_lshr_and:
     16 ; X64:       # %bb.0:
     17 ; X64-NEXT:    # kill: def $edi killed $edi def $rdi
     18 ; X64-NEXT:    shrl $2, %edi
     19 ; X64-NEXT:    andl $3, %edi
     20 ; X64-NEXT:    movl array(,%rdi,4), %eax
     21 ; X64-NEXT:    retq
     22   %tmp2 = lshr i32 %x, 2
     23   %tmp3 = and i32 %tmp2, 3
     24   %tmp4 = getelementptr [4 x i32], [4 x i32]* @array, i32 0, i32 %tmp3
     25   %tmp5 = load i32, i32* %tmp4, align 4
     26   ret i32 %tmp5
     27 }
     28 
     29 define i32* @test_exact1(i32 %a, i32 %b, i32* %x)  {
     30 ; X32-LABEL: test_exact1:
     31 ; X32:       # %bb.0:
     32 ; X32-NEXT:    movl {{[0-9]+}}(%esp), %eax
     33 ; X32-NEXT:    subl {{[0-9]+}}(%esp), %eax
     34 ; X32-NEXT:    sarl %eax
     35 ; X32-NEXT:    addl {{[0-9]+}}(%esp), %eax
     36 ; X32-NEXT:    retl
     37 ;
     38 ; X64-LABEL: test_exact1:
     39 ; X64:       # %bb.0:
     40 ; X64-NEXT:    subl %edi, %esi
     41 ; X64-NEXT:    sarl $3, %esi
     42 ; X64-NEXT:    movslq %esi, %rax
     43 ; X64-NEXT:    leaq (%rdx,%rax,4), %rax
     44 ; X64-NEXT:    retq
     45   %sub = sub i32 %b, %a
     46   %shr = ashr exact i32 %sub, 3
     47   %gep = getelementptr inbounds i32, i32* %x, i32 %shr
     48   ret i32* %gep
     49 }
     50 
     51 define i32* @test_exact2(i32 %a, i32 %b, i32* %x)  {
     52 ; X32-LABEL: test_exact2:
     53 ; X32:       # %bb.0:
     54 ; X32-NEXT:    movl {{[0-9]+}}(%esp), %eax
     55 ; X32-NEXT:    subl {{[0-9]+}}(%esp), %eax
     56 ; X32-NEXT:    sarl %eax
     57 ; X32-NEXT:    addl {{[0-9]+}}(%esp), %eax
     58 ; X32-NEXT:    retl
     59 ;
     60 ; X64-LABEL: test_exact2:
     61 ; X64:       # %bb.0:
     62 ; X64-NEXT:    subl %edi, %esi
     63 ; X64-NEXT:    sarl $3, %esi
     64 ; X64-NEXT:    movslq %esi, %rax
     65 ; X64-NEXT:    leaq (%rdx,%rax,4), %rax
     66 ; X64-NEXT:    retq
     67   %sub = sub i32 %b, %a
     68   %shr = ashr exact i32 %sub, 3
     69   %gep = getelementptr inbounds i32, i32* %x, i32 %shr
     70   ret i32* %gep
     71 }
     72 
     73 define i32* @test_exact3(i32 %a, i32 %b, i32* %x)  {
     74 ; X32-LABEL: test_exact3:
     75 ; X32:       # %bb.0:
     76 ; X32-NEXT:    movl {{[0-9]+}}(%esp), %eax
     77 ; X32-NEXT:    subl {{[0-9]+}}(%esp), %eax
     78 ; X32-NEXT:    addl {{[0-9]+}}(%esp), %eax
     79 ; X32-NEXT:    retl
     80 ;
     81 ; X64-LABEL: test_exact3:
     82 ; X64:       # %bb.0:
     83 ; X64-NEXT:    subl %edi, %esi
     84 ; X64-NEXT:    sarl $2, %esi
     85 ; X64-NEXT:    movslq %esi, %rax
     86 ; X64-NEXT:    leaq (%rdx,%rax,4), %rax
     87 ; X64-NEXT:    retq
     88   %sub = sub i32 %b, %a
     89   %shr = ashr exact i32 %sub, 2
     90   %gep = getelementptr inbounds i32, i32* %x, i32 %shr
     91   ret i32* %gep
     92 }
     93 
     94 define i32* @test_exact4(i32 %a, i32 %b, i32* %x)  {
     95 ; X32-LABEL: test_exact4:
     96 ; X32:       # %bb.0:
     97 ; X32-NEXT:    movl {{[0-9]+}}(%esp), %eax
     98 ; X32-NEXT:    subl {{[0-9]+}}(%esp), %eax
     99 ; X32-NEXT:    shrl %eax
    100 ; X32-NEXT:    addl {{[0-9]+}}(%esp), %eax
    101 ; X32-NEXT:    retl
    102 ;
    103 ; X64-LABEL: test_exact4:
    104 ; X64:       # %bb.0:
    105 ; X64-NEXT:    # kill: def $esi killed $esi def $rsi
    106 ; X64-NEXT:    subl %edi, %esi
    107 ; X64-NEXT:    shrl $3, %esi
    108 ; X64-NEXT:    leaq (%rdx,%rsi,4), %rax
    109 ; X64-NEXT:    retq
    110   %sub = sub i32 %b, %a
    111   %shr = lshr exact i32 %sub, 3
    112   %gep = getelementptr inbounds i32, i32* %x, i32 %shr
    113   ret i32* %gep
    114 }
    115 
    116 define i32* @test_exact5(i32 %a, i32 %b, i32* %x)  {
    117 ; X32-LABEL: test_exact5:
    118 ; X32:       # %bb.0:
    119 ; X32-NEXT:    movl {{[0-9]+}}(%esp), %eax
    120 ; X32-NEXT:    subl {{[0-9]+}}(%esp), %eax
    121 ; X32-NEXT:    shrl %eax
    122 ; X32-NEXT:    addl {{[0-9]+}}(%esp), %eax
    123 ; X32-NEXT:    retl
    124 ;
    125 ; X64-LABEL: test_exact5:
    126 ; X64:       # %bb.0:
    127 ; X64-NEXT:    # kill: def $esi killed $esi def $rsi
    128 ; X64-NEXT:    subl %edi, %esi
    129 ; X64-NEXT:    shrl $3, %esi
    130 ; X64-NEXT:    leaq (%rdx,%rsi,4), %rax
    131 ; X64-NEXT:    retq
    132   %sub = sub i32 %b, %a
    133   %shr = lshr exact i32 %sub, 3
    134   %gep = getelementptr inbounds i32, i32* %x, i32 %shr
    135   ret i32* %gep
    136 }
    137 
    138 define i32* @test_exact6(i32 %a, i32 %b, i32* %x)  {
    139 ; X32-LABEL: test_exact6:
    140 ; X32:       # %bb.0:
    141 ; X32-NEXT:    movl {{[0-9]+}}(%esp), %eax
    142 ; X32-NEXT:    subl {{[0-9]+}}(%esp), %eax
    143 ; X32-NEXT:    addl {{[0-9]+}}(%esp), %eax
    144 ; X32-NEXT:    retl
    145 ;
    146 ; X64-LABEL: test_exact6:
    147 ; X64:       # %bb.0:
    148 ; X64-NEXT:    # kill: def $esi killed $esi def $rsi
    149 ; X64-NEXT:    subl %edi, %esi
    150 ; X64-NEXT:    leaq (%rsi,%rdx), %rax
    151 ; X64-NEXT:    retq
    152   %sub = sub i32 %b, %a
    153   %shr = lshr exact i32 %sub, 2
    154   %gep = getelementptr inbounds i32, i32* %x, i32 %shr
    155   ret i32* %gep
    156 }
    157