On Sat, Oct 25, 2025 at 10:30 AM Jeff Law <[email protected]> wrote:
>
>
>
> On 10/24/25 10:51 PM, Andrew Pinski wrote:
> > After r16-4081-g966cdec2b2 which added folding of __builtin_assume_aligned,
> > forwprop would propagate pointers that lower alignment replacing ones with
> > greater alignment. This causes us to lose alignment information that
> > __builtin_assume_aligned provided to expand.  Normally this just loses some
> > optimizations except in the s390 case where the alignment is specifically
> > checked and was for inlining of the atomics; without this patch an 
> > infininite
> > loop would happen.
> >
> > Note this was previously broken for -Og before r16-4081-g966cdec2b2. This
> > fixes -Og case as forwprop is used instead of copyprop.
> >
> > This moves the testcase for pr107389.c to torture to get a generic testcase.
> > pr107389.c was originally for -O0 case but we should test for other
> > optimization levels so this is not lost again.
> >
> > align-5.c is xfailed because __builtin_assume_aligned is not instrumented 
> > for ubsan
> > alignment and ubsan check to see pointer is aligned before emitting a check 
> > for the
> > load (based on the known alignment in compiling). See PR 122038 too. I had 
> > mentioned
> > this issue previously in r16-4081-g966cdec2b2 too.
> >
> >       PR middle-end/107389
> >       PR tree-optimization/122086
> > gcc/ChangeLog:
> >
> >       * tree-ssa-forwprop.cc (forwprop_may_propagate_copy): New function.
> >       (pass_forwprop::execute):  Use forwprop_may_propagate_copy
> >       instead of may_propagate_copy.
> >
> > gcc/testsuite/ChangeLog:
> >
> >       * gcc.dg/pr107389.c: Move to...
> >       * gcc.dg/torture/pr107389.c: ...here. Skip for lto.
> >       Use dg-additional-options rather than dg-options.
> >       * c-c++-common/ubsan/align-5.c: xfail.
> OK after fixing the excessively long line in the function comment for
> fwprop_may_propagate_copy.

Fixed.

>
>
> One could potentially make the argument that this should be in
> may_propagate_copy.  But I'll assume you rejected that idea for good
> reasons.

Yes I rejected that idea because I felt it was giving too much
overhead for may_propagate_copy in earlier (non-forwprop) passes. And
since the only pass that does the copy prop after the folding of
__builtin_assume_aligned is forwprop I didn't see a reason to make a
change to the more generic may_propagate_copy.

Note in the 390 case expand should use the ranger now to get the
alignment but that is not hooked up yet; I might have a look to see if
there is a decent way to do that too.

Thanks,
Andrew

>
> Jeff

Reply via email to