Skip to content

Commit 47cd060

Browse files
committed
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. (cherry picked from commit 724b643)
1 parent 4299355 commit 47cd060

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* { dg-do run { target { { *-*-linux* *-*-gnu* *-*-uclinux* } && mmap } } } */
2+
/* { dg-additional-options "-fno-strict-aliasing" } */
3+
4+
#include "pr110799.c"

gcc/tree-ssa-pre.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4224,6 +4224,20 @@ compute_avail (function *fun)
42244224
= wide_int_to_tree (ptr_type_node,
42254225
wi::to_wide (ref1->op2));
42264226
}
4227+
/* We also need to make sure that the access path
4228+
ends in an access of the same size as otherwise
4229+
we might assume an access may not trap while in
4230+
fact it might. That's independent of whether
4231+
TBAA is in effect. */
4232+
if (TYPE_SIZE (ref1->type) != TYPE_SIZE (ref2->type)
4233+
&& (! TYPE_SIZE (ref1->type)
4234+
|| ! TYPE_SIZE (ref2->type)
4235+
|| ! operand_equal_p (TYPE_SIZE (ref1->type),
4236+
TYPE_SIZE (ref2->type))))
4237+
{
4238+
operands.release ();
4239+
continue;
4240+
}
42274241
operands.release ();
42284242

42294243
result = get_or_alloc_expr_for_reference

0 commit comments

Comments
 (0)