tkchia / gcc-ia16

Fork of Lambertsen & Jenner (& al.)'s IA-16 (Intel 16-bit x86) port of GNU compilers ― added far pointers & more • use https://github.com/tkchia/build-ia16 to build • Ubuntu binaries at https://launchpad.net/%7Etkchia/+archive/ubuntu/build-ia16/ • DJGPP/MS-DOS binaries at https://gitlab.com/tkchia/build-ia16/-/releases • mirror of https://gitlab.com/tkchia/gcc-ia16
GNU General Public License v2.0
178 stars 13 forks source link

ICE for fmemcpy with -Os, -O2 #16

Closed bartoldeman closed 6 years ago

bartoldeman commented 6 years ago

This "fmemcpy" causes trouble with -Os and -O2, but is ok with -O1.

$ cat fmemcpy.c
void _fmemcpy(void __far *s1, const void __far *s2, unsigned length)
{       char __far *p;
        const char __far *q;

        if(length) {
                p = s1;
                q = s2;
                do *p++ = *q++;
                while(--length);
        }
}
$ ia16-elf-gcc -Os fmemcpy.c -c
fmemcpy.c: In function ‘_fmemcpy’:
fmemcpy.c:11:1: error: unable to find a register to spill
 }
 ^
fmemcpy.c:11:1: error: this is the insn:
(insn 38 90 91 3 (set (reg:QI 52)
        (mem:QI (plus:HI (unspec:HI [
                        (reg:HI 51 [orig:49 s2+2 ] [49])
                    ] 1)
                (reg:HI 40 [ q ])) [0 *q_3+0 S1 A8 AS1])) fmemcpy.c:8 9 {*movqi}
     (expr_list:REG_DEAD (reg:HI 51 [orig:49 s2+2 ] [49])
        (nil)))
fmemcpy.c:11: confused by earlier errors, bailing out
tkchia commented 6 years ago

Hello @bartoldeman ,

Thanks for the report, and my apologies for the delay.

It seems that at optimization levels -Os and -O2, GCC tries to assign %es to both FP_SEG (p) and FP_SEG (q) (so to speak) at the same time --- this for some reason does not happen at -O1. I did some quick tests which suggest that freeing up %ds for register allocation should resolve the problem (as well as #12).

Also, I find that if I compile your _fmemcpy routine with -O3, I get a different crash:

fmemcpy.c: In function ‘_fmemcpy’:
fmemcpy.c:1:6: internal compiler error: in ia16_expand_weird_pointer_plus_expr, at config/ia16/ia16.c:604
 void _fmemcpy(void __far *s1, const void __far *s2, unsigned length)
      ^~~~~~~~
0xb9c79a ia16_expand_weird_pointer_plus_expr(rtx_def*, rtx_def*, rtx_def*, machine_mode)
    ../../gcc-ia16/gcc/config/ia16/ia16.c:604
0x72f840 expand_expr_real_2(separate_ops*, rtx_def*, machine_mode, expand_modifier)
    ../../gcc-ia16/gcc/expr.c:8288
0x65356d expand_gimple_stmt_1
    ../../gcc-ia16/gcc/cfgexpand.c:3654
0x65356d expand_gimple_stmt
    ../../gcc-ia16/gcc/cfgexpand.c:3714
0x654a80 expand_gimple_basic_block
    ../../gcc-ia16/gcc/cfgexpand.c:5720
0x65907e execute
    ../../gcc-ia16/gcc/cfgexpand.c:6335
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.

I will also see how I can fix this other crash.

Thank you!