The following avoids building BIT_FIELD_REFs of reference trees that are unexpected by nonoverlapping_refs_since_match_p and while being there also those declared invalid by IL verification.
Bootstrapped on x86_64-unknown-linux-gnu with go enabled, testing in progress. PR tree-optimization/121454 * tree-ssa-sccvn.cc (visit_nary_op): Avoid unexpected BIT_FIELD_REFs. --- gcc/tree-ssa-sccvn.cc | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 1c113f848eb..ccd80806263 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -5643,15 +5643,24 @@ visit_nary_op (tree lhs, gassign *stmt) && vn_get_stmt_kind (ass) == VN_REFERENCE) { tree last_vuse = gimple_vuse (ass); - tree op = build3 (BIT_FIELD_REF, TREE_TYPE (rhs1), - gimple_assign_rhs1 (ass), - TREE_OPERAND (rhs1, 1), TREE_OPERAND (rhs1, 2)); - tree result = vn_reference_lookup (op, gimple_vuse (ass), - default_vn_walk_kind, - NULL, true, &last_vuse); - if (result - && useless_type_conversion_p (type, TREE_TYPE (result))) - return set_ssa_val_to (lhs, result); + tree op = gimple_assign_rhs1 (ass); + /* Avoid building invalid and unexpected refs. */ + if (TREE_CODE (op) != TARGET_MEM_REF + && TREE_CODE (op) != BIT_FIELD_REF + && TREE_CODE (op) != REALPART_EXPR + && TREE_CODE (op) != IMAGPART_EXPR) + { + tree op = build3 (BIT_FIELD_REF, TREE_TYPE (rhs1), + gimple_assign_rhs1 (ass), + TREE_OPERAND (rhs1, 1), + TREE_OPERAND (rhs1, 2)); + tree result = vn_reference_lookup (op, gimple_vuse (ass), + default_vn_walk_kind, + NULL, true, &last_vuse); + if (result + && useless_type_conversion_p (type, TREE_TYPE (result))) + return set_ssa_val_to (lhs, result); + } } } break; -- 2.43.0