<div dir="ltr"><div><div>Hi Bill,</div><div><br></div><div>I realize that we are somewhat late in the cycle, but I think that this should be merged into the 3.5 branch. Currently, an invocation of __umodsi3 in a compiler-rt built with clang 3.5 for an ARM chip with idiv may fault (if you are lucky) or plain corrupt memory.</div>
<div><br></div><div>The change is limited to ARMv7 with idiv and ARMv8 chips.</div></div><div><br></div>On Sat, Aug 9, 2014 at 1:17 PM, Saleem Abdulrasool <span dir="ltr"><<a href="mailto:compnerd@compnerd.org" target="_blank">compnerd@compnerd.org</a>></span> wrote:<br>
<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: compnerd<br>
Date: Sat Aug 9 15:17:37 2014<br>
New Revision: 215295<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=215295&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=215295&view=rev</a><br>
Log:<br>
builtins: correct __umodsi3, __udivsi3 on ARM<br>
<br>
When building the builtins for a modern CPU (idiv support), __umodsi3 was<br>
completely incorrect as it would behave as __udivmosi3, which takes a tertiary<br>
parameter which is a pointer.<br>
<br>
__udivsi3 was also incorrect, returning the remainder in r1. Although this<br>
would not result in any crash or invalid behaviour as r1 is a caller saved<br>
register in AAPCS, this is unnecessary. Simply perform the division ignoring<br><br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Modified:<br>
compiler-rt/trunk/lib/builtins/arm/udivsi3.S<br>
compiler-rt/trunk/lib/builtins/arm/umodsi3.S<br>
<br>
Modified: compiler-rt/trunk/lib/builtins/arm/udivsi3.S<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/arm/udivsi3.S?rev=215295&r1=215294&r2=215295&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/arm/udivsi3.S?rev=215295&r1=215294&r2=215295&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/builtins/arm/udivsi3.S (original)<br>
+++ compiler-rt/trunk/lib/builtins/arm/udivsi3.S Sat Aug 9 15:17:37 2014<br>
@@ -27,9 +27,7 @@ DEFINE_COMPILERRT_FUNCTION(__udivsi3)<br>
#if __ARM_ARCH_EXT_IDIV__<br>
tst r1, r1<br>
beq LOCAL_LABEL(divby0)<br>
- mov r3, r0<br>
- udiv r0, r3, r1<br>
- mls r1, r0, r1, r3<br>
+ udiv r0, r0, r1<br>
bx lr<br>
#else<br>
cmp r1, #1<br>
<br>
Modified: compiler-rt/trunk/lib/builtins/arm/umodsi3.S<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/arm/umodsi3.S?rev=215295&r1=215294&r2=215295&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/arm/umodsi3.S?rev=215295&r1=215294&r2=215295&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/builtins/arm/umodsi3.S (original)<br>
+++ compiler-rt/trunk/lib/builtins/arm/umodsi3.S Sat Aug 9 15:17:37 2014<br>
@@ -25,10 +25,8 @@ DEFINE_COMPILERRT_FUNCTION(__umodsi3)<br>
#if __ARM_ARCH_EXT_IDIV__<br>
tst r1, r1<br>
beq LOCAL_LABEL(divby0)<br>
- mov r3, r0<br>
- udiv r0, r3, r1<br>
- mls r1, r0, r1, r3<br>
- str r1, [r2]<br>
+ udiv r2, r0, r1<br>
+ mls r0, r2, r1, r0<br>
bx lr<br>
#else<br>
cmp r1, #1<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Saleem Abdulrasool<br>compnerd (at) compnerd (dot) org
</div></div>