Home | History | Annotate | Download | only in ARM
      1 ; RUN: llc -mtriple armv7-none-eabi %s -o - | FileCheck %s --check-prefix=EABI
      2 ; RUN: llc -mtriple armv7-none-eabihf %s -o - | FileCheck %s --check-prefix=EABI
      3 ; All "eabi" (Bare, GNU and Android) must lower SREM/UREM to __aeabi_{u,i}divmod
      4 ; RUN: llc -mtriple armv7-linux-androideabi %s -o - | FileCheck %s --check-prefix=EABI
      5 ; RUN: llc -mtriple armv7-linux-gnueabi %s -o - | FileCheck %s --check-prefix=EABI
      6 ; RUN: llc -mtriple armv7-linux-musleabi %s -o - | FileCheck %s --check-prefix=EABI
      7 ; RUN: llc -mtriple armv7-apple-darwin %s -o - | FileCheck %s --check-prefix=DARWIN
      8 ; FIXME: long-term, we will use "-apple-macho" and won't need this exception:
      9 ; RUN: llc -mtriple armv7-apple-darwin-eabi %s -o - | FileCheck %s --check-prefix=DARWIN
     10 
     11 define signext i16 @f16(i16 signext %a, i16 signext %b) {
     12 ; EABI-LABEL: f16:
     13 ; DARWIN-LABEL: f16:
     14 entry:
     15   %conv = sext i16 %a to i32
     16   %conv1 = sext i16 %b to i32
     17   %div = sdiv i32 %conv, %conv1
     18   %rem = srem i32 %conv, %conv1
     19 ; EABI: __aeabi_idivmod
     20 ; EABI: mov [[div:r[0-9]+]], r0
     21 ; EABI: mov [[rem:r[0-9]+]], r1
     22 ; DARWIN: ___divsi3
     23 ; DARWIN: mov [[sum:r[0-9]+]], r0
     24 ; DARWIN: __modsi3
     25 ; DARWIN: add [[sum]]{{.*}}r0
     26   %rem8 = srem i32 %conv1, %conv
     27 ; EABI: __aeabi_idivmod
     28 ; DARWIN: __modsi3
     29   %add = add nsw i32 %rem, %div
     30   %add13 = add nsw i32 %add, %rem8
     31   %conv14 = trunc i32 %add13 to i16
     32 ; EABI: add r0{{.*}}r1
     33 ; EABI: sxth r0, r0
     34 ; DARWIN: add r0{{.*}}[[sum]]
     35 ; DARWIN: sxth r0, r0
     36   ret i16 %conv14
     37 }
     38 
     39 define i32 @f32(i32 %a, i32 %b) {
     40 ; EABI-LABEL: f32:
     41 ; DARWIN-LABEL: f32:
     42 entry:
     43   %div = sdiv i32 %a, %b
     44   %rem = srem i32 %a, %b
     45 ; EABI: __aeabi_idivmod
     46 ; EABI: mov [[div:r[0-9]+]], r0
     47 ; EABI: mov [[rem:r[0-9]+]], r1
     48 ; DARWIN: ___divsi3
     49 ; DARWIN: mov [[sum:r[0-9]+]], r0
     50 ; DARWIN: __modsi3
     51 ; DARWIN: add [[sum]]{{.*}}r0
     52   %rem1 = srem i32 %b, %a
     53 ; EABI: __aeabi_idivmod
     54 ; DARWIN: __modsi3
     55   %add = add nsw i32 %rem, %div
     56   %add2 = add nsw i32 %add, %rem1
     57 ; EABI: add r0{{.*}}r1
     58 ; DARWIN: add r0{{.*}}[[sum]]
     59   ret i32 %add2
     60 }
     61 
     62 define i32 @uf(i32 %a, i32 %b) {
     63 ; EABI-LABEL: uf:
     64 ; DARWIN-LABEL: uf:
     65 entry:
     66   %div = udiv i32 %a, %b
     67   %rem = urem i32 %a, %b
     68 ; EABI: __aeabi_uidivmod
     69 ; DARWIN: ___udivsi3
     70 ; DARWIN: mov [[sum:r[0-9]+]], r0
     71 ; DARWIN: __umodsi3
     72 ; DARWIN: add [[sum]]{{.*}}r0
     73   %rem1 = urem i32 %b, %a
     74 ; EABI: __aeabi_uidivmod
     75 ; DARWIN: __umodsi3
     76   %add = add nuw i32 %rem, %div
     77   %add2 = add nuw i32 %add, %rem1
     78 ; EABI: add r0{{.*}}r1
     79 ; DARWIN: add r0{{.*}}[[sum]]
     80   ret i32 %add2
     81 }
     82 
     83 define i64 @longf(i64 %a, i64 %b) {
     84 ; EABI-LABEL: longf:
     85 ; DARWIN-LABEL: longf:
     86 entry:
     87   %div = sdiv i64 %a, %b
     88   %rem = srem i64 %a, %b
     89 ; EABI: __aeabi_ldivmod
     90 ; EABI-NEXT: adds r0
     91 ; EABI-NEXT: adc r1
     92 ; EABI-NOT: __aeabi_ldivmod
     93 ; DARWIN: ___divdi3
     94 ; DARWIN: mov [[div1:r[0-9]+]], r0
     95 ; DARWIN: mov [[div2:r[0-9]+]], r1
     96 ; DARWIN: __moddi3
     97   %add = add nsw i64 %rem, %div
     98 ; DARWIN: adds r0{{.*}}[[div1]]
     99 ; DARWIN: adc r1{{.*}}[[div2]]
    100   ret i64 %add
    101 }
    102 
    103 define i16 @shortf(i16 %a, i16 %b) {
    104 ; EABI-LABEL: shortf:
    105 ; DARWIN-LABEL: shortf:
    106 entry:
    107   %div = sdiv i16 %a, %b
    108   %rem = srem i16 %a, %b
    109 ; EABI: __aeabi_idivmod
    110 ; DARWIN: ___divsi3
    111 ; DARWIN: mov [[div1:r[0-9]+]], r0
    112 ; DARWIN: __modsi3
    113   %add = add nsw i16 %rem, %div
    114 ; DARWIN: add r0{{.*}}[[div1]]
    115   ret i16 %add
    116 }
    117 
    118 define i32 @g1(i32 %a, i32 %b) {
    119 ; EABI-LABEL: g1:
    120 ; DARWIN-LABEL: g1:
    121 entry:
    122   %div = sdiv i32 %a, %b
    123   %rem = srem i32 %a, %b
    124 ; EABI: __aeabi_idivmod
    125 ; DARWIN: ___divsi3
    126 ; DARWIN: mov [[sum:r[0-9]+]], r0
    127 ; DARWIN: __modsi3
    128   %add = add nsw i32 %rem, %div
    129 ; EABI:	add	r0{{.*}}r1
    130 ; DARWIN: add r0{{.*}}[[sum]]
    131   ret i32 %add
    132 }
    133 
    134 ; On both Darwin and Gnu, this is just a call to __modsi3
    135 define i32 @g2(i32 %a, i32 %b) {
    136 ; EABI-LABEL: g2:
    137 ; DARWIN-LABEL: g2:
    138 entry:
    139   %rem = srem i32 %a, %b
    140 ; EABI: __aeabi_idivmod
    141 ; DARWIN: __modsi3
    142   ret i32 %rem
    143 ; EABI:	mov	r0, r1
    144 }
    145 
    146 define i32 @g3(i32 %a, i32 %b) {
    147 ; EABI-LABEL: g3:
    148 ; DARWIN-LABEL: g3:
    149 entry:
    150   %rem = srem i32 %a, %b
    151 ; EABI: __aeabi_idivmod
    152 ; EABI: mov [[mod:r[0-9]+]], r1
    153 ; DARWIN: __modsi3
    154 ; DARWIN: mov [[sum:r[0-9]+]], r0
    155   %rem1 = srem i32 %b, %rem
    156 ; EABI: __aeabi_idivmod
    157 ; DARWIN: __modsi3
    158   %add = add nsw i32 %rem1, %rem
    159 ; EABI: add r0, r1, [[mod]]
    160 ; DARWIN: add r0{{.*}}[[sum]]
    161   ret i32 %add
    162 }
    163 
    164 define i32 @g4(i32 %a, i32 %b) {
    165 ; EABI-LABEL: g4:
    166 ; DARWIN-LABEL: g4:
    167 entry:
    168   %div = sdiv i32 %a, %b
    169 ; EABI: __aeabi_idiv{{$}}
    170 ; EABI: mov [[div:r[0-9]+]], r0
    171 ; DARWIN: ___divsi3
    172 ; DARWIN: mov [[sum:r[0-9]+]], r0
    173   %rem = srem i32 %b, %div
    174 ; EABI: __aeabi_idivmod
    175 ; DARWIN: __modsi3
    176   %add = add nsw i32 %rem, %div
    177 ; EABI: add r0, r1, [[div]]
    178 ; DARWIN: add r0{{.*}}[[sum]]
    179   ret i32 %add
    180 }
    181