Skip to content

Commit

Permalink
tree-optimization/113630 - invalid code hoisting
Browse files Browse the repository at this point in the history
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.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	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.
  • Loading branch information
rguenth authored and ouuleilei-bot committed Jan 31, 2024
1 parent c2d62cd commit 91bf143
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gcc/testsuite/gcc.dg/torture/pr113630.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* { dg-do run { target { { *-*-linux* *-*-gnu* *-*-uclinux* } && mmap } } } */
/* { dg-additional-options "-fno-strict-aliasing" } */

#include "pr110799.c"
14 changes: 14 additions & 0 deletions gcc/tree-ssa-pre.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4221,6 +4221,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
Expand Down

0 comments on commit 91bf143

Please sign in to comment.