<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - sparc64: incorrect modulo"
href="http://llvm.org/bugs/show_bug.cgi?id=18150">18150</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>sparc64: incorrect modulo
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>phcoder@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>When compiling following code (with -Os) for sparc64 the generated sequence for
modulo produces incorrect results. Source:
unsigned __attribute__ ((noinline))
rem (unsigned long b)
{
return (b * 2606459UL) % 1021;
}
Compilation:
clang -target sparc64 -c -o 1.o 1.c -Os -ccc-gcc-name
sparc64-linux-gnu-gcc-4.7
test
rem(1) returns -816954
rem(2) returns -1633908
rem(3) returns -2450862
assembly:
0000000000000148 <rem>:
rem():
/home/phcoder/grub2/git/grub-core/hello/hello.c:32
148: 9d e3 bf 80 save %sp, -128, %sp
14c: 33 00 09 f1 sethi %hi(0x27c400), %i1
150: b2 16 61 7b or %i1, 0x17b, %i1 ! 27c57b <rem+0x27c433>
/home/phcoder/grub2/git/grub-core/hello/hello.c:34
154: b0 4e 00 19 mulx %i0, %i1, %i0
158: 33 14 4f 3b sethi %hi(0x513cec00), %i1
15c: b2 16 61 b3 or %i1, 0x1b3, %i1 ! 513cedb3 <rem+0x513cec6b>
160: 35 00 30 24 sethi %hi(0xc09000), %i2
164: b4 16 a0 6c or %i2, 0x6c, %i2 ! c0906c <rem+0xc08f24>
168: b5 2e b0 20 sllx %i2, 0x20, %i2
16c: b2 16 80 19 or %i2, %i1, %i1
170: b2 56 00 19 umul %i0, %i1, %i1
174: b3 40 00 00 rd %y, %i1
178: b4 26 00 19 sub %i0, %i1, %i2
17c: b5 36 b0 01 srlx %i2, 1, %i2
180: b2 06 80 19 add %i2, %i1, %i1
184: b3 36 70 09 srlx %i1, 9, %i1
188: b2 4e 63 fd mulx %i1, 0x3fd, %i1
18c: b0 26 00 19 sub %i0, %i1, %i0
190: 81 c7 e0 08 ret
194: 81 e8 00 00 restore
clang -v:
Debian clang version 3.4-1 (tags/RELEASE_34/rc2) (based on LLVM 3.4)
Target: x86_64-pc-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.6
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.6.4
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.7
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.7.3
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7.3
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.2
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>