This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

messy combine problem - PPC


I'm looking at a nasty combine problem exposed by my PPC ABI patches.
Suppose you have code like this:

struct a { 
  char hours, day, month;
  short year;
};

extern struct a A;
extern struct a ret_struct_a();

void test(void)
{
  A = ret_struct_a();
}

Right before combine, we have this RTL:

(call_insn 8 48 9 (parallel[ 
            (set (reg:DI 3 r3)
                (call (mem:SI (symbol_ref:SI ("ret_struct_a")) [0 S4 A32])
                    (const_int 0 [0x0])))
            (use (const_int 0 [0x0]))
            (clobber (scratch:SI))
        ] ) -1 (nil)
    (expr_list:REG_UNUSED (scratch:SI)
        (nil))
    (nil))

(insn 9 8 11 (set (reg:SI 115)
        (zero_extend:SI (subreg:HI (reg:SI 3 r3) 2)))
	 30 {*rs6000.md:1385}
    (insn_list 8 (nil))
    (expr_list:REG_DEAD (reg:SI 3 r3)
        (nil)))

As far as I know this is correct RTL.  Combine tries to do something
(I'm not entirely sure what) with insn 9.  At -O1, in the course of
that it calls get_last_value for

  (subreg:HI (reg:SI 3 r3) 2)

and get_last_value obligingly tries to return the call pattern wrapped
in a SUBREG.  This blows up in simplify_gen_subreg, since the call RTX
has no mode.

Breakpoint 1, fancy_abort (
    file=0x8439ba0 "../../../gcc/ppc-eabi/gcc/simplify-rtx.c", line=2649, 
    function=0x843a11b "simplify_gen_subreg")
    at ../../../gcc/ppc-eabi/gcc/diagnostic.c:1450
1450      internal_error ("Internal compiler error in %s, at %s:%d",
(gdb) bt
#0  fancy_abort (file=0x8439ba0 "../../../gcc/ppc-eabi/gcc/simplify-rtx.c", 
    line=2649, function=0x843a11b "simplify_gen_subreg")
    at ../../../gcc/ppc-eabi/gcc/diagnostic.c:1450
#1  0x082b61a9 in simplify_gen_subreg (outermode=HImode, op=0x40174df8, 
    innermode=VOIDmode, byte=0)
    at ../../../gcc/ppc-eabi/gcc/simplify-rtx.c:2649
#2  0x0834d2aa in gen_lowpart_for_combine (mode=HImode, x=0x40174df8)
    at ../../../gcc/ppc-eabi/gcc/combine.c:9748
#3  0x08351cc8 in get_last_value (x=0x4016ea20)
    at ../../../gcc/ppc-eabi/gcc/combine.c:11366


At -O2, -fexpensive-optimizations is on, and 

  (zero_extend:SI (subreg:HI (reg:SI 3 r3) 2))

is replaced by

  (and:SI (reg:SI 3 r3) (const_int 65535 [0xffff]))

before anything else happens; this goes through a different code path,
combine asks for the last value of (reg:SI 3 r3), and
simplify_gen_subreg is not asked to do anything with the CALL pattern.

The $64,000 question: what's the right fix here?  The incoming RTL is
correct, so a fix in the machine description is inappropriate.
simplify_gen_subreg is correct to abort, (subreg:HI (call ...) N) is
ill-formed.  I'm not familiar enough with combine to know where in
between these two the fix should go.

Ideas?

zw


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]