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

Aldy Hernandez <aldyh at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |aldyh at gcc dot gnu.org

--- Comment #14 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
(In reply to rguent...@suse.de from comment #13)
> On Wed, 10 Nov 2021, aldyh at gcc dot gnu.org wrote:

> > So, we could fix this either by relaxing the restriction with your patch, 
> > or by
> > teaching should_duplicate_loop_header_p that an incoming edge can resolve 
> > the
> > conditional in the header?
> 
> Yes.  I think the latter would be cleaner but the former has an (ugly)
> patch already (see above).  Not sure how difficult it is to do the latter,

The idea is actually straightforward.  Assuming I have the right edge, this
would get us the result:

@@ -60,6 +63,24 @@ should_duplicate_loop_header_p (basic_block header, class
loop *loop,
   if (optimize_loop_for_size_p (loop)
       && !loop->force_vectorize)
     {
+      if (gcond *last = safe_dyn_cast <gcond *> (last_stmt (header)))
+       {
+         gimple_ranger ranger;
+         int_range<2> r;
+         path_range_query path (ranger, /*resolve=*/true);
+         auto_vec<basic_block> bbs (2);
+         edge e = loop_preheader_edge (loop);
+
+         gcc_checking_assert (e->dest == header);
+         bbs.quick_push (header);
+         bbs.quick_push (e->src);
+         bitmap imports = ranger.gori ().imports (header);
+         path.compute_ranges (bbs, imports);
+         path.range_of_stmt (r, last);
+         r.dump ();
+         fputc ('\n', stderr);
+       }
+
       if (dump_file && (dump_flags & TDF_DETAILS))
        fprintf (dump_file,

$ ./cc1 a.c -quiet -I/tmp -Os
_Bool [1, 1]

which means the final conditional in the path evaluates to true.

I'll come up with an actual patch.  The gori imports stuff can be hidden away
in the path solver and we should have a ranger available for the entire pass,
not instantiate a new one every time.

> you are likely 10x quicker than me to figure that out ;)

Well, only because you did all the hard work here :).

Reply via email to