[llvm-bugs] [Bug 46683] New: LLVM generates illegal instruciton with -O3 on powerpc (32bit)
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Jul 11 00:29:11 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=46683
Bug ID: 46683
Summary: LLVM generates illegal instruciton with -O3 on powerpc
(32bit)
Product: clang
Version: 10.0
Hardware: Macintosh
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: LLVM Codegen
Assignee: unassignedclangbugs at nondot.org
Reporter: osmanx at problemloesungsmaschine.de
CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
richard-llvm at metafoo.co.uk
Created attachment 23720
--> https://bugs.llvm.org/attachment.cgi?id=23720&action=edit
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 (https://lib.openmpt.org/) for powerpc with
clang.
=====
manx at 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 at bleifus:~/tmp$ clang-10 --version
clang version 10.0.0-3
Target: powerpc-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
manx at bleifus:~/tmp$ clang-10 -std=c11 -O3 -Wall -Wextra -o test test.c
manx at bleifus:~/tmp$ ./test
Illegal instruction
manx at 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 at bleifus:~/tmp$ clang-10 -c -std=c11 -O3 -Wall -Wextra -o test.o test.c
manx at 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 at 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 <http://gnu.org/licenses/gpl.html>
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:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
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 at bleifus:~/tmp$ clang-10 -std=c11 -O2 -Wall -Wextra -o test test.c
manx at bleifus:~/tmp$ ./test
manx at bleifus:~/tmp$ clang-10 -c -std=c11 -O2 -Wall -Wextra -o test.o test.c
manx at 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 at bleifus:~/tmp$ clang-10 -std=c11 -mcpu=generic -O3 -Wall -Wextra -o test
test.c
manx at bleifus:~/tmp$ ./test
Illegal instruction
manx at bleifus:~/tmp$
=====
Tested on Debian-ports powerpc on an Apple MacMini G4.
--
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/20200711/fd862b6c/attachment.html>
More information about the llvm-bugs
mailing list