https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86489

--- Comment #3 from kugan at gcc dot gnu.org ---
(In reply to Richard Biener from comment #2)
>   gimple *phi = SSA_NAME_DEF_STMT (b_11);
>   if (gimple_code (phi) != GIMPLE_PHI
>       || (gimple_assign_lhs (and_stmt)
>           != gimple_phi_arg_def (phi, loop_latch_edge (loop)->dest_idx)))
>     return false;
> 
> this may fail if the PHI in question is not the correct one in which case
> it may not have the argument at the latch dest_idx.  Try first verifying
> that the loop latch destination is indeed gimple_bb (phi).

yes, thanks for spotting. I am testing the following patch:

diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index f6fa2f7..fbdf838 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -2555,6 +2555,7 @@ number_of_iterations_popcount (loop_p loop, edge exit,
    ... = PHI <b_5(2), b_6(3)>.  */
   gimple *phi = SSA_NAME_DEF_STMT (b_11);
   if (gimple_code (phi) != GIMPLE_PHI
+      || (gimple_bb (phi) != loop_latch_edge (loop)->dest)
       || (gimple_assign_lhs (and_stmt)
          != gimple_phi_arg_def (phi, loop_latch_edge (loop)->dest_idx)))
     return false;

is checking that there is argument at the latch dest_idx (argument count of
PHI) is still necessary?

Reply via email to