lim/cselim: Use lhs_could_trap_p directly instead of inline

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>
diff --git a/gcc/tree-ssa-loop-im.cc b/gcc/tree-ssa-loop-im.cc
index 0dcf598..19523fb 100644
--- a/gcc/tree-ssa-loop-im.cc
+++ b/gcc/tree-ssa-loop-im.cc
@@ -3351,8 +3351,6 @@
 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 @@
   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 959ab66..6e17d21 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -3289,15 +3289,8 @@
       /* 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;
     }