diff options
author | Richard Biener <rguenther@suse.de> | 2025-05-08 10:05:42 +0200 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2025-05-11 10:54:02 +0200 |
commit | 856c493db1d5e2fa9377f4a0c438afbcaf6c7e01 (patch) | |
tree | 0699e8d8aed4178181ceb1d0a3af172d6ab3b053 | |
parent | 7b38bab21a126512c17c8084ad78b6bf75fc1437 (diff) | |
download | gcc-856c493db1d5e2fa9377f4a0c438afbcaf6c7e01.zip gcc-856c493db1d5e2fa9377f4a0c438afbcaf6c7e01.tar.gz gcc-856c493db1d5e2fa9377f4a0c438afbcaf6c7e01.tar.bz2 |
tree-optimization/120043 - bogus conditional store elimination
The following fixes conditional store elimination to properly
check for conditional stores to readonly memory which we can
obviously not store to unconditionally. The tree_could_trap_p
predicate used is only considering rvalues and the chosen
approach mimics that of loop store motion.
PR tree-optimization/120043
* tree-ssa-phiopt.cc (cond_store_replacement): Check
whether the store is to readonly memory.
* gcc.dg/torture/pr120043.c: New testcase.
(cherry picked from commit 93586e5d51188bf71f4f8fae4ee94ff631740f24)
-rw-r--r-- | gcc/testsuite/gcc.dg/torture/pr120043.c | 10 | ||||
-rw-r--r-- | gcc/tree-ssa-phiopt.cc | 8 |
2 files changed, 17 insertions, 1 deletions
diff --git a/gcc/testsuite/gcc.dg/torture/pr120043.c b/gcc/testsuite/gcc.dg/torture/pr120043.c new file mode 100644 index 0000000..ae27468 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr120043.c @@ -0,0 +1,10 @@ +/* { dg-do run } */ +/* { dg-additional-options "-fallow-store-data-races" } */ + +const int a; +int *b; +int main() +{ + &a != b || (*b = 1); + return 0; +} diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index a194bf6..7f3390b 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -3559,8 +3559,14 @@ cond_store_replacement (basic_block middle_bb, basic_block join_bb, /* 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 (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))) return false; } |