Commit eda71a9e by Jakub Jelinek Committed by Jakub Jelinek

re PR tree-optimization/85257 (wrong code with -O -fno-tree-ccp and reading zeroed vector member)

	PR tree-optimization/85257
	* fold-const.c (native_encode_vector): If not all elts could fit
	and off is -1, return 0 rather than offset.
	* tree-ssa-sccvn.c (vn_reference_lookup_3): Pass
	(offseti - offset2) / BITS_PER_UNIT as 4th argument to
	native_encode_expr.  Verify len * BITS_PER_UNIT >= maxsizei.  Don't
	adjust buffer in native_interpret_expr call.

	* gcc.dg/pr85257.c: New test.

From-SVN: r259206
parent f1a0afe2
2018-04-07 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/85257
* fold-const.c (native_encode_vector): If not all elts could fit
and off is -1, return 0 rather than offset.
* tree-ssa-sccvn.c (vn_reference_lookup_3): Pass
(offseti - offset2) / BITS_PER_UNIT as 4th argument to
native_encode_expr. Verify len * BITS_PER_UNIT >= maxsizei. Don't
adjust buffer in native_interpret_expr call.
2018-04-07 Monk Chiang <sh.chiang04@gmail.com> 2018-04-07 Monk Chiang <sh.chiang04@gmail.com>
* config/nds32/constants.md (unspec_volatile_element): Add cache * config/nds32/constants.md (unspec_volatile_element): Add cache
......
...@@ -7307,7 +7307,7 @@ native_encode_vector (const_tree expr, unsigned char *ptr, int len, int off) ...@@ -7307,7 +7307,7 @@ native_encode_vector (const_tree expr, unsigned char *ptr, int len, int off)
return 0; return 0;
offset += res; offset += res;
if (offset >= len) if (offset >= len)
return offset; return (off == -1 && i < count - 1) ? 0 : offset;
if (off != -1) if (off != -1)
off = 0; off = 0;
} }
......
2018-04-07 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/85257
* gcc.dg/pr85257.c: New test.
2018-04-06 Eric Botcazou <ebotcazou@adacore.com> 2018-04-06 Eric Botcazou <ebotcazou@adacore.com>
* g++.dg/opt/pr85196.C: New test. * g++.dg/opt/pr85196.C: New test.
......
/* PR tree-optimization/85257 */
/* { dg-do run { target int128 } } */
/* { dg-options "-O2 -fno-tree-ccp" } */
typedef __int128 V __attribute__ ((__vector_size__ (16 * sizeof (__int128))));
__int128 __attribute__ ((noipa))
foo (void)
{
V v = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
return v[5];
}
int
main ()
{
if (foo () != 6)
__builtin_abort ();
return 0;
}
...@@ -2038,8 +2038,9 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_, ...@@ -2038,8 +2038,9 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_,
if (TREE_CODE (rhs) == SSA_NAME) if (TREE_CODE (rhs) == SSA_NAME)
rhs = SSA_VAL (rhs); rhs = SSA_VAL (rhs);
len = native_encode_expr (gimple_assign_rhs1 (def_stmt), len = native_encode_expr (gimple_assign_rhs1 (def_stmt),
buffer, sizeof (buffer)); buffer, sizeof (buffer),
if (len > 0) (offseti - offset2) / BITS_PER_UNIT);
if (len > 0 && len * BITS_PER_UNIT >= maxsizei)
{ {
tree type = vr->type; tree type = vr->type;
/* Make sure to interpret in a type that has a range /* Make sure to interpret in a type that has a range
...@@ -2048,10 +2049,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_, ...@@ -2048,10 +2049,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_,
&& maxsizei != TYPE_PRECISION (vr->type)) && maxsizei != TYPE_PRECISION (vr->type))
type = build_nonstandard_integer_type (maxsizei, type = build_nonstandard_integer_type (maxsizei,
TYPE_UNSIGNED (type)); TYPE_UNSIGNED (type));
tree val = native_interpret_expr (type, tree val = native_interpret_expr (type, buffer,
buffer
+ ((offseti - offset2)
/ BITS_PER_UNIT),
maxsizei / BITS_PER_UNIT); maxsizei / BITS_PER_UNIT);
/* If we chop off bits because the types precision doesn't /* If we chop off bits because the types precision doesn't
match the memory access size this is ok when optimizing match the memory access size this is ok when optimizing
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment