[LLVMbugs] [Bug 18150] New: sparc64: incorrect modulo

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Dec 5 12:24:21 PST 2013


http://llvm.org/bugs/show_bug.cgi?id=18150

            Bug ID: 18150
           Summary: sparc64: incorrect modulo
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: phcoder at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20131205/2fda6b33/attachment.html>


More information about the llvm-bugs mailing list