]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/121454 - ICE building libgo
authorRichard Biener <rguenther@suse.de>
Fri, 8 Aug 2025 06:57:58 +0000 (08:57 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 8 Aug 2025 09:17:40 +0000 (11:17 +0200)
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.

PR tree-optimization/121454
* tree-ssa-sccvn.cc (visit_nary_op): Avoid unexpected
BIT_FIELD_REFs.

gcc/tree-ssa-sccvn.cc

index 1c113f848ebb4b48929f2e14f9623b42ebbba735..ccd80806263bb8cdc0374b139364345080eb71d1 100644 (file)
@@ -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;