Skip to content

Commit

Permalink
tree-optimization/94103 avoid CSE of loads with padding
Browse files Browse the repository at this point in the history
VN currently replaces a load of a 16 byte entity 128 bits of precision
(TImode) with the result of a load of a 16 byte entity with 80 bits of
mode precision (XFmode).  That will go downhill since if the padding
bits are not actually filled with memory contents those bits are
missing.

2020-03-12  Richard Biener  <[email protected]>

	PR tree-optimization/94103
	* tree-ssa-sccvn.c (visit_reference_op_load): Avoid type
	punning when the mode precision is not sufficient.

	* gcc.target/i386/pr94103.c: New testcase.
  • Loading branch information
rguenth committed Mar 12, 2020
1 parent fcc443b commit 1dc00a8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
6 changes: 6 additions & 0 deletions gcc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2020-03-12 Richard Biener <[email protected]>

PR tree-optimization/94103
* tree-ssa-sccvn.c (visit_reference_op_load): Avoid type
punning when the mode precision is not sufficient.

2020-03-12 H.J. Lu <[email protected]>

PR target/89229
Expand Down
5 changes: 5 additions & 0 deletions gcc/testsuite/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2020-03-12 Richard Biener <[email protected]>

PR tree-optimization/94103
* gcc.target/i386/pr94103.c: New testcase.

2020-03-12 Tobias Burnus <[email protected]>

PR middle-end/94120
Expand Down
17 changes: 17 additions & 0 deletions gcc/testsuite/gcc.target/i386/pr94103.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* { dg-do run { target lp64 } } */
/* { dg-options "-O3" } */

int main()
{
long double x;
unsigned long u[2] = {0xEEEEEEEEEEEEEEEEUL, 0xEEEEEEEEEEEEEEEEUL};
__builtin_memcpy(&x, &u, sizeof x);
__builtin_memcpy(&u, &x, sizeof u);
++*(unsigned char *)&x;
(void)-x;
__builtin_memcpy(&u, &x, sizeof u);
if (u[1] != 0xEEEEEEEEEEEEEEEEUL
|| u[0] != 0xEEEEEEEEEEEEEEEFUL)
__builtin_abort ();
return 0;
}
23 changes: 16 additions & 7 deletions gcc/tree-ssa-sccvn.c
Original file line number Diff line number Diff line change
Expand Up @@ -4899,13 +4899,22 @@ visit_reference_op_load (tree lhs, tree op, gimple *stmt)
if (result
&& !useless_type_conversion_p (TREE_TYPE (result), TREE_TYPE (op)))
{
/* We will be setting the value number of lhs to the value number
of VIEW_CONVERT_EXPR <TREE_TYPE (result)> (result).
So first simplify and lookup this expression to see if it
is already available. */
gimple_match_op res_op (gimple_match_cond::UNCOND,
VIEW_CONVERT_EXPR, TREE_TYPE (op), result);
result = vn_nary_build_or_lookup (&res_op);
/* Avoid the type punning in case the result mode has padding where
the op we lookup has not. */
if (maybe_lt (GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (result))),
GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (op)))))
result = NULL_TREE;
else
{
/* We will be setting the value number of lhs to the value number
of VIEW_CONVERT_EXPR <TREE_TYPE (result)> (result).
So first simplify and lookup this expression to see if it
is already available. */
gimple_match_op res_op (gimple_match_cond::UNCOND,
VIEW_CONVERT_EXPR, TREE_TYPE (op), result);
result = vn_nary_build_or_lookup (&res_op);
}

/* When building the conversion fails avoid inserting the reference
again. */
if (!result)
Expand Down

0 comments on commit 1dc00a8

Please sign in to comment.