]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix discriminators of gimple PHI arguments
authorJan Hubicka <hubicka@ucw.cz>
Tue, 30 Sep 2025 12:51:39 +0000 (14:51 +0200)
committerJan Hubicka <hubicka@ucw.cz>
Tue, 30 Sep 2025 12:51:39 +0000 (14:51 +0200)
while gimple PHI itself does not have locations, the arguments does and they
can be used to determine count of edges in CFG.  Assign_discriminators already
knows how to handle goto_locus and PHI args should be handled same way as
done by this patch.

Bootstrapped/regtested x86_64-linux, comitted.

gcc/ChangeLog:

* auto-profile.cc (function_instance::match): Sanity check
that gimple PHI has no location.
* tree-cfg.cc (assign_discriminators): Also remap locations
of gimple PHI arguments.

gcc/auto-profile.cc
gcc/tree-cfg.cc

index cf4d34c6435c3c100108ad7e55afe76d86171c24..0b0ab4a99f56cc17d29e9afb0dbe24c1a68aa2e0 100644 (file)
@@ -1371,10 +1371,13 @@ function_instance::match (cgraph_node *node,
          gphi *phi = gpi.phi ();
          inline_stack stack;
 
+         /* We do not assign discriminators to PHI nodes.
+            In case we every start using them, we wil need to
+            update tree-cfg.cc::assign_discriminators.  */
+         gcc_assert (gimple_location (phi) == UNKNOWN_LOCATION);
          get_inline_stack_in_node (gimple_location (phi), &stack, node);
          count_info *info = lookup_count (gimple_location (phi), stack, node);
-         if (info)
-           counts.add (info);
+         gcc_assert (!info);
          dump_stmt (phi, info, NULL, stack);
          counts.add (info);
          for (edge e : bb->succs)
index c3883446de8bae86c348c16de4f2c82c83d1a391..39aeb16f74e0e5a9aa6a7f896c4b698a78bfed7b 100644 (file)
@@ -1132,8 +1132,8 @@ assign_discriminators (void)
     {
       location_t prev_loc = UNKNOWN_LOCATION, prev_replacement = UNKNOWN_LOCATION;
       /* Traverse the basic block, if two function calls within a basic block
-       are mapped to the same line, assign a new discriminator because a call
-       stmt could be a split point of a basic block.  */
+        are mapped to the same line, assign a new discriminator because a call
+        stmt could be a split point of a basic block.  */
       for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
           !gsi_end_p (gsi); gsi_next (&gsi))
        {
@@ -1149,8 +1149,8 @@ assign_discriminators (void)
              prev_replacement = assign_discriminator (loc, bb_id, map);
              gimple_set_location (stmt, prev_replacement);
            }
-         /* Break basic blocks after each call.  This is requires so each
-            call site has unque discriminator.
+         /* Break basic blocks after each call.  This is required so each
+            call site has unique discriminator.
             More correctly, we can break after each statement that can possibly
             terinate execution of the basic block, but for auto-profile this
             precision is probably not useful.  */
@@ -1160,16 +1160,27 @@ assign_discriminators (void)
              bb_id++;
            }
        }
-      /* IF basic block has multiple sucessors, consdier every edge as a separate
-        block.  */
+      /* If basic block has multiple sucessors, consdier every edge as a
+        separate block.  */
       if (!single_succ_p (bb))
        bb_id++;
       for (edge e : bb->succs)
-       if (e->goto_locus != UNKNOWN_LOCATION)
-         {
+       {
+         if (e->goto_locus != UNKNOWN_LOCATION)
            e->goto_locus = assign_discriminator (e->goto_locus, bb_id, map);
-           bb_id++;
-         }
+         for (gphi_iterator gpi = gsi_start_phis (bb);
+              !gsi_end_p (gpi); gsi_next (&gpi))
+           {
+             gphi *phi = gpi.phi ();
+             location_t phi_loc
+               = gimple_phi_arg_location_from_edge (phi, e);
+             if (phi_loc == UNKNOWN_LOCATION)
+               continue;
+             gimple_phi_arg_set_location
+               (phi, e->dest_idx, assign_discriminator (phi_loc, bb_id, map));
+           }
+          bb_id++;
+       }
       bb_id++;
     }