public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Compare loop bounds in ipa-icf
@ 2024-05-29 15:10 Jan Hubicka
  0 siblings, 0 replies; only message in thread
From: Jan Hubicka @ 2024-05-29 15:10 UTC (permalink / raw)
  To: gcc-patches

Hi,
this testcase shows another poblem with missing comparators for metadata
in ICF. With value ranges available to loop optimizations during early
opts we can estimate number of iterations based on guarding condition that
can be split away by the fnsplit pass. This patch disables ICF when
number of iteraitons does not match.

Bootstrapped/regtesed x86_64-linux, will commit it shortly

gcc/ChangeLog:

	PR ipa/115277
	* ipa-icf-gimple.cc (func_checker::compare_loops):

gcc/testsuite/ChangeLog:

	* gcc.c-torture/compile/pr115277.c: New test.

diff --git a/gcc/ipa-icf-gimple.cc b/gcc/ipa-icf-gimple.cc
index c25eb24710f..4c3174b68b6 100644
--- a/gcc/ipa-icf-gimple.cc
+++ b/gcc/ipa-icf-gimple.cc
@@ -543,6 +543,10 @@ func_checker::compare_loops (basic_block bb1, basic_block bb2)
     return return_false_with_msg ("unroll");
   if (!compare_variable_decl (l1->simduid, l2->simduid))
     return return_false_with_msg ("simduid");
+  if ((l1->any_upper_bound != l2->any_upper_bound)
+      || (l1->any_upper_bound
+	  && (l1->nb_iterations_upper_bound != l2->nb_iterations_upper_bound)))
+    return return_false_with_msg ("nb_iterations_upper_bound");
 
   return true;
 }
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr115277.c b/gcc/testsuite/gcc.c-torture/compile/pr115277.c
new file mode 100644
index 00000000000..27449eb254f
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr115277.c
@@ -0,0 +1,28 @@
+int array[1000];
+void
+test (int a)
+{
+        if (__builtin_expect (a > 3, 1))
+                return;
+        for (int i = 0; i < a; i++)
+                array[i]=i;
+}
+void
+test2 (int a)
+{
+        if (__builtin_expect (a > 10, 1))
+                return;
+        for (int i = 0; i < a; i++)
+                array[i]=i;
+}
+int
+main()
+{
+        test(1);
+        test(2);
+        test(3);
+        test2(10);
+        if (array[9] != 9)
+                __builtin_abort ();
+        return 0;
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-05-29 15:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-29 15:10 Compare loop bounds in ipa-icf Jan Hubicka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).