https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98138

--- Comment #19 from Kewen Lin <linkw at gcc dot gnu.org> ---
(In reply to rguent...@suse.de from comment #18)
> I think this misses a :s on the negate_expr_p, but I'm not sure this
> "works", so eventually && single_use (@1), given the original expression
> doesn't go away.

Thanks for the hints!  I verified that :s isn't supported there, it seems still
a good thing to make this matching if there are multiple uses but all are under
the same form (rhs_code and operand index are the same) since the original
expression are able to be eliminated? Should we introduce a stricter check for
this like below?

+static inline bool
+all_same_assign_form_uses (const_tree t)
+{
+  if (TREE_CODE (t) != SSA_NAME)
+    return true;
+
+  /* Inline return has_zero_uses (t) || has_single_use (t);  */
+  const ssa_use_operand_t *const head = &(SSA_NAME_IMM_USE_NODE (t));
+  const ssa_use_operand_t *ptr;
+  bool seen = false;
+  unsigned int op_index = 0;
+  tree_code rhs_code = ERROR_MARK;
+
+  for (ptr = head->next; ptr != head; ptr = ptr->next)
+    {
+      gimple *use_stmt = USE_STMT (ptr);
+      if (use_stmt)
+        {
+          if (is_gimple_debug (use_stmt))
+            continue;
+          if (!is_gimple_assign (use_stmt))
+            return false;
+          if (seen)
+            {
+              if (gimple_assign_rhs_code (use_stmt) != rhs_code)
+                return false;
+              if ((ptr->use - gimple_ops (use_stmt)) != op_index)
+                return false;
+            }
+          else
+            {
+              seen = true;
+              rhs_code = gimple_assign_rhs_code (use_stmt);
+              op_index = ptr->use - gimple_ops (use_stmt);
+            }
+        }
+    }
+  return true;
+}

Reply via email to