Created attachment 46640 [details] Preprocessed source triggering the error Compilation of ``` int test() { return 0; } ``` with `powerpc-eabi-gcc-9.1.0 -Wall -Wextra -ffreestanding -fstack-limit-symbol=symbol_name -c test.c` leads to the internal compiler error: ``` test.c: In function 'test': test.c:3:1: error: insn does not satisfy its constraints: 3 | } | ^ (insn 17 16 18 (set (reg:SI 0 0) (lo_sum:SI (reg:SI 0 0) (const (plus:SI (symbol_ref:SI ("symbol_name")) (const_int 16 [0x10]))))) "test.c":1:12 700 {elf_low} (nil)) during RTL pass: final test.c:3:1: internal compiler error: in final_scan_insn_1, at final.c:3013 0x5a8c18 _fatal_insn(char const*, rtx_def const*, char const*, int, char const*) ../../gcc/gcc/rtl-error.c:108 0x5a8c3e _fatal_insn_not_found(rtx_def const*, char const*, int, char const*) ../../gcc/gcc/rtl-error.c:118 0x59c796 final_scan_insn_1 ../../gcc/gcc/final.c:3013 0x7cefc8 final_scan_insn(rtx_insn*, _IO_FILE*, int, int, int*) ../../gcc/gcc/final.c:3153 0x7cf28c final_1 ../../gcc/gcc/final.c:2021 0x7cfcc4 rest_of_handle_final ../../gcc/gcc/final.c:4659 0x7cfcc4 execute ../../gcc/gcc/final.c:4737 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions. ``` The gcc-9.1.0 is built with the following options: (gcc --verbose) ``` Using built-in specs. COLLECT_GCC=powerpc-eabi-gcc-9.1.0 COLLECT_LTO_WRAPPER=/fasthome/pspilger/gcc/install/libexec/gcc/powerpc-eabi/9.1.0/lto-wrapper Target: powerpc-eabi Configured with: ../gcc/configure --prefix=/fasthome/pspilger/gcc/install --target=powerpc-eabi --enable-languages=c,c++ --disable-shared --enable-lto --with-float=soft --without-headers --disable-threads --disable-decimal-float --disable-multilib --disable-nls --disable-libstdcxx --disable-libgomp --disable-libvtv --disable-libatomic --disable-libmpx --disable-libquadmath --disable-libssp Thread model: single gcc version 9.1.0 (GCC) ``` The problem also occurs with gcc-8.1.0, but does not occur with gcc-4.9.4.
We did a quick search for changes to the "elf_low" insn which is mentioned in the error message and found commit 55a56a6f323e876a0368f268f2bf85a5739c7498 ("PR target/64180", 2014-12-10 by segher). After reverting this commit (based on "gcc-9_1_0-release") we do not encounter the problem anymore; the generated assembly looks okay.
Only reverting the "elf_low" insn changes of this commit leads to no encounter of the problem, i.e. the following diff "resolves" the problem on gcc-9_1_0-release. diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md index ad80592765d0..f797008eac9b 100644 --- a/gcc/config/rs6000/rs6000.md +++ b/gcc/config/rs6000/rs6000.md @@ -10138,11 +10138,13 @@ "lis %0,%1@ha") (define_insn "elf_low" - [(set (match_operand:SI 0 "gpc_reg_operand" "=r") - (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b") + [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r") + (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b,!*r") (match_operand 2 "" "")))] "TARGET_ELF && !TARGET_64BIT && !flag_pic" - "la %0,%2@l(%1)") + "@ + la %0,%2@l(%1) + addic %0,%1,%K2") (define_insn "*pltseq_tocsave_<mode>" [(set (match_operand:P 0 "memory_operand" "=m")
Confirmed. Any target. Needs -O0 -m32 -fstack-limit-symbol=symbol_name .
(I don't have working GCC 5 and GCC 6 compilers handy, but based on comment 1, I've marked those versions as failing as well).
(BTW, using addic here is wrong: addic clobbers CA, which may not be free).
Created attachment 46853 [details] Proposed patch Could you try this patch?
I doubt the patch will work in all cases. r11 might be in use. BTW, trashing CA in the prologue won't matter since XER is volatile over function calls. So addic could be used. (I know, just not in elf_low so there would be a bit of messing around to use addsi3_carry.)
Ah, no addsi3_carry won't work. You'll need a special version of elf_low that trashes CA.
My patch do not clobber r11, that's the point of it :-)
The prologue is not necessarily inserted as the first bb, so it's not clear to me that CA is never live there. The code copying r11 to r0, and back, is removed by the usual optimisations btw, in all normal cases.
(In reply to Segher Boessenkool from comment #6) > Created attachment 46853 [details] > Proposed patch > > Could you try this patch? The proposed patch works back-ported to 8.1 (residing in rs6000.c then) during compile-time (i.e. nothing breaks) and functionally for an example use case. Will try on vanilla 9.1.
Thanks for testing!
(In reply to Segher Boessenkool from comment #9) > My patch do not clobber r11, that's the point of it :-) Eh, I shouldn't look at patches late at night. Even simple ones.
Author: segher Date: Sat Oct 26 16:38:59 2019 New Revision: 277472 URL: https://gcc.gnu.org/viewcvs?rev=277472&root=gcc&view=rev Log: rs6000: Fix allocate_stack in a corner case (PR91289) When we have -fstack-limit-symbol with sysv we can end up with a non- existing instruction (you cannot add an immediate to register 0). Fix this by using register 11 instead. It might be used for something else already though, so save and restore its value around this. In optimizing compiles these extra moves are usually removed again: the restore by cprop_hardreg, and then the save by rtl_dce. PR target/91289 * config/rs6000/rs6000-logue.c (rs6000_emit_allocate_stack): Don't add an immediate to r0; use r11 instead. Save and restore r11 to r0 around this. Modified: trunk/gcc/ChangeLog trunk/gcc/config/rs6000/rs6000-logue.c
Fixed on trunk (so far).
Author: segher Date: Tue Nov 5 17:17:03 2019 New Revision: 277855 URL: https://gcc.gnu.org/viewcvs?rev=277855&root=gcc&view=rev Log: backport for PR91289 Backport from trunk 2019-10-26 Segher Boessenkool <segher@kernel.crashing.org> PR target/91289 * config/rs6000/rs6000.c (rs6000_emit_allocate_stack): Don't add an immediate to r0; use r11 instead. Save and restore r11 to r0 around this. Modified: branches/gcc-9-branch/gcc/ChangeLog branches/gcc-9-branch/gcc/config/rs6000/rs6000.c
Author: segher Date: Tue Nov 5 17:20:00 2019 New Revision: 277856 URL: https://gcc.gnu.org/viewcvs?rev=277856&root=gcc&view=rev Log: backport for PR91289 Backport from trunk 2019-10-26 Segher Boessenkool <segher@kernel.crashing.org> PR target/91289 * config/rs6000/rs6000.c (rs6000_emit_allocate_stack): Don't add an immediate to r0; use r11 instead. Save and restore r11 to r0 around this. Modified: branches/gcc-8-branch/gcc/ChangeLog branches/gcc-8-branch/gcc/config/rs6000/rs6000.c
Fixed on trunk, 9, 8. Closing.