diff mbox series

[v2,4/5] lto: Stream has_unroll flag during LTO [PR116140]

Message ID Zs8AjM95S89S2BF7@arm.com
State New
Headers show
Series None | expand

Commit Message

Alex Coplan Aug. 28, 2024, 10:48 a.m. UTC
This is a v2 of:
https://gcc.gnu.org/pipermail/gcc-patches/2024-August/659969.html
this version just streams the flag as requested.

Bootstrapped/tested as a series on aarch64-linux-gnu (both with and
without LTO), OK for trunk?

Thanks,
Alex

-- >8 --

When #pragma GCC unroll is processed in
tree-cfg.cc:replace_loop_annotate_in_block, we set both the loop->unroll
field (which is currently streamed during LTO) but also the
cfun->has_unroll flag.

cfun->has_unroll, however, is not currently streamed during LTO.  This
patch fixes that.

Prior to this patch, loops marked with #pragma GCC unroll that would be
unrolled by RTL loop2_unroll in a non-LTO compilation didn't get
unrolled under LTO.

gcc/ChangeLog:

	PR libstdc++/116140
	* lto-streamer-in.cc (input_struct_function_base): Stream in
	fn->has_unroll.
	* lto-streamer-out.cc (output_struct_function_base): Stream out
	fn->has_unroll.

gcc/testsuite/ChangeLog:

	PR libstdc++/116140
	* g++.dg/ext/pragma-unroll-lambda-lto.C: New test.
---
 gcc/lto-streamer-in.cc                        |  1 +
 gcc/lto-streamer-out.cc                       |  1 +
 .../g++.dg/ext/pragma-unroll-lambda-lto.C     | 32 +++++++++++++++++++
 3 files changed, 34 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/ext/pragma-unroll-lambda-lto.C

Comments

Richard Biener Aug. 28, 2024, 10:55 a.m. UTC | #1
On Wed, Aug 28, 2024 at 12:49 PM Alex Coplan <alex.coplan@arm.com> wrote:
>
> This is a v2 of:
> https://gcc.gnu.org/pipermail/gcc-patches/2024-August/659969.html
> this version just streams the flag as requested.
>
> Bootstrapped/tested as a series on aarch64-linux-gnu (both with and
> without LTO), OK for trunk?

OK

> Thanks,
> Alex
>
> -- >8 --
>
> When #pragma GCC unroll is processed in
> tree-cfg.cc:replace_loop_annotate_in_block, we set both the loop->unroll
> field (which is currently streamed during LTO) but also the
> cfun->has_unroll flag.
>
> cfun->has_unroll, however, is not currently streamed during LTO.  This
> patch fixes that.
>
> Prior to this patch, loops marked with #pragma GCC unroll that would be
> unrolled by RTL loop2_unroll in a non-LTO compilation didn't get
> unrolled under LTO.
>
> gcc/ChangeLog:
>
>         PR libstdc++/116140
>         * lto-streamer-in.cc (input_struct_function_base): Stream in
>         fn->has_unroll.
>         * lto-streamer-out.cc (output_struct_function_base): Stream out
>         fn->has_unroll.
>
> gcc/testsuite/ChangeLog:
>
>         PR libstdc++/116140
>         * g++.dg/ext/pragma-unroll-lambda-lto.C: New test.
> ---
>  gcc/lto-streamer-in.cc                        |  1 +
>  gcc/lto-streamer-out.cc                       |  1 +
>  .../g++.dg/ext/pragma-unroll-lambda-lto.C     | 32 +++++++++++++++++++
>  3 files changed, 34 insertions(+)
>  create mode 100644 gcc/testsuite/g++.dg/ext/pragma-unroll-lambda-lto.C
>
diff mbox series

Patch

diff --git a/gcc/lto-streamer-in.cc b/gcc/lto-streamer-in.cc
index 64f75807328..9d0ec5d589c 100644
--- a/gcc/lto-streamer-in.cc
+++ b/gcc/lto-streamer-in.cc
@@ -1326,6 +1326,7 @@  input_struct_function_base (struct function *fn, class data_in *data_in,
   fn->has_force_vectorize_loops = bp_unpack_value (&bp, 1);
   fn->has_simduid_loops = bp_unpack_value (&bp, 1);
   fn->has_musttail = bp_unpack_value (&bp, 1);
+  fn->has_unroll = bp_unpack_value (&bp, 1);
   fn->assume_function = bp_unpack_value (&bp, 1);
   fn->va_list_fpr_size = bp_unpack_value (&bp, 8);
   fn->va_list_gpr_size = bp_unpack_value (&bp, 8);
diff --git a/gcc/lto-streamer-out.cc b/gcc/lto-streamer-out.cc
index 523d6dad221..52d0d737330 100644
--- a/gcc/lto-streamer-out.cc
+++ b/gcc/lto-streamer-out.cc
@@ -2283,6 +2283,7 @@  output_struct_function_base (struct output_block *ob, struct function *fn)
   bp_pack_value (&bp, fn->has_force_vectorize_loops, 1);
   bp_pack_value (&bp, fn->has_simduid_loops, 1);
   bp_pack_value (&bp, fn->has_musttail, 1);
+  bp_pack_value (&bp, fn->has_unroll, 1);
   bp_pack_value (&bp, fn->assume_function, 1);
   bp_pack_value (&bp, fn->va_list_fpr_size, 8);
   bp_pack_value (&bp, fn->va_list_gpr_size, 8);
diff --git a/gcc/testsuite/g++.dg/ext/pragma-unroll-lambda-lto.C b/gcc/testsuite/g++.dg/ext/pragma-unroll-lambda-lto.C
new file mode 100644
index 00000000000..144c4c32692
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/pragma-unroll-lambda-lto.C
@@ -0,0 +1,32 @@ 
+// { dg-do link { target c++11 } }
+// { dg-options "-O2 -flto -fdump-rtl-loop2_unroll" }
+
+#include <cstdlib>
+
+template<typename Iter, typename Pred>
+inline Iter
+my_find(Iter first, Iter last, Pred pred)
+{
+#pragma GCC unroll 4
+    while (first != last && !pred(*first))
+        ++first;
+    return first;
+}
+
+__attribute__((noipa))
+short *use_find(short *p)
+{
+    auto pred = [](short x) { return x == 42; };
+    return my_find(p, p + 1024, pred);
+}
+
+int main(void)
+{
+  short a[1024];
+  for (int i = 0; i < 1024; i++)
+    a[i] = rand ();
+
+  return use_find (a) - a;
+}
+
+// { dg-final { scan-ltrans-rtl-dump-times "Unrolled loop 3 times" 1 "loop2_unroll" } }