aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2024-01-31 11:28:50 +0100
committerRichard Biener <rguenther@suse.de>2024-01-31 12:29:19 +0100
commit724b64304ff5c8ac08a913509afd6fde38d7b767 (patch)
treea9919753900b9f3b5fa99781d921c6641169b86c
parentb59775b642bb2b1ecd2e6d52c988b9c432117bc8 (diff)
downloadgcc-724b64304ff5c8ac08a913509afd6fde38d7b767.zip
gcc-724b64304ff5c8ac08a913509afd6fde38d7b767.tar.gz
gcc-724b64304ff5c8ac08a913509afd6fde38d7b767.tar.bz2
tree-optimization/113630 - invalid code hoisting
The following avoids code hoisting (but also PRE insertion) of expressions that got value-numbered to another one that are not a valid replacement (but still compute the same value). This time because the access path ends in a structure with different size, meaning we consider a related access as not trapping because of the size of the base of the access. PR tree-optimization/113630 * tree-ssa-pre.cc (compute_avail): Avoid registering a reference with a representation with not matching base access size. * gcc.dg/torture/pr113630.c: New testcase.
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr113630.c4
-rw-r--r--gcc/tree-ssa-pre.cc14
2 files changed, 18 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/torture/pr113630.c b/gcc/testsuite/gcc.dg/torture/pr113630.c
new file mode 100644
index 0000000..72ebdef
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr113630.c
@@ -0,0 +1,4 @@
+/* { dg-do run { target { { *-*-linux* *-*-gnu* *-*-uclinux* } && mmap } } } */
+/* { dg-additional-options "-fno-strict-aliasing" } */
+
+#include "pr110799.c"
diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc
index e72592d..d29214d 100644
--- a/gcc/tree-ssa-pre.cc
+++ b/gcc/tree-ssa-pre.cc
@@ -4281,6 +4281,20 @@ compute_avail (function *fun)
= wide_int_to_tree (ptr_type_node,
wi::to_wide (ref1->op2));
}
+ /* We also need to make sure that the access path
+ ends in an access of the same size as otherwise
+ we might assume an access may not trap while in
+ fact it might. That's independent of whether
+ TBAA is in effect. */
+ if (TYPE_SIZE (ref1->type) != TYPE_SIZE (ref2->type)
+ && (! TYPE_SIZE (ref1->type)
+ || ! TYPE_SIZE (ref2->type)
+ || ! operand_equal_p (TYPE_SIZE (ref1->type),
+ TYPE_SIZE (ref2->type))))
+ {
+ operands.release ();
+ continue;
+ }
operands.release ();
result = get_or_alloc_expr_for_reference