public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* variable-arrays problem
@ 2002-08-07 10:50 Dale Johannesen
  2002-08-07 10:59 ` Graham Stott
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Dale Johannesen @ 2002-08-07 10:50 UTC (permalink / raw)
  To: gcc

I'm looking at a problem in code similar to the following:

  int y;
  {  int a[f()];
     ...
     y = a[0];
  }
  ...reference to y...

The scheduler can move the load of a[0] across the code that
pops a[] from the stack; there is no dependency telling it
not to do that.  Areas below the stack pointer are subject
to random clobbering by context switches on many targets, so
this is not a good thing.  RTL for ppc below; x86 has the
same basic problem.  Note there's no dependency, direct or
indirect, between 117 and 120.  I'm not sure how to fix this.
Will adding a clobber(MEM(a)) at the end of the block suffice?

; r29 was set equal to &a[0] much earlier in the block...

; load a[0]
(insn 117 113 119 (set (reg/v:SI 3 r3 [116])
        (mem/j:SI (reg/f:SI 29 r29 [134]) [0 a+0 S4 A32])) 311 
{*movsi_internal\
1} (insn_list 56 (insn_list:REG_DEP_ANTI 113 (nil)))
    (expr_list:REG_DEAD (reg/f:SI 29 r29 [134])
        (nil)))

; load previous frame pointer from current stack bottom
; (part of ppc calling convention, ymmv, and not really
; relevant to the problem)
(insn:TI 119 117 120 (set (reg:SI 0 r0 [152])
        (mem:SI (reg/f:SI 1 r1) [0 S4 A8])) 311 {*movsi_internal1} 
(insn_list:R\
EG_DEP_OUTPUT 87 (insn_list 89 (insn_list:REG_DEP_ANTI 113 (nil))))
    (nil))

; restore old stack bottom
(insn 120 119 121 (set (reg/f:SI 1 r1)
        (reg/f:SI 28 r28 [117])) 311 {*movsi_internal1} 
(insn_list:REG_DEP_ANTI\
 118 (insn_list:REG_DEP_ANTI 112 (insn_list:REG_DEP_ANTI 113 
(insn_list:REG_DEP\
_ANTI 119 (insn_list:REG_DEP_OUTPUT 89 (insn_list 14 (nil)))))))
    (expr_list:REG_DEAD (reg/f:SI 28 r28 [117])
        (nil)))

; store previous frame pointer into new stack bottom
(insn:TI 121 120 174 (set (mem:SI (reg/f:SI 1 r1) [0 S4 A8])
        (reg:SI 0 r0 [152])) 311 {*movsi_internal1} (insn_list 120 
(insn_list:R\
EG_DEP_ANTI 113 (insn_list 119 (insn_list:REG_DEP_ANTI 117 (nil)))))
    (expr_list:REG_DEAD (reg:SI 0 r0 [152])
        (nil)))

(note 174 121 132 0xe61180 NOTE_INSN_BLOCK_END)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: variable-arrays problem
  2002-08-07 10:50 variable-arrays problem Dale Johannesen
@ 2002-08-07 10:59 ` Graham Stott
  2002-08-07 11:13 ` Richard Henderson
  2002-08-07 11:47 ` Jamie Lokier
  2 siblings, 0 replies; 8+ messages in thread
From: Graham Stott @ 2002-08-07 10:59 UTC (permalink / raw)
  To: Dale Johannesen; +Cc: gcc

Dale,

Do you have a complete testcase?

From your description it appears to imply that the poping
of the a appears at the end of the block containing a.

Graham

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: variable-arrays problem
  2002-08-07 10:50 variable-arrays problem Dale Johannesen
  2002-08-07 10:59 ` Graham Stott
@ 2002-08-07 11:13 ` Richard Henderson
  2002-08-07 11:19   ` Dale Johannesen
  2002-08-07 12:44   ` Dale Johannesen
  2002-08-07 11:47 ` Jamie Lokier
  2 siblings, 2 replies; 8+ messages in thread
From: Richard Henderson @ 2002-08-07 11:13 UTC (permalink / raw)
  To: Dale Johannesen; +Cc: gcc

On Wed, Aug 07, 2002 at 10:50:52AM -0700, Dale Johannesen wrote:
> Will adding a clobber(MEM(a)) at the end of the block suffice?

(clobber (mem:blk (scratch))) will.


r~

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: variable-arrays problem
  2002-08-07 11:13 ` Richard Henderson
@ 2002-08-07 11:19   ` Dale Johannesen
  2002-08-07 12:44     ` Richard Henderson
  2002-08-07 12:44   ` Dale Johannesen
  1 sibling, 1 reply; 8+ messages in thread
From: Dale Johannesen @ 2002-08-07 11:19 UTC (permalink / raw)
  To: Richard Henderson; +Cc: Dale Johannesen, gcc

On Wednesday, August 7, 2002, at 11:13 AM, Richard Henderson wrote:

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: variable-arrays problem
  2002-08-07 10:50 variable-arrays problem Dale Johannesen
  2002-08-07 10:59 ` Graham Stott
  2002-08-07 11:13 ` Richard Henderson
@ 2002-08-07 11:47 ` Jamie Lokier
  2 siblings, 0 replies; 8+ messages in thread
From: Jamie Lokier @ 2002-08-07 11:47 UTC (permalink / raw)
  To: Dale Johannesen; +Cc: gcc

Dale Johannesen wrote:
> Areas below the stack pointer are subject
> to random clobbering by context switches on many targets,

... and by signal handlers too, e.g. on GNU/Linux.
So this is a significant bug.

-- Jamie

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: variable-arrays problem
  2002-08-07 11:19   ` Dale Johannesen
@ 2002-08-07 12:44     ` Richard Henderson
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2002-08-07 12:44 UTC (permalink / raw)
  To: Dale Johannesen; +Cc: gcc

On Wed, Aug 07, 2002 at 11:19:33AM -0700, Dale Johannesen wrote:
> >(clobber (mem:blk (scratch))) will.
> 
> Thanks!  What does that mean exactly?  All memory is clobbered?

Yes.  Ideally we'd just clobber all stack memory, but
we need this special form in order to match bits marked
with RTX_UNCHANGING_P.  Which IMO is sort of a historical
mistake for any stack variable.


r~

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: variable-arrays problem
  2002-08-07 11:13 ` Richard Henderson
  2002-08-07 11:19   ` Dale Johannesen
@ 2002-08-07 12:44   ` Dale Johannesen
  2002-08-07 12:46     ` Richard Henderson
  1 sibling, 1 reply; 8+ messages in thread
From: Dale Johannesen @ 2002-08-07 12:44 UTC (permalink / raw)
  To: Richard Henderson; +Cc: Dale Johannesen, gcc

On Wednesday, August 7, 2002, at 11:13 AM, Richard Henderson wrote:

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: variable-arrays problem
  2002-08-07 12:44   ` Dale Johannesen
@ 2002-08-07 12:46     ` Richard Henderson
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2002-08-07 12:46 UTC (permalink / raw)
  To: Dale Johannesen; +Cc: gcc

On Wed, Aug 07, 2002 at 12:44:07PM -0700, Dale Johannesen wrote:
> Doesn't seem to, actually.  This works for the first scheduler pass,
> but by the time the second one rolls around the clobber has been
> removed, and no dependency is computed between the load and the
> stack pop.  In fact they're both put in the ready list at the same
> cycle.  Now what?

Modify the bits in reload1.c near

  /* Make a pass over all the insns and delete all USEs which we inserted
     only to tag a REG_EQUAL note on them.  Remove all REG_DEAD and REG_UNUSED
     notes.  Delete all CLOBBER insns that don't refer to the return value
     and simplify (subreg (reg)) operands.  Also remove all REG_RETVAL and
     REG_LIBCALL notes since they are no longer useful or accurate.  Strip
     and regenerate REG_INC notes that may have been moved around.  */

to leave clobbers of memory alone.


r~

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2002-08-07 12:46 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-07 10:50 variable-arrays problem Dale Johannesen
2002-08-07 10:59 ` Graham Stott
2002-08-07 11:13 ` Richard Henderson
2002-08-07 11:19   ` Dale Johannesen
2002-08-07 12:44     ` Richard Henderson
2002-08-07 12:44   ` Dale Johannesen
2002-08-07 12:46     ` Richard Henderson
2002-08-07 11:47 ` Jamie Lokier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).