[1/2] lim/cselim: Use lhs_could_trap_p directly instead of inline

Message ID 20260901235731.2884382-1-andrew.pinski@oss.qualcomm.com
State Committed
Commit e4d36a3fc154fe500bdfd7835ec9fe4d5e41fb42
Headers
Series [1/2] lim/cselim: Use lhs_could_trap_p directly instead of inline |

Commit Message

Andrea Pinski Sept. 1, 2026, 11:57 p.m. UTC
  Instead of calling tree_could_trap_p and then testing decl/string,
we can just use lhs_could_trap_p.
This will be used by the next patch to fix `this->a` accesses.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-loop-im.cc (can_sm_ref_p): Use lhs_could_trap_p.
	* tree-ssa-phiopt.cc (cond_store_replacement): Likewise.

Signed-off-by: Andrea Pinski <andrew.pinski@oss.qualcomm.com>
---
 gcc/tree-ssa-loop-im.cc | 12 ++----------
 gcc/tree-ssa-phiopt.cc  |  9 +--------
 2 files changed, 3 insertions(+), 18 deletions(-)
  

Comments

Jeff Law Sept. 2, 2026, 1:27 a.m. UTC | #1
On 9/1/26 5:57 PM, Andrea Pinski wrote:
> Instead of calling tree_could_trap_p and then testing decl/string,
> we can just use lhs_could_trap_p.
> This will be used by the next patch to fix `this->a` accesses.
>
> Bootstrapped and tested on x86_64-linux-gnu.
>
> gcc/ChangeLog:
>
> 	* tree-ssa-loop-im.cc (can_sm_ref_p): Use lhs_could_trap_p.
> 	* tree-ssa-phiopt.cc (cond_store_replacement): Likewise.
>
> Signed-off-by: Andrea Pinski <andrew.pinski@oss.qualcomm.com>
OK
jeff
  

Patch

diff --git a/gcc/tree-ssa-loop-im.cc b/gcc/tree-ssa-loop-im.cc
index 0dcf5982ec2..19523fb157a 100644
--- a/gcc/tree-ssa-loop-im.cc
+++ b/gcc/tree-ssa-loop-im.cc
@@ -3351,8 +3351,6 @@  ref_in_loop_hot_body::operator () (mem_ref_loc *loc)
 static bool
 can_sm_ref_p (class loop *loop, im_mem_ref *ref)
 {
-  tree base;
-
   /* Can't hoist unanalyzable refs.  */
   if (!MEM_ANALYZABLE (ref))
     return false;
@@ -3371,14 +3369,8 @@  can_sm_ref_p (class loop *loop, im_mem_ref *ref)
   if (tree_could_throw_p (ref->mem.ref))
     return false;
 
-  /* If it can trap, it must be always executed in LOOP.
-     Readonly memory locations may trap when storing to them, but
-     tree_could_trap_p is a predicate for rvalues, so check that
-     explicitly.  */
-  base = get_base_address (ref->mem.ref);
-  if ((tree_could_trap_p (ref->mem.ref)
-       || (DECL_P (base) && TREE_READONLY (base))
-       || TREE_CODE (base) == STRING_CST)
+  /* If the store can trap, it must be always executed in LOOP.  */
+  if (lhs_could_trap_p (ref->mem.ref)
       /* ???  We can at least use false here, allowing loads?  We
 	 are forcing conditional stores if the ref is not always
 	 stored to later anyway.  So this would only guard
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index 959ab66133d..6e17d21b58c 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -3289,15 +3289,8 @@  cond_store_replacement (basic_block middle_bb, basic_block join_bb, edge e0,
       /* If LHS is an access to a local variable without address-taken
 	 (or when we allow data races) and known not to trap, we could
 	 always safely move down the store.  */
-      tree base;
       if (ref_can_have_store_data_races (lhs)
-	  || tree_could_trap_p (lhs)
-	  /* tree_could_trap_p is a predicate for rvalues, so check
-	     for readonly memory explicitly.  */
-	  || ((base = get_base_address (lhs))
-	      && ((DECL_P (base)
-		   && TREE_READONLY (base))
-		  || TREE_CODE (base) == STRING_CST)))
+	  || lhs_could_trap_p (lhs))
 	return false;
     }