When a BIT_FIELD_REF lookup combined with a defining load RHS results in a wrongly typed result, try looking up or inserting a VIEW_CONVERT_EXPR to the desired type.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/121488 * tree-ssa-sccvn.cc (visit_nary_op): If the BIT_FIELD_REF result is of wrong type, try a VIEW_CONVERT_EXPR around it. * gcc.dg/tree-ssa/ssa-fre-108.c: New testcase. --- gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-108.c | 30 +++++++++++++++++++++ gcc/tree-ssa-sccvn.cc | 17 ++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-108.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-108.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-108.c new file mode 100644 index 00000000000..a13e9729e5f --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-108.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-O -Wno-psabi -fdump-tree-fre1" } */ + +#define vector16 __attribute__((vector_size(16))) +#define vector32 __attribute__((vector_size(32))) + +union u1 +{ + struct s1 + { + vector16 int hi; + vector16 int low; + }hilow; + vector32 int v; +}; + +vector16 float f(vector16 int a, vector16 int b) +{ + union u1 c; + c.hilow.hi = a; + c.hilow.low = b; + vector32 int d0 = c.v; + vector32 float d = (vector32 float)d0; + vector16 float e = __builtin_shufflevector (d, d, 0, 1, 2, 3); + vector16 float f = __builtin_shufflevector (d, d, 4, 5, 6, 7); + return e/f; +} + +/* { dg-final { scan-tree-dump-times "_\[0-9\]\+ = VIEW_CONVERT_EXPR" 2 "fre1" } } */ +/* { dg-final { scan-tree-dump-not "BIT_FIELD_REF" "fre1" } } */ diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 866d49c15a1..61d794d8407 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -5660,6 +5660,23 @@ visit_nary_op (tree lhs, gassign *stmt) if (result && useless_type_conversion_p (type, TREE_TYPE (result))) return set_ssa_val_to (lhs, result); + else if (result + && TYPE_SIZE (type) + && TYPE_SIZE (TREE_TYPE (result)) + && operand_equal_p (TYPE_SIZE (type), + TYPE_SIZE (TREE_TYPE (result)))) + { + gimple_match_op match_op (gimple_match_cond::UNCOND, + VIEW_CONVERT_EXPR, + type, result); + result = vn_nary_build_or_lookup (&match_op); + if (result) + { + bool changed = set_ssa_val_to (lhs, result); + vn_nary_op_insert_stmt (stmt, result); + return changed; + } + } } } } -- 2.43.0