]> git.ipfire.org Git - thirdparty/gcc.git/commit
forwprop: Fix copy prop for alignment after the final folding [PR122086]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Sat, 25 Oct 2025 00:13:26 +0000 (17:13 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Mon, 27 Oct 2025 00:35:54 +0000 (17:35 -0700)
commit8590b32deac05e6eb368b72bd353749134120a1f
tree1095bb702981dd9c1f92972149796220a62d1cf4
parent596633aa809b7525866d53d137f621583fe4a589
forwprop: Fix copy prop for alignment after the final folding [PR122086]

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.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/testsuite/c-c++-common/ubsan/align-5.c
gcc/testsuite/gcc.dg/torture/pr107389.c [moved from gcc/testsuite/gcc.dg/pr107389.c with 73% similarity]
gcc/tree-ssa-forwprop.cc