From: Jan Hubicka Date: Tue, 30 Sep 2025 12:51:39 +0000 (+0200) Subject: Fix discriminators of gimple PHI arguments X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ab015c2a0ce2c33f1963bf47d2d437affdf264ff;p=thirdparty%2Fgcc.git Fix discriminators of gimple PHI arguments 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. --- diff --git a/gcc/auto-profile.cc b/gcc/auto-profile.cc index cf4d34c6435..0b0ab4a99f5 100644 --- a/gcc/auto-profile.cc +++ b/gcc/auto-profile.cc @@ -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) diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index c3883446de8..39aeb16f74e 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -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++; }