On Thu, Feb 10, 2022 at 10:10:13AM -0600, Segher Boessenkool wrote:
> >     case POST_DEC:
> >       {
> >         poly_int64 size = GET_MODE_SIZE (GET_MODE (mem));
> >         rtx r1 = XEXP (x, 0);
> >         rtx c = gen_int_mode (-size, GET_MODE (r1));
> >         return fn (mem, x, r1, r1, c, data);
> >       }
> > and that code rightfully expects that the PRE_DEC operand has non-VOIDmode
> > (as it needs to be a REG) - gen_int_mode for VOIDmode results in ICE.
> > I think it is better not to emit the clearly invalid RTL during substitution
> > like we do for other cases, than to adding workarounds for invalid IL
> > created by combine to rtlanal.cc and perhaps elsewhere.
> 
> But we do have that in other cases, and not just for combine.  IMO it
> is a good idea to robustify for_each_inc_dec (simply have it skip if the
> address is not MODE_INT or such).  It also is a good idea to robustify
> combine subst, just as you do.  It is best to do both!

Well, skipping would mean the callback isn't called on it so the autoinc
isn't detected.
But we could do:
         rtx c = (GET_MODE (r1) == VOIDmode
                  ? GEN_INT (-size) : gen_int_mode (-size, GET_MODE (r1)));
with a comment why do do that.

> >     PR middle-end/104446
> >     * combine.cc (subst): Don't substitute CONST_INTs into RTX_AUTOINC
> >     operands.
> > 
> >     * gcc.target/i386/pr104446.c: New test.
> 
> > +/* PR middle-end/104446 */
> > +/* { dg-do compile { target ia32 } } */
> > +/* { dg-options "-O2 -mrtd" } */
> > +
> > +register volatile int a __asm__("%esp");
> > +void foo (void *);
> > +void bar (void *);
> > +
> > +void
> > +baz (void)
> > +{
> > +  foo (__builtin_return_address (0));
> > +  a = 0;
> > +  bar (__builtin_return_address (0));
> > +}
> 
> So does it not fail if you make this valid code (by using another
> register)?  bp, si, or di maybe?

Not on x86, that isn't a general auto-inc-dec target, but uses PRE_DEC
etc. only for the sp hard register.
For other targets we'd need to somehow convince all the earlier passes
(gimple and RTL) not to try to propagate the constant value into the
addition inside of a memory address.

        Jakub

Reply via email to