Hi All, In PR116140 it was brought up that adding pragma GCC unroll in std::find makes it so that you can't use a larger unroll factor if you wanted to. This is because the value can't be overriden by the other unrolling flags such as -funroll-loops.
To know whether this should be possible to do or not this proposes an extension to the pragma GCC unroll with an argument to indicate if we can override the value or not. * requested: means that we cannot override the value. If we can unroll the unroll, we must unroll by the amount specified. * preferred: means that we can override the value. Effectively we ignore the count if -funrol-loops is specified and leave it up to costing and the max unroll parameters. The default is "requested" to match what it does today. Bootstrapped Regtested on aarch64-none-linux-gnu, arm-none-linux-gnueabihf, x86_64-pc-linux-gnu -m32, -m64 and no issues. Ok for master? Thanks, Tamar gcc/ChangeLog: PR libstdc++/116140 * doc/extend.texi (pragma GCC unroll): Document extension. --- diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 40ccf22b29f4316928f905ec2c978fdaf30a55ec..e87a3c271f8420d8fd175823b5bb655f76c89afe 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -10384,14 +10384,19 @@ void foo (int n, int *a, int *b, int *c) @} @end smallexample -@cindex pragma GCC unroll @var{n} -@item #pragma GCC unroll @var{n} +@cindex pragma GCC unroll @var{n} [@var{requested|preferred}] +@item #pragma GCC unroll @var{n} [@var{requested|preferred}] You can use this pragma to control how many times a loop should be unrolled. It must be placed immediately before a @code{for}, @code{while} or @code{do} loop or a @code{#pragma GCC ivdep}, and applies only to the loop that follows. @var{n} is an integer constant expression specifying the unrolling factor. The values of @math{0} and @math{1} block any unrolling of the loop. +The optional argument indicates whether the user can still override the amount. +When the optional argument is @var{requested} (default) the loop will always be +unrolled @var{n} times regardless of any commandline arguments. +When the option is @var{preferred} then the user is allowed to override the +unroll amount through commandline options. @end table --
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 40ccf22b29f4316928f905ec2c978fdaf30a55ec..e87a3c271f8420d8fd175823b5bb655f76c89afe 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -10384,14 +10384,19 @@ void foo (int n, int *a, int *b, int *c) @} @end smallexample -@cindex pragma GCC unroll @var{n} -@item #pragma GCC unroll @var{n} +@cindex pragma GCC unroll @var{n} [@var{requested|preferred}] +@item #pragma GCC unroll @var{n} [@var{requested|preferred}] You can use this pragma to control how many times a loop should be unrolled. It must be placed immediately before a @code{for}, @code{while} or @code{do} loop or a @code{#pragma GCC ivdep}, and applies only to the loop that follows. @var{n} is an integer constant expression specifying the unrolling factor. The values of @math{0} and @math{1} block any unrolling of the loop. +The optional argument indicates whether the user can still override the amount. +When the optional argument is @var{requested} (default) the loop will always be +unrolled @var{n} times regardless of any commandline arguments. +When the option is @var{preferred} then the user is allowed to override the +unroll amount through commandline options. @end table