+2020-03-12 Richard Biener <rguenther@suse.de>
+
+ 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 <hongjiu.lu@intel.com>
PR target/89229
--- /dev/null
+/* { 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;
+}
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)