[gcc r17-2882] cselim: Fix cond_store_replacement_limited for clobbers [PR126569]
Andrea Pinski via Gcc-cvs <[email protected]> Sun, 2 Aug 2026 05:37:21 +0000 (GMT)
| Newsgroups | gmane.comp.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://gcc.gnu.org/g:c42241d2de04ce75550649ed3dca7ff1549c3343 commit r17-2882-gc42241d2de04ce75550649ed3dca7ff1549c3343 Author: Andrea Pinski <[email protected]> Date: Sat Aug 1 17:58:48 2026 -0700 cselim: Fix cond_store_replacement_limited for clobbers [PR126569] cond_store_replacement_limited mistaken a clobber for a store, meaning that it would use {CLOBBER(eos)} as a phi argument. So this fixes that issue by rejecting that case. Pushed as obvious after bootstrap/test on x86_64-linux-gnu. PR tree-optimization/126569 gcc/ChangeLog: * tree-ssa-phiopt.cc (cond_store_replacement_limited): A clobber is not a store. gcc/testsuite/ChangeLog: * gcc.dg/pr126569-1.c: New test. Signed-off-by: Andrea Pinski <[email protected]> Diff: --- gcc/testsuite/gcc.dg/pr126569-1.c | 20 ++++++++++++++++++++ gcc/tree-ssa-phiopt.cc | 2 ++ 2 files changed, 22 insertions(+) diff --git a/gcc/testsuite/gcc.dg/pr126569-1.c b/gcc/testsuite/gcc.dg/pr126569-1.c new file mode 100644 index 000000000000..5e2348c2ff19 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr126569-1.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-tree-dce -fno-tree-dse" } */ +/* PR tree-optimization/126569 */ + +int wx, qi, gw, ak; + +void +f (void) +{ + while (wx) + { + int k2 = ak; + ja: + *(int **) &k2 = &gw; + while (qi) + ++qi; + } + gw = 1; + goto ja; +} diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index 2ff26bfab73f..d63a47cc615a 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -3683,6 +3683,8 @@ cond_store_replacement_limited (basic_block middle_bb, basic_block join_bb, tree beforelhs = gimple_assign_lhs (vdef_before); /* Only allow the store to be right before the condition. */ if (gimple_bb (vdef_before) == cond_bb + /* This can't be a clobber */ + && !gimple_clobber_p (vdef_before) /* An exact match is only supported. FIXME: Allow for clique/base mismatch? */ && operand_equal_p (lhs, beforelhs))