> On Fri, Jul 28, 2023 at 9:58 AM Jan Hubicka via Gcc-patches > <gcc-patches@gcc.gnu.org> wrote: > > > > Hi, > > this patch fixes profile update in the first case of loop splitting. > > The pass still gives up on very basic testcases: > > > > __attribute__ ((noinline,noipa)) > > void test1 (int n) > > { > > if (n <= 0 || n > 100000) > > return; > > for (int i = 0; i <= n; i++) > > { > > if (i < n) > > do_something (); > > if (a[i]) > > do_something2(); > > } > > } > > Here I needed to do the conditoinal that enforces sane value range of n. > > The reason is that it gives up on: > > !number_of_iterations_exit (loop1, exit1, &niter, false, true) > > and without the conditonal we get assumption that n>=0 and not INT_MAX. > > I think from overflow we shold derive that INT_MAX test is not needed and > > since > > the loop does nothing for n<0 it is also just an paranoia. > > I only get n != 2147483647 (loop header copying does the n >= 0). Indeed > this test looks odd. It's because we turn i <= n into i < n + 1 and analyze > that (our canonical test is LT_EXPR), for this to work n may not be INT_MAX.
Yep, I can't think on how that can disturb loop splitting. The loop above is similar to one in hmmer so people do loops like that. We should be able to use the fact that i can not overflow to get rid of this assumtion, but I am not that famililar with that code... I think it would help elsewhere too? > > In principle it could just look at the scalar evolution for the IV in > the exit test. > Aka use simple_iv () and check ->no_overflow? Yep, I tink that should be enough. It uses simple_iv to analyze the in-loop conditionals. I will look into that. Honza