]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ranger: Handle the theoretical case of GIMPLE_COND with one succ edge during expansio...
authorJakub Jelinek <jakub@redhat.com>
Wed, 11 Jun 2025 05:03:04 +0000 (07:03 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 11 Jun 2025 05:03:04 +0000 (07:03 +0200)
On Tue, Jun 10, 2025 at 10:51:25AM -0400, Andrew MacLeod wrote:
> Edge range should be fine, and really that assert doesnt really need to be
> there.
>
> Where the issue could arise is in gimple-range-fold.cc in
> fold_using_range::range_of_range_op()  where we see something like:
>
>          else if (is_a<gcond *> (s) && gimple_bb (s))
>             {
>               basic_block bb = gimple_bb (s);
>               edge e0 = EDGE_SUCC (bb, 0);
>               edge e1 = EDGE_SUCC (bb, 1);
>
>               if (!single_pred_p (e0->dest))
>                 e0 = NULL;
>               if (!single_pred_p (e1->dest))
>                 e1 = NULL;
>               src.register_outgoing_edges (as_a<gcond *> (s),
>                                            as_a <irange> (r), e0, e1);
>
> Althogh, now that I look at it, it doesn't need much adjustment, just the
> expectation that there are 2 edges.  I suppose EDGE_SUCC (bb, 1) cpould
> potentially trap if there is only one edge.   we'd just have to guard it and
> alloow for that case

This patch implements that.

2025-06-11  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/120434
* gimple-range-fold.cc: Include rtl.h.
(fold_using_range::range_of_range_op): Handle bb ending with
GIMPLE_COND during RTL expansion where there is only one succ
edge instead of two.

gcc/gimple-range-fold.cc

index aed5c7dc21eb05d0d4416178308bc957170c96b7..d18b37b33800e978e61121790153e1d4fd53ce22 100644 (file)
@@ -51,6 +51,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "sreal.h"
 #include "ipa-cp.h"
 #include "ipa-prop.h"
+#include "rtl.h"
 // Construct a fur_source, and set the m_query field.
 
 fur_source::fur_source (range_query *q)
@@ -778,11 +779,14 @@ fold_using_range::range_of_range_op (vrange &r,
            {
              basic_block bb = gimple_bb (s);
              edge e0 = EDGE_SUCC (bb, 0);
-             edge e1 = EDGE_SUCC (bb, 1);
+             /* During RTL expansion one of the edges can be removed
+                if expansion proves the jump is unconditional.  */
+             edge e1 = single_succ_p (bb) ? NULL : EDGE_SUCC (bb, 1);
 
+             gcc_checking_assert (e1 || currently_expanding_to_rtl);
              if (!single_pred_p (e0->dest))
                e0 = NULL;
-             if (!single_pred_p (e1->dest))
+             if (e1 && !single_pred_p (e1->dest))
                e1 = NULL;
              src.register_outgoing_edges (as_a<gcond *> (s),
                                           as_a <irange> (r), e0, e1);