16195 – [3.4 only] Miscompilation of GCC 3.3.x by 3.4.x (original) (raw)
Description Jakub Jelinek 2004-06-25 11:01:55 UTC
The following testcase distilled from ggc-common.c in GCC 3.3.4 is miscompiled on ppc64. It loads a floating point value (70.0) into the pic register and dereferences it, thus the testcase segfaults.
/* { dg-do run } / / { dg-options "-O2" } / / { dg-options "-mminimal-toc" { target powerpc64-- } } */
extern void abort (void); extern void exit (int);
double attribute((noinline)) foo (void) { return 16441577472.0; }
double attribute((noinline)) bar (double x) { return x; }
int attribute((noinline)) test (void) { double x = foo (); x = bar (x); x /= 1024 * 1024 * 1024; x *= 70; x = x < 70 ? x : 70; x += 30; return x; }
int main (void) { if (test () != 100) abort (); exit (0); }
Comment 1 Jakub Jelinek 2004-06-25 12:01:08 UTC
At lreg time there is: (insn 38 66 39 3 (set (reg:DF 127 [ x ]) (mem/u/f:DF (plus:DI (reg:DI 30 30) (const:DI (minus:DI (symbol_ref/u:DI (".LC1") [flags 0x2]) (symbol_ref:DI (".LCTOC1"))))) [0 S8 A64])) 312 {*movdf_hardfloat64} (nil) (expr_list:REG_DEAD (reg:DI 30 30) (expr_list:REG_EQUAL (const_double:DF 7.0e+1 [0x0.8cp+7]) (nil)))) ... (insn 40 67 42 4 (set (mem/f:DF (plus:DI (reg/f:DI 31 31) (const_int 112 [0x70])) [0 x+0 S8 A64]) (reg:DF 127 [ x ])) 312 {*movdf_hardfloat64} (nil) (expr_list:REG_DEAD (reg:DF 127 [ x ]) (nil))) ... (insn 43 42 44 4 (set (reg:DF 132) (const_double:DF 3.0e+1 [0x0.fp+5])) 312 {*movdf_hardfloat64} (nil) (nil))
As insn 38 is the last one which uses the PIC register at lreg time, global alloc decides to put DF 127 into DF 30: Reloads for insn # 38 Reload 0: reload_out (DF) = (reg:DF 127 [ x ]) GENERAL_REGS, RELOAD_FOR_OUTPUT (opnum = 0) reload_out_reg: (reg:DF 127 [ x ]) reload_reg_rtx: (reg:DF 30 30)
which would be fine if insn 43 was not reloaded into: (insn 43 42 44 4 (set (reg:DF 32 0 [132]) (mem/u/f:DF (plus:DI (reg:DI 30 30) (const:DI (minus:DI (symbol_ref/u:DI (".LC3") [flags 0x2]) (symbol_ref:DI (".LCTOC1"))))) [0 S8 A64])) 312 {*movdf_hardfloat64} (nil) (nil))
RS6000_PIC_OFFSET_TABLE_REGNUM is not a fixed reg on ppc64 and insn 43 at lreg time has no (use (reg:DI 30 30)) or something similar, so there is nothing that prevents this. In GCC 3.3.4 the situation is the same, but the testcase works, as register f0 is chosen instead of r30. In 3.4 without -mminimal-toc, but with -fpic or -fPIC the situation is very similar, s/r30/r2/, but r0 is chosen instead of r2 and thus the testcase doesn't fail, still I don't see what would prevent under bigger register preasure using that register.
Given that rs6000_legitimize_reload_address on TARGET_TOC architectures can reference TOC_REGISTER at any time (call create_TOC_reference ()), I don't see other solution than to: if (TARGET_TOC) { fixed_regs[TOC_REGISTER] = call_used_regs[TOC_REGISTER] = 1; } in CONDITIONAL_REGISTER_USAGE (resp. rs6000_conditional_register_usage in 3.5), do you agree? Dunno if it should be call_really_used_regs[TOC_REGISTER] = 1 as well or not.
Comment 2 Jakub Jelinek 2004-06-25 12:27:13 UTC
*** Bug 16197 has been marked as a duplicate of this bug. ***
Comment 3 Jakub Jelinek 2004-06-25 12:27:46 UTC
*** Bug 16198 has been marked as a duplicate of this bug. ***
Comment 7 Mark Mitchell 2004-08-19 21:24:44 UTC
Since this patch went in on the mainline, may we please also have the 3.4 backport applied?
Comment 9 Drea Pinski 2004-08-19 23:29:59 UTC
Fixed.