]> git.ipfire.org Git - thirdparty/gcc.git/commit
reassociation: Fix canonical ordering in some cases
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Wed, 26 Nov 2025 21:55:41 +0000 (13:55 -0800)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Thu, 27 Nov 2025 16:46:09 +0000 (08:46 -0800)
commita651bb353554ecb79898d48dd077b7cd288467df
treef5a35856b257a6bed4f76d2670cf5a5788e8c383
parentdfd17e05f9e983660b87e603c062918d2d173fc3
reassociation: Fix canonical ordering in some cases

This was noticed in PR122843 were sometimes reassociation
would create the uncanonical order of operands. This fixes
the problem by swapping the order as the rewrite happens.

Wstringop-overflow.c needed to be xfailed since it started
not to warn because well the warning is too dependent on
the order of operands to MIN_EXPR. This testcase
failed if we had supplied -fno-tree-reassoc before too;
but nothing in the IR changes except the order of 2 operands
of MIN_EXPR. I filed PR 122881 for this xfail.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

* tree-ssa-reassoc.cc (rewrite_expr_tree): Swap
oe1 and oe2 if commutative code and not in
canonical order.

gcc/testsuite/ChangeLog:

* c-c++-common/Wstringop-overflow.c: Xfail, PR 122881.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/testsuite/c-c++-common/Wstringop-overflow.c
gcc/tree-ssa-reassoc.cc