On Dec 17, 2024, Alexandre Oliva <ol...@adacore.com> wrote:

> On Dec 17, 2024, Sam James <s...@gentoo.org> wrote:
>>> +/* { dg-options "-O3 -fno-tree-copy-prop -fno-tree-vrp" */

>> Missing closing '}'.

> Thanks, I've fixed that, and retested.

Here's the consolidated patch what I've just installed.


noncontiguous ifcombine: skip marking of non-SSA_NAMEs [PR117915]

When ifcombine_mark_ssa_name is called directly, rather than by
ifcombine_mark_ssa_name_walk, we need to check that name is an
SSA_NAME at the caller or in the function itself.  For convenience and
safety, I'm moving the checks from _walk to the implementation proper.


for  gcc/ChangeLog

        PR tree-optimization/117915
        * tree-ssa-ifcombine.cc (ifcombine_mark_ssa_name): Move
        preconditions from...
        (ifcombine_mark_ssa_name_walk): ... here.

for  gcc/testsuite/ChangeLog

        PR tree-optimization/117915
        * gcc.dg/pr117915.c: New.
---
 gcc/testsuite/gcc.dg/pr117915.c |    9 +++++++++
 gcc/tree-ssa-ifcombine.cc       |    5 ++---
 2 files changed, 11 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr117915.c

diff --git a/gcc/testsuite/gcc.dg/pr117915.c b/gcc/testsuite/gcc.dg/pr117915.c
new file mode 100644
index 0000000000000..5f9f4ecf4980f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr117915.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fno-tree-copy-prop -fno-tree-vrp" } */
+
+unsigned a;
+int b, c;
+int main() {
+  a = a & b || (c || b) | a;
+  return 0;
+}
diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc
index de8db2be5572a..02c2f5a29b561 100644
--- a/gcc/tree-ssa-ifcombine.cc
+++ b/gcc/tree-ssa-ifcombine.cc
@@ -475,7 +475,7 @@ update_profile_after_ifcombine (basic_block inner_cond_bb,
 static void
 ifcombine_mark_ssa_name (bitmap used, tree name, basic_block outer)
 {
-  if (SSA_NAME_IS_DEFAULT_DEF (name))
+  if (!name || TREE_CODE (name) != SSA_NAME || SSA_NAME_IS_DEFAULT_DEF (name))
     return;
 
   gimple *def = SSA_NAME_DEF_STMT (name);
@@ -502,8 +502,7 @@ ifcombine_mark_ssa_name_walk (tree *t, int *, void *data_)
 {
   ifcombine_mark_ssa_name_t *data = (ifcombine_mark_ssa_name_t *)data_;
 
-  if (*t && TREE_CODE (*t) == SSA_NAME)
-    ifcombine_mark_ssa_name (data->used, *t, data->outer);
+  ifcombine_mark_ssa_name (data->used, *t, data->outer);
 
   return NULL;
 }


-- 
Alexandre Oliva, happy hacker            https://FSFLA.org/blogs/lxo/
   Free Software Activist                   GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity
Excluding neuro-others for not behaving ""normal"" is *not* inclusive

Reply via email to