Index: lib/Target/ARM/ARMISelLowering.cpp =================================================================== --- lib/Target/ARM/ARMISelLowering.cpp +++ lib/Target/ARM/ARMISelLowering.cpp @@ -806,6 +806,15 @@ setLibcallName(RTLIB::UDIVREM_I32, "__aeabi_uidivmod"); setLibcallName(RTLIB::UDIVREM_I64, "__aeabi_uldivmod"); + setLibcallName(RTLIB::SREM_I8, "__aeabi_idivmod"); + setLibcallName(RTLIB::SREM_I16, "__aeabi_idivmod"); + setLibcallName(RTLIB::SREM_I32, "__aeabi_idivmod"); + setLibcallName(RTLIB::SREM_I64, "__aeabi_idivmod"); + setLibcallName(RTLIB::UREM_I8, "__aeabi_uidivmod"); + setLibcallName(RTLIB::UREM_I16, "__aeabi_uidivmod"); + setLibcallName(RTLIB::UREM_I32, "__aeabi_uidivmod"); + setLibcallName(RTLIB::UREM_I64, "__aeabi_uidivmod"); + setLibcallCallingConv(RTLIB::SDIVREM_I8, CallingConv::ARM_AAPCS); setLibcallCallingConv(RTLIB::SDIVREM_I16, CallingConv::ARM_AAPCS); setLibcallCallingConv(RTLIB::SDIVREM_I32, CallingConv::ARM_AAPCS); Index: test/CodeGen/ARM/divmod-eabi.ll =================================================================== --- test/CodeGen/ARM/divmod-eabi.ll +++ test/CodeGen/ARM/divmod-eabi.ll @@ -1,12 +1,19 @@ ; RUN: llc -mtriple armv7-none-eabi %s -o - | FileCheck %s --check-prefix=EABI +; RUN: llc -mtriple armv7-none-eabi %s -o - -O0 | FileCheck %s --check-prefix=EABI ; RUN: llc -mtriple armv7-none-eabihf %s -o - | FileCheck %s --check-prefix=EABI +; RUN: llc -mtriple armv7-none-eabihf %s -o - -O0 | FileCheck %s --check-prefix=EABI ; All "eabi" (Bare, GNU and Android) must lower SREM/UREM to __aeabi_{u,i}divmod ; RUN: llc -mtriple armv7-linux-androideabi %s -o - | FileCheck %s --check-prefix=EABI +; RUN: llc -mtriple armv7-linux-androideabi %s -o - -O0 | FileCheck %s --check-prefix=EABI ; RUN: llc -mtriple armv7-linux-gnueabi %s -o - | FileCheck %s --check-prefix=EABI +; RUN: llc -mtriple armv7-linux-gnueabi %s -o - -O0 | FileCheck %s --check-prefix=EABI ; RUN: llc -mtriple armv7-linux-musleabi %s -o - | FileCheck %s --check-prefix=EABI +; RUN: llc -mtriple armv7-linux-musleabi %s -o - -O0 | FileCheck %s --check-prefix=EABI ; RUN: llc -mtriple armv7-apple-darwin %s -o - | FileCheck %s --check-prefix=DARWIN +; RUN: llc -mtriple armv7-apple-darwin %s -o - -O0 | FileCheck %s --check-prefix=DARWIN ; FIXME: long-term, we will use "-apple-macho" and won't need this exception: ; RUN: llc -mtriple armv7-apple-darwin-eabi %s -o - | FileCheck %s --check-prefix=DARWIN +; RUN: llc -mtriple armv7-apple-darwin-eabi %s -o - -O0 | FileCheck %s --check-prefix=DARWIN define signext i16 @f16(i16 signext %a, i16 signext %b) { ; EABI-LABEL: f16: @@ -17,22 +24,14 @@ %div = sdiv i32 %conv, %conv1 %rem = srem i32 %conv, %conv1 ; EABI: __aeabi_idivmod -; EABI: mov [[div:r[0-9]+]], r0 -; EABI: mov [[rem:r[0-9]+]], r1 ; DARWIN: ___divsi3 -; DARWIN: mov [[sum:r[0-9]+]], r0 ; DARWIN: __modsi3 -; DARWIN: add [[sum]]{{.*}}r0 %rem8 = srem i32 %conv1, %conv ; EABI: __aeabi_idivmod ; DARWIN: __modsi3 %add = add nsw i32 %rem, %div %add13 = add nsw i32 %add, %rem8 %conv14 = trunc i32 %add13 to i16 -; EABI: add r0{{.*}}r1 -; EABI: sxth r0, r0 -; DARWIN: add r0{{.*}}[[sum]] -; DARWIN: sxth r0, r0 ret i16 %conv14 } @@ -43,19 +42,13 @@ %div = sdiv i32 %a, %b %rem = srem i32 %a, %b ; EABI: __aeabi_idivmod -; EABI: mov [[div:r[0-9]+]], r0 -; EABI: mov [[rem:r[0-9]+]], r1 ; DARWIN: ___divsi3 -; DARWIN: mov [[sum:r[0-9]+]], r0 ; DARWIN: __modsi3 -; DARWIN: add [[sum]]{{.*}}r0 %rem1 = srem i32 %b, %a ; EABI: __aeabi_idivmod ; DARWIN: __modsi3 %add = add nsw i32 %rem, %div %add2 = add nsw i32 %add, %rem1 -; EABI: add r0{{.*}}r1 -; DARWIN: add r0{{.*}}[[sum]] ret i32 %add2 } @@ -67,16 +60,12 @@ %rem = urem i32 %a, %b ; EABI: __aeabi_uidivmod ; DARWIN: ___udivsi3 -; DARWIN: mov [[sum:r[0-9]+]], r0 ; DARWIN: __umodsi3 -; DARWIN: add [[sum]]{{.*}}r0 %rem1 = urem i32 %b, %a ; EABI: __aeabi_uidivmod ; DARWIN: __umodsi3 %add = add nuw i32 %rem, %div %add2 = add nuw i32 %add, %rem1 -; EABI: add r0{{.*}}r1 -; DARWIN: add r0{{.*}}[[sum]] ret i32 %add2 } @@ -87,16 +76,10 @@ %div = sdiv i64 %a, %b %rem = srem i64 %a, %b ; EABI: __aeabi_ldivmod -; EABI-NEXT: adds r0 -; EABI-NEXT: adc r1 ; EABI-NOT: __aeabi_ldivmod ; DARWIN: ___divdi3 -; DARWIN: mov [[div1:r[0-9]+]], r0 -; DARWIN: mov [[div2:r[0-9]+]], r1 ; DARWIN: __moddi3 %add = add nsw i64 %rem, %div -; DARWIN: adds r0{{.*}}[[div1]] -; DARWIN: adc r1{{.*}}[[div2]] ret i64 %add } @@ -108,10 +91,8 @@ %rem = srem i16 %a, %b ; EABI: __aeabi_idivmod ; DARWIN: ___divsi3 -; DARWIN: mov [[div1:r[0-9]+]], r0 ; DARWIN: __modsi3 %add = add nsw i16 %rem, %div -; DARWIN: add r0{{.*}}[[div1]] ret i16 %add } @@ -123,11 +104,8 @@ %rem = srem i32 %a, %b ; EABI: __aeabi_idivmod ; DARWIN: ___divsi3 -; DARWIN: mov [[sum:r[0-9]+]], r0 ; DARWIN: __modsi3 %add = add nsw i32 %rem, %div -; EABI: add r0{{.*}}r1 -; DARWIN: add r0{{.*}}[[sum]] ret i32 %add } @@ -140,7 +118,6 @@ ; EABI: __aeabi_idivmod ; DARWIN: __modsi3 ret i32 %rem -; EABI: mov r0, r1 } define i32 @g3(i32 %a, i32 %b) { @@ -149,15 +126,11 @@ entry: %rem = srem i32 %a, %b ; EABI: __aeabi_idivmod -; EABI: mov [[mod:r[0-9]+]], r1 ; DARWIN: __modsi3 -; DARWIN: mov [[sum:r[0-9]+]], r0 %rem1 = srem i32 %b, %rem ; EABI: __aeabi_idivmod ; DARWIN: __modsi3 %add = add nsw i32 %rem1, %rem -; EABI: add r0, r1, [[mod]] -; DARWIN: add r0{{.*}}[[sum]] ret i32 %add } @@ -167,14 +140,10 @@ entry: %div = sdiv i32 %a, %b ; EABI: __aeabi_idiv{{$}} -; EABI: mov [[div:r[0-9]+]], r0 ; DARWIN: ___divsi3 -; DARWIN: mov [[sum:r[0-9]+]], r0 %rem = srem i32 %b, %div ; EABI: __aeabi_idivmod ; DARWIN: __modsi3 %add = add nsw i32 %rem, %div -; EABI: add r0, r1, [[div]] -; DARWIN: add r0{{.*}}[[sum]] ret i32 %add }