Steven Bosscher <stevenb....@gmail.com> writes:
> On Thu, May 17, 2012, Meador Inge <meadori ar codesourcery dot com> wrote:
>>> ;; This is *not* equal to zero because the upper
>>> ;; two bytes are undefined.
>>> (insn 14 13 15 2 (set (reg:SI 142)
>>>         (subreg:SI (reg:QI 141) 0))
>>>      (expr_list:REG_EQUAL (const_int 0 [0])
>>>         (nil)))
>
> Hmm, this is what doc/rtl.texi has to say about paradoxical subregs as 
> rvalues:
>
> The high-order bits of rvalues are in the following circumstances:
>
> * subreg regs
> The upper bits are defined when SUBREG_PROMOTED_VAR_P is true.
> SUBREG_PROMOTED_UNSIGNED_P describes what the upper bits hold.
>
> The way I read this, suggests your patch allow simplify_subreg on
> paradoxical subregs if SUBREG_PROMOTED_VAR_P is true. But I'm not
> exactly an RTL expert, and I'm not 100% sure if this part of doc
> applies here. ;-)

Yeah, I think that's just for non-paradoxical lowpart subregs.
I.e. for (subreg:M (reg:N ...)), it's making a guarantee about
the bits that are in N but not in M.

After agonising over this for a couple of days, I think it's probably
the correct fix.  What we're doing now would be valid if the only use of
equiv_constant(x) were to substitute for x.  The name and current use
of the function obviously require equality though.

Patch is OK, thanks.  It might be worth extending fold_rtx and
equiv_constant to set a flag that says whether the returned value
is equivalent or simply one of many valid replacement values.
We'd then be able to replace uses of registers like 142 with 0,
while not replacing uses of 0 with 142.  I don't know how much it
would buy us though.  That kind of thing is probably more of a job
for fwprop.

Please add UL to the hex constants in the testcase.  Not sure whether
it matters for 16-bit int targets or not, but better safe than sorry :-)

Also, rather than:

> +      /* Otherwise see if we already have a constant for the inner REG.
> +      Don't bother with paradoxical subregs because we have no way
> +      of knowing what the upper bytes are.  */

how about:

      /* Otherwise see if we already have a constant for the inner REG,
         and if that is enough to calculate an equivalent constant for
         the subreg.  Note that the upper bits of paradoxical subregs
         are undefined, so they cannot be said to equal anything.  */

Richard

Reply via email to