public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* paradoxical subreg problem
@ 2002-01-28 11:36 law
  2002-01-28 11:50 ` Richard Henderson
                   ` (2 more replies)
  0 siblings, 3 replies; 32+ messages in thread
From: law @ 2002-01-28 11:36 UTC (permalink / raw)
  To: gcc


What a rats nest.  This relates of PRs 5169, 5185 and 5264.

I'll start simple.  On a big endian machine, can this expression be optimized
into true/false at compile time, or must it be run-time computed?

(eq (subreg:SI (mem/s:QI (plus:SI (reg:SI 3 %r3)
                (const_int 15 [0xf])) 1) 0)
    (mem/s:SI (plus:SI (reg:SI 3 %r3)
            (const_int 12 [0xc])) 1))


Think very very carefully about the semantics of a paradoxical subreg.

According to my reading, the compiler is allowed to optimize the expression
into (true) because the bits outside of QImode on the subreg are "don't care
bits" -- meaning they can have any value that is convenient to us.

Agree/Disagree?

Now consider if byte loads zero extend.  Does your answer change?  In the
subreg arm, those "don't care" bits, have a well defined meaning -- ie, we
can't pretend they have whatever value is convenient for us.  So, unless
we have some more specific knowledge about the other arm, then this
expression must be evaluated at runtime.

As you can probably guess, the compiler evaluates the expression at compile
time, which is wrong.


Can someone explain to me clearly what the semantics of a paradoxical
subreg really are?


jeff


^ permalink raw reply	[flat|nested] 32+ messages in thread
* Re:  paradoxical subreg problem
@ 2002-01-28 12:03 Richard Kenner
  2002-01-28 12:15 ` law
  0 siblings, 1 reply; 32+ messages in thread
From: Richard Kenner @ 2002-01-28 12:03 UTC (permalink / raw)
  To: law; +Cc: gcc

    I'll start simple.  On a big endian machine, can this expression be
    optimized into true/false at compile time, or must it be run-time
    computed?

    (eq (subreg:SI (mem/s:QI (plus:SI (reg:SI 3 %r3)
                    (const_int 15 [0xf])) 1) 0)
        (mem/s:SI (plus:SI (reg:SI 3 %r3)
              (const_int 12 [0xc])) 1))

This is equivalent to:

    (set (reg:QI xx) (mem/s:QI (plus:SI (reg:SI 3 %r3)
				        (const_int 15 [0xf])) 0))
    (eq (subreg:SI (reg:QI xx) 0)
        (mem/s:SI (plus:SI (reg:SI 3 %r3)
	                   (const_int 12 [0xc])) 1))


on all machines.

    According to my reading, the compiler is allowed to optimize the
    expression into (true) because the bits outside of QImode on the
    subreg are "don't care bits" -- meaning they can have any value that
    is convenient to us.

    Agree/Disagree?

I agree.

    Now consider if byte loads zero extend.  Does your answer change?  In the
    subreg arm, those "don't care" bits, have a well defined meaning -- ie, we
    can't pretend they have whatever value is convenient for us.  So, unless
    we have some more specific knowledge about the other arm, then this
    expression must be evaluated at runtime.

I disagree.  We "know" what they will be, but the undefined semantics still
holds.  So this can also be true.

^ permalink raw reply	[flat|nested] 32+ messages in thread
* Re: paradoxical subreg problem
@ 2002-01-28 12:18 Richard Kenner
  2002-01-28 12:47 ` law
  2002-01-28 14:53 ` law
  0 siblings, 2 replies; 32+ messages in thread
From: Richard Kenner @ 2002-01-28 12:18 UTC (permalink / raw)
  To: law; +Cc: gcc

    Don't assume you can break it into two expressions.  Consider the
    expression as it stands (and as combine creates it).

Sure, but I'm trying to define what it means by comparison with
two expressions.

    So with your assertions in mind are these two expresions equivalent?

    (and:SI (subreg:SI (mem:QI) 0) (const_int 255))

    (subreg:SI (mem:QI X) 0)

I'd be inclined to say "yes".

^ permalink raw reply	[flat|nested] 32+ messages in thread
* Re: paradoxical subreg problem
@ 2002-01-28 12:47 Richard Kenner
  2002-01-28 13:10 ` law
  0 siblings, 1 reply; 32+ messages in thread
From: Richard Kenner @ 2002-01-28 12:47 UTC (permalink / raw)
  To: law; +Cc: gcc

I think the code issue here is that if the bits are undefined, why is
this being generated?

^ permalink raw reply	[flat|nested] 32+ messages in thread
* Re: paradoxical subreg problem
@ 2002-01-28 13:25 Richard Kenner
  2002-01-28 13:46 ` David Edelsohn
  0 siblings, 1 reply; 32+ messages in thread
From: Richard Kenner @ 2002-01-28 13:25 UTC (permalink / raw)
  To: law; +Cc: gcc

Let me rephrase: why are we genering this if we don't know what those
bits are?

^ permalink raw reply	[flat|nested] 32+ messages in thread
* Re: paradoxical subreg problem
@ 2002-01-28 15:21 Richard Kenner
  2002-01-28 15:41 ` law
  0 siblings, 1 reply; 32+ messages in thread
From: Richard Kenner @ 2002-01-28 15:21 UTC (permalink / raw)
  To: law; +Cc: gcc

    Kenner's initial claim was not that they were undefined, but that they
    were bits we could pretend had any value that was interesting to us
    (don't care).  If you read the section on paradoxical subregs, this is
    what it implies.

I must say I don't understand the distinction between those two cases.

But, as I said, I think the real issue here is why this is being emitted when
we don't know for sure what those bits are.

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

end of thread, other threads:[~2002-01-31 18:15 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-28 11:36 paradoxical subreg problem law
2002-01-28 11:50 ` Richard Henderson
2002-01-28 11:58   ` law
2002-01-28 12:05     ` Richard Henderson
2002-01-28 12:09       ` law
2002-01-28 12:39         ` Richard Henderson
2002-01-28 13:03           ` law
2002-01-28 13:18             ` Richard Henderson
2002-01-28 14:25             ` Michael Matz
2002-01-28 12:15 ` Michael Matz
2002-01-28 15:41 ` Jim Wilson
2002-01-29  1:57   ` Jim Wilson
2002-01-29 10:55   ` Richard Earnshaw
2002-01-29 12:21   ` paradoxical subreg problem [ patch attached ] law
2002-01-29 13:46     ` Richard Earnshaw
2002-01-29 16:41     ` Jim Wilson
2002-01-29 18:08       ` law
2002-01-31 13:22       ` law
2002-01-28 12:03 paradoxical subreg problem Richard Kenner
2002-01-28 12:15 ` law
2002-01-28 12:18 Richard Kenner
2002-01-28 12:47 ` law
2002-01-28 14:53 ` law
2002-01-29 10:31   ` Richard Earnshaw
2002-01-28 12:47 Richard Kenner
2002-01-28 13:10 ` law
2002-01-28 13:25 Richard Kenner
2002-01-28 13:46 ` David Edelsohn
2002-01-28 15:20   ` law
2002-01-28 15:50     ` Geoff Keating
2002-01-28 15:21 Richard Kenner
2002-01-28 15:41 ` law

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