https://gcc.gnu.org/g:e4d36a3fc154fe500bdfd7835ec9fe4d5e41fb42
commit r17-3840-ge4d36a3fc154fe500bdfd7835ec9fe4d5e41fb42 Author: Andrea Pinski <[email protected]> Date: Tue Sep 1 14:23:44 2026 -0700 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 <[email protected]> Diff: --- gcc/tree-ssa-loop-im.cc | 12 ++---------- gcc/tree-ssa-phiopt.cc | 9 +-------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/gcc/tree-ssa-loop-im.cc b/gcc/tree-ssa-loop-im.cc index 0dcf5982ec2d..19523fb157a5 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 959ab66133db..6e17d21b58c0 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; }
