public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Why doesn't combine like volatiles? (volatile_ok again, sorry!)
@ 2005-11-21 18:12 Dave Korn
  2005-11-21 21:46 ` Ian Lance Taylor
  0 siblings, 1 reply; 49+ messages in thread
From: Dave Korn @ 2005-11-21 18:12 UTC (permalink / raw)
  To: gcc



  Morning gcc-hackers!


  I was wondering why combine could piece together two insns like these:

----------------------------<snip!>----------------------------
(insn 11 5 12 0 0x1002f330 (set (reg:QI 74)
        (mem:QI (reg/v/f:SI 70) [0 S1 A8])) 25 {movqi} (insn_list 3 (nil))
    (expr_list:REG_DEAD (reg/v/f:SI 70)
        (nil)))

(insn 12 11 14 0 0x1002f330 (set (reg/v:SI 72)
        (zero_extend:SI (reg:QI 74))) 17 {zero_extendqisi2} (insn_list 11
(nil))
    (expr_list:REG_DEAD (reg:QI 74)
        (nil)))
----------------------------<snip!>----------------------------

into one like this:

----------------------------<snip!>----------------------------
(note 11 5 12 0 NOTE_INSN_DELETED)

(insn 12 11 14 0 0x1002f330 (set (reg/v:SI 72)
        (zero_extend:SI (mem:QI (reg/v/f:SI 70) [0 S1 A8]))) 17
{zero_extendqisi2} (insn_list 3 (nil))
    (expr_list:REG_DEAD (reg/v/f:SI 70)
        (nil)))
----------------------------<snip!>----------------------------

but it fails if the MEM references are volatile:

----------------------------<snip!>----------------------------
(insn 11 5 12 0 0x1002fc60 (set (reg:QI 74)
        (mem/v:QI (reg/v/f:SI 70) [0 S1 A8])) 25 {movqi} (insn_list 3 (nil))
    (expr_list:REG_DEAD (reg/v/f:SI 70)
        (nil)))

(insn 12 11 14 0 0x1002fc60 (set (reg/v:SI 72)
        (zero_extend:SI (reg:QI 74))) 17 {zero_extendqisi2} (insn_list 11
(nil))
    (expr_list:REG_DEAD (reg:QI 74)
        (nil)))
----------------------------<snip!>----------------------------

  Looking at it, this seems to be quite deliberate: combine_instructions()
calls init_recog_no_volatile() before it runs the combine pass and
init_recog() afterward.  I haven't delved into the morass of machine-generated
loveliness that is insn-recog.c, but by modifying recog_for_combine() to try
calling recog() twice, once with volatiles disabled, and once with them
enabled, I've been able to determine that that's definitely the cause that
prevents the volatile loads from being combined with the zero_extend
operations.

  All this is despite the fact that I have "#define LOAD_EXTEND_OP(MODE)
ZERO_EXTEND" in my target header file.

  I see from the archives that this has come up before.  I found loads of
mails from Mike Stump suggesting to google his name and "volatile_ok" to find
a patch, but I couldn't find it, and I couldn't get a clear impression of what
the real issue is here.

  What's a decent solution here?  Should I come up with a new version of
general_operand, call it general_or_volatile_operand, that would accept mem/v
references, and use it for the movXX patterns in my md?  Or, given that this
is likely to be the most common case and perhaps the only one I'm going to
care about, should I just define a pattern that matches the (set:SI
(zero_extend:SI (mem:QI))) insn directly?  Or how about the dodgy hacks that
temporarily reenable volatile_ok and then clear it again after calling the
recognizer?

    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....
 

^ permalink raw reply	[flat|nested] 49+ messages in thread
* Re: Why doesn't combine like volatiles? (volatile_ok again, sorry!)
@ 2005-11-22 16:16 Richard Kenner
  2005-11-22 18:38 ` Robert Dewar
  0 siblings, 1 reply; 49+ messages in thread
From: Richard Kenner @ 2005-11-22 16:16 UTC (permalink / raw)
  To: dewar; +Cc: gcc

    > AFAICT it is probably safe to do the combination provided (in addition
    > to the normal restrictions on combine) that:

    I think this is a bad idea in practice, since volatile will be used
    to describe memory mapped devices, and combining can completely
    mess up the access. Yes, it is probably conforming, but it is
    simply not a good idea to do this, and the gain is too small.

The issue is that we currently don't combine if volatile is anywhere in
sight, whether or not we'd be affecting that access. Just because you have
something volatile on the LHS doesn't mean we can't combine into the RHS.  A
good example are addressing modes: if we have a MEM->MEM copy with one side
volatile, doing anything inside the addressing computation of either (even
the volatile one) is perfectly safe.

I do agree, of course, that the gain here is small, but we do lots of things
in GCC with small gains ...

^ permalink raw reply	[flat|nested] 49+ messages in thread
* Re: Why doesn't combine like volatiles? (volatile_ok again, sorry!)
@ 2005-11-28 17:28 Richard Kenner
  2005-11-28 17:44 ` Mike Stump
  0 siblings, 1 reply; 49+ messages in thread
From: Richard Kenner @ 2005-11-28 17:28 UTC (permalink / raw)
  To: mrs; +Cc: gcc

    >> Possibly, but I think the more interesting observation is listed in
    >> parenthesis: Can a volatile access ever alias a non-volatile access?
    >
    > I think the answer is no, Certainly Ada has compile time rules
    > carefully written to make this impossible.

    gcc is not just an Ada compiler.  Clearly, the answer has to be yes  
    to support GNU C.

And where is the standard for the language known as "GNU C"?  One of the
major problems with the GNU C extensions has been that they were done in an
era where people weren't as precise as they are today regarding language
definition and the interactions of features with each other and with
optimizations.

Obviously, Robert was giving Ada as an example of a language that *does*
precisely give the answers to these questions, unlikely GNU C.  Another
interesting datapoint is clearly what the current C and C++ standards say on
the matter.  However, despite the legacy code issue, I wouldn't put too much
import on the relatively informal definition of "GNU C".

^ permalink raw reply	[flat|nested] 49+ messages in thread
* Re: Why doesn't combine like volatiles? (volatile_ok again, sorry!)
@ 2005-11-28 18:50 Richard Kenner
  2005-11-28 20:25 ` Mike Stump
  0 siblings, 1 reply; 49+ messages in thread
From: Richard Kenner @ 2005-11-28 18:50 UTC (permalink / raw)
  To: mrs; +Cc: gcc

    He said we can do anything, this is untrue.  I rail against the casual
    use of the word because it misleads others into believing it, and then
    proposing patches that do anything they want, and yet make gcc worse.
    I realize there that we have no documentation person that writes down
    everything religiously and that from time to time, people that should
    write documentation, don't.  I'm just as guilty (or more so) as
    everyone else.  Realize, some consider that just a simple
    documentation bug, not an opportunity to go messing with a fine compiler.

It's not that simple and I suspect you know it.  The things that aren't
written down are the "contract" between the programmer and the compiler
about what the latter is guaranteeing to the former.  It's nice to say
that a compiler won't ever make a change that won't break *any* program,
but that's impossible.  Even the slightest change can "break" a program
that relies on an uninitialized variable, for example.  Obviously, we
understand that's permissible because such a program is "not correct"
or "erroneous".  But the problem in extending that doctrine is that we
have to know which programs are erroneous and when there's no precise
documentation of the language in which they're written (GNU C),
there's no way to say with certainty whether a program is or not.
So there's no way to know whether the set of programs that a given
change will break consists of just erroneous programs.  One can take
the very conservative approach of avoiding that problem by not making
*any* changes that could conceivably break a program, but that would mean
making no progress on improving a "fine compiler".

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

end of thread, other threads:[~2005-11-28 22:26 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-21 18:12 Why doesn't combine like volatiles? (volatile_ok again, sorry!) Dave Korn
2005-11-21 21:46 ` Ian Lance Taylor
2005-11-22 10:45   ` Richard Earnshaw
2005-11-22 15:33     ` Dave Korn
2005-11-22 15:52       ` Richard Earnshaw
2005-11-22 16:10         ` Robert Dewar
2005-11-27  3:18           ` Mike Stump
2005-11-27  3:14         ` Mike Stump
2005-11-28 11:01           ` Richard Earnshaw
2005-11-28 11:13             ` Robert Dewar
2005-11-28 13:09               ` Paolo Bonzini
2005-11-28 21:05                 ` Laurent GUERBY
2005-11-28 22:26                   ` Robert Dewar
2005-11-28 17:14               ` Mike Stump
2005-11-28 17:19                 ` Andrew Pinski
2005-11-28 17:22                   ` Mike Stump
2005-11-28 17:35                   ` Mike Stump
2005-11-28 17:41                     ` Andrew Pinski
2005-11-28 17:53                       ` Mike Stump
2005-11-28 18:08                         ` Joe Buck
2005-11-28 18:28                           ` Mike Stump
2005-11-28 19:12                         ` Robert Dewar
2005-11-28 19:56                           ` Mike Stump
2005-11-28 20:01                             ` Robert Dewar
2005-11-28 20:18                               ` Gabriel Dos Reis
2005-11-28 20:21                                 ` Robert Dewar
2005-11-28 19:05                 ` Robert Dewar
2005-11-28 19:53                   ` Mike Stump
2005-11-28 17:11             ` Mike Stump
2005-11-28 17:29               ` Dave Korn
2005-11-28 18:14                 ` Mike Stump
2005-11-23 19:54   ` Accidentally on the list Eric J. Goforth
2005-11-23 19:56     ` Gerald Pfeifer
2005-11-22 16:16 Why doesn't combine like volatiles? (volatile_ok again, sorry!) Richard Kenner
2005-11-22 18:38 ` Robert Dewar
2005-11-22 19:02   ` Dave Korn
2005-11-22 19:10     ` Robert Dewar
2005-11-22 20:39       ` Dave Korn
2005-11-23 11:27       ` Richard Earnshaw
2005-11-23 11:41         ` Robert Dewar
2005-11-23 12:04           ` Richard Earnshaw
2005-11-23 12:15             ` Robert Dewar
2005-11-28 17:28 Richard Kenner
2005-11-28 17:44 ` Mike Stump
2005-11-28 18:50 Richard Kenner
2005-11-28 20:25 ` Mike Stump
2005-11-28 20:40   ` Andrew Pinski
2005-11-28 21:55     ` Mike Stump
2005-11-28 22:14       ` Andrew Pinski

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).