<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - LLVM generates illegal instruciton with -O3 on powerpc (32bit)"
   href="https://bugs.llvm.org/show_bug.cgi?id=46683">46683</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLVM generates illegal instruciton with -O3 on powerpc (32bit)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>10.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </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>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>osmanx@problemloesungsmaschine.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23720" name="attach_23720" title="minimal test case">attachment 23720</a> <a href="attachment.cgi?id=23720&action=edit" title="minimal test case">[details]</a></span>
minimal test case

Clang 10 (and 9, and 8, did not check earlier versions) generates illegal
instruction (clrldi) with -O3 on powerpc (32bit). Even setting -mcpu=generic
(or any other -mcpu for that matter) does not avoid generating the problematic
instruction. -O2 works.



The bug affects building libopenmpt (<a href="https://lib.openmpt.org/">https://lib.openmpt.org/</a>) for powerpc with
clang.



=====
manx@bleifus:~/tmp$ cat test.c
/*
clang -std=c11 -O3 -Wall -Wextra -o test test.c
*/
static unsigned int reverse(unsigned int value) {
        const unsigned long bits = sizeof(unsigned int) * 8;
        unsigned int result = 0;
        for (unsigned long i = 0; i < bits; ++i) {
                result <<= 1;
                result |= (unsigned int)(value & 0x1);
                value >>= 1;
        }
        return result;
}
int main(int argc, char * argv []) {
        (void)argv;
        return reverse(argc);
}
manx@bleifus:~/tmp$ clang-10 --version
clang version 10.0.0-3
Target: powerpc-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
manx@bleifus:~/tmp$ clang-10 -std=c11 -O3 -Wall -Wextra -o test test.c
manx@bleifus:~/tmp$ ./test
Illegal instruction
manx@bleifus:~/tmp$ cat /proc/cpuinfo
processor       : 0
cpu             : 7447A, altivec supported
clock           : 1416.666661MHz
revision        : 1.1 (pvr 8003 0101)
bogomips        : 83.24

timebase        : 41620907
platform        : PowerMac
model           : PowerMac10,1
machine         : PowerMac10,1
motherboard     : PowerMac10,1 MacRISC3 Power Macintosh
detected as     : 287 (Mac mini)
pmac flags      : 00000010
L2 cache        : 512K unified
pmac-generation : NewWorld
Memory          : 512 MB
manx@bleifus:~/tmp$ clang-10 -c -std=c11 -O3 -Wall -Wextra -o test.o test.c
manx@bleifus:~/tmp$ objdump -d test.o

test.o:     file format elf32-powerpc


Disassembly of section .text:

00000000 <main>:
   0:   3c 80 aa aa     lis     r4,-21846
   4:   60 84 aa aa     ori     r4,r4,43690
   8:   54 65 08 3c     rlwinm  r5,r3,1,0,30
   c:   7c a4 20 38     and     r4,r5,r4
  10:   3c a0 55 55     lis     r5,21845
  14:   60 a5 55 55     ori     r5,r5,21845
  18:   54 63 f8 7e     rlwinm  r3,r3,31,1,31
  1c:   7c 63 28 38     and     r3,r3,r5
  20:   3c a0 cc cc     lis     r5,-13108
  24:   7c 63 23 78     or      r3,r3,r4
  28:   60 a5 cc cc     ori     r5,r5,52428
  2c:   54 64 10 3a     rlwinm  r4,r3,2,0,29
  30:   7c 84 28 38     and     r4,r4,r5
  34:   3c a0 33 33     lis     r5,13107
  38:   60 a5 33 33     ori     r5,r5,13107
  3c:   54 63 f0 be     rlwinm  r3,r3,30,2,31
  40:   7c 63 28 38     and     r3,r3,r5
  44:   3c a0 f0 f0     lis     r5,-3856
  48:   7c 63 23 78     or      r3,r3,r4
  4c:   60 a5 f0 f0     ori     r5,r5,61680
  50:   54 64 20 36     rlwinm  r4,r3,4,0,27
  54:   7c 84 28 38     and     r4,r4,r5
  58:   3c a0 0f 0f     lis     r5,3855
  5c:   60 a5 0f 0f     ori     r5,r5,3855
  60:   54 63 e1 3e     rlwinm  r3,r3,28,4,31
  64:   7c 63 28 38     and     r3,r3,r5
  68:   7c 63 23 78     or      r3,r3,r4
  6c:   54 64 c0 3e     rotlwi  r4,r3,24
  70:   50 64 42 1e     rlwimi  r4,r3,8,8,15
  74:   50 64 46 3e     rlwimi  r4,r3,8,24,31
  78:   78 83 00 20     clrldi  r3,r4,32
  7c:   4e 80 00 20     blr
manx@bleifus:~/tmp$ gdb ./test
GNU gdb (Debian 9.2-1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <<a href="http://gnu.org/licenses/gpl.html">http://gnu.org/licenses/gpl.html</a>>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "powerpc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<<a href="http://www.gnu.org/software/gdb/bugs/">http://www.gnu.org/software/gdb/bugs/</a>>.
Find the GDB manual and other documentation resources online at:
    <<a href="http://www.gnu.org/software/gdb/documentation/">http://www.gnu.org/software/gdb/documentation/</a>>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./test...
(No debugging symbols found in ./test)
(gdb) run
Starting program: /home/manx/tmp/test

Program received signal SIGILL, Illegal instruction.
0x1000047c in main ()
(gdb) display/i $pc
1: x/i $pc
=> 0x1000047c <main+120>:       clrldi  r3,r4,32
(gdb) quit
A debugging session is active.

        Inferior 1 [process 3728] will be killed.

Quit anyway? (y or n) y
manx@bleifus:~/tmp$ clang-10 -std=c11 -O2 -Wall -Wextra -o test test.c
manx@bleifus:~/tmp$ ./test
manx@bleifus:~/tmp$ clang-10 -c -std=c11 -O2 -Wall -Wextra -o test.o test.c
manx@bleifus:~/tmp$ objdump -d test.o

test.o:     file format elf32-powerpc


Disassembly of section .text:

00000000 <main>:
   0:   38 80 00 20     li      r4,32
   4:   7c 89 03 a6     mtctr   r4
   8:   38 80 00 00     li      r4,0
   c:   7c 85 23 78     mr      r5,r4
  10:   7c 64 1b 78     mr      r4,r3
  14:   54 63 f8 7e     rlwinm  r3,r3,31,1,31
  18:   50 a4 08 3c     rlwimi  r4,r5,1,0,30
  1c:   42 00 ff f0     bdnz    c <main+0xc>
  20:   7c 83 23 78     mr      r3,r4
  24:   4e 80 00 20     blr
manx@bleifus:~/tmp$ clang-10 -std=c11 -mcpu=generic -O3 -Wall -Wextra -o test
test.c
manx@bleifus:~/tmp$ ./test
Illegal instruction
manx@bleifus:~/tmp$ 
=====



Tested on Debian-ports powerpc on an Apple MacMini G4.</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>