Bug 88435 - Compiling with optimizations causes the compiler to fail.
Summary: Compiling with optimizations causes the compiler to fail.
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 8.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2018-12-10 21:10 UTC by Mattis Lind
Modified: 2018-12-11 18:17 UTC (History)
0 users

See Also:
Host:
Target: pdp11-aout
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mattis Lind 2018-12-10 21:10:27 UTC
pdp11-aout-gcc -save-temps -O2 -v  -m10  -Ttext 1000 -msoft-float  -nostartfiles  -nodefaultlibs  -nostdlib   -fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations gccbug.c 
Using built-in specs.
COLLECT_GCC=pdp11-aout-gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/pdp11-aout/8.2.0/lto-wrapper
Target: pdp11-aout
Configured with: ./configure --target=pdp11-aout --disable-nls --without-headers --enable-languages=c
Thread model: single
gcc version 8.2.0 (GCC) 
COLLECT_GCC_OPTIONS='-save-temps' '-O2' '-v' '-m10' '-Ttext' '1000' '-msoft-float' '-nostartfiles' '-nodefaultlibs' '-nostdlib' '-fno-strict-aliasing' '-fwrapv' '-fno-aggressive-loop-optimizations'
 /usr/local/libexec/gcc/pdp11-aout/8.2.0/cc1 -E -quiet -v -imultilib msoft-float gccbug.c -m10 -msoft-float -fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations -O2 -fpch-preprocess -o gccbug.i
ignoring nonexistent directory "/usr/local/lib/gcc/pdp11-aout/8.2.0/../../../../pdp11-aout/sys-include"
ignoring nonexistent directory "/usr/local/lib/gcc/pdp11-aout/8.2.0/../../../../pdp11-aout/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/gcc/pdp11-aout/8.2.0/include
 /usr/local/lib/gcc/pdp11-aout/8.2.0/include-fixed
End of search list.
COLLECT_GCC_OPTIONS='-save-temps' '-O2' '-v' '-m10' '-Ttext' '1000' '-msoft-float' '-nostartfiles' '-nodefaultlibs' '-nostdlib' '-fno-strict-aliasing' '-fwrapv' '-fno-aggressive-loop-optimizations'
 /usr/local/libexec/gcc/pdp11-aout/8.2.0/cc1 -fpreprocessed gccbug.i -quiet -dumpbase gccbug.c -m10 -msoft-float -auxbase gccbug -O2 -version -fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations -o gccbug.s
GNU C17 (GCC) version 8.2.0 (pdp11-aout)
	compiled by GNU C version 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.76), GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C17 (GCC) version 8.2.0 (pdp11-aout)
	compiled by GNU C version 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.76), GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: bc392ef67ca9ec448731a9f0a726ee14
gccbug.c: In function 'pollConsole':
gccbug.c:11:1: error: unrecognizable insn:
 }
 ^
(insn 13 12 14 2 (set (reg:SI 35)
        (ashift:SI (reg:SI 34)
            (const_int -9 [0xfffffffffffffff7]))) "gccbug.c":5 -1
     (nil))
during RTL pass: vregs
gccbug.c:11:1: internal compiler error: in extract_insn, at recog.c:2304
libbacktrace could not find executable to open
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.




$ cat gccbug.c
int pollConsole () {
  volatile unsigned int  * rxcsr = (unsigned int *) 0177560; 
  unsigned int tmp =  512 & *rxcsr;
  if (tmp == 512) {
    return 1;
  }
  else {
    return 0;
  }
} 

The compile fail if the two literals 512 is equal and greater than 16. It also has to have one single bit set. I.e. 32, 64, 128... 

33,34 woks fine.

$ cat gccbug.i
# 1 "gccbug.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "gccbug.c"

int pollConsole () {
  volatile unsigned int * rxcsr = (unsigned int *) 0177560;
  unsigned int tmp = 512 & *rxcsr;
  if (tmp == 512) {
    return 1;
  }
  else {
    return 0;
  }
}
Comment 1 Mattis Lind 2018-12-10 21:22:27 UTC
The very same bug is present in 9.0

The problem goes away if you change to pdp-11/40 rather than pdp-11/10 using -m40 option.
Comment 2 pkoning 2018-12-10 21:42:47 UTC
I don't see it in the current V9, rev 266823.

./xgcc -B. -O2 -S ~/Documents/pr88435.c -m10 
cat pr88435.s 

	.text
	.even
	.globl	_pollConsole
_pollConsole:
	mov	@$-0220,r0
	mov	$011,r1
L_4:
	clc
	ror	r0
	dec	r1
	bne	L_4
	bic	$-02,r0
	rts	pc

Clearly this is not optimal -- it shouldn't do this with a shift but rather using a "BIT" instruction.  But the code does produce the correct answer and the compiler doesn't fail.
Comment 3 Mattis Lind 2018-12-11 18:17:03 UTC
I can confirm that latest 9.0 doesn't have this problem.