PHI arguments are indexed by incoming edges.  function_instance::match
walked successor edges and could fail gimple_phi_arg_def_from_edge's
destination assertion during afdo_offline.

gcc/ChangeLog:

        * auto-profile.cc (function_instance::match): Walk predecessor edges
        for PHI arguments.

Regression tested on aarch64-linux-gnu with no new regressions

Signed-off-by: Kugan Vivekanandarajah <[email protected]>
---
 gcc/auto-profile.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/auto-profile.cc b/gcc/auto-profile.cc
index f4562d7f2f98..60f6b1ba480b 100644
--- a/gcc/auto-profile.cc
+++ b/gcc/auto-profile.cc
@@ -1764,7 +1764,8 @@ function_instance::match (cgraph_node *node,
          gcc_assert (!info);
          dump_stmt (phi, info, NULL, stack);
          counts.add (info);
-         for (edge e : bb->succs)
+         /* PHI arguments are indexed by incoming (predecessor) edges.  */
+         for (edge e : bb->preds)
            {
              location_t phi_loc
                = gimple_phi_arg_location_from_edge (phi, e);
-- 
2.34.1

Reply via email to