[SPR] i386: Only enable small loop unrolling in backend [PR 107692]
Followed by the discussion in pr107692, -munroll-only-small-loops
Does not turns on/off -funroll-loops, and current check in
pass_rtl_unroll_loops::gate would cause -fno-unroll-loops do not take
effect. Revert the change about targetm.loop_unroll_adjust and apply
the backend option change to strictly follow the rule that
-funroll-loops takes full control of loop unrolling, and
munroll-only-small-loops just change its behavior to unroll small size
loops.
gcc/ChangeLog:
PR target/107692
* common/config/i386/i386-common.cc (ix86_optimization_table):
Enable loop unroll O2, disable -fweb and -frename-registers
by default.
* config/i386/i386-options.cc
(ix86_override_options_after_change):
Disable small loop unroll when funroll-loops enabled, reset
cunroll_grow_size when it is not explicitly enabled.
(ix86_option_override_internal): Call
ix86_override_options_after_change instead of calling
ix86_recompute_optlev_based_flags and ix86_default_align
separately.
* config/i386/i386.cc (ix86_loop_unroll_adjust): Adjust unroll
factor if -munroll-only-small-loops enabled.
* loop-init.cc (pass_rtl_unroll_loops::gate): Do not enable
loop unrolling for -O2-speed.
(pass_rtl_unroll_loops::execute): Rmove
targetm.loop_unroll_adjust check.
gcc/testsuite/ChangeLog:
PR target/107692
* gcc.dg/guality/loop-1.c: Remove additional option for ia32.
* gcc.target/i386/pr86270.c: Add -fno-unroll-loops.
* gcc.target/i386/pr93002.c: Likewise.
url:https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=8caf155a3d6e23e47bf55068ad23c23d4655a054
This commit is contained in:
parent
70bccee5fa
commit
5603bb17fc
231
0006-i386-Only-enable-small-loop-unrolling-in-backend-PR-.patch
Normal file
231
0006-i386-Only-enable-small-loop-unrolling-in-backend-PR-.patch
Normal file
@ -0,0 +1,231 @@
|
||||
From 5c07825ca0c34dd946a8cfc0325ddb452d7f65c5 Mon Sep 17 00:00:00 2001
|
||||
From: Hongyu Wang <hongyu.wang@intel.com>
|
||||
Date: Sat, 19 Nov 2022 09:38:00 +0800
|
||||
Subject: [PATCH 5/5] i386: Only enable small loop unrolling in backend [PR
|
||||
107692]
|
||||
|
||||
Followed by the discussion in pr107692, -munroll-only-small-loops
|
||||
Does not turns on/off -funroll-loops, and current check in
|
||||
pass_rtl_unroll_loops::gate would cause -fno-unroll-loops do not take
|
||||
effect. Revert the change about targetm.loop_unroll_adjust and apply
|
||||
the backend option change to strictly follow the rule that
|
||||
-funroll-loops takes full control of loop unrolling, and
|
||||
munroll-only-small-loops just change its behavior to unroll small size
|
||||
loops.
|
||||
|
||||
gcc/ChangeLog:
|
||||
|
||||
PR target/107692
|
||||
* common/config/i386/i386-common.cc (ix86_optimization_table):
|
||||
Enable loop unroll O2, disable -fweb and -frename-registers
|
||||
by default.
|
||||
* config/i386/i386-options.cc
|
||||
(ix86_override_options_after_change):
|
||||
Disable small loop unroll when funroll-loops enabled, reset
|
||||
cunroll_grow_size when it is not explicitly enabled.
|
||||
(ix86_option_override_internal): Call
|
||||
ix86_override_options_after_change instead of calling
|
||||
ix86_recompute_optlev_based_flags and ix86_default_align
|
||||
separately.
|
||||
* config/i386/i386.cc (ix86_loop_unroll_adjust): Adjust unroll
|
||||
factor if -munroll-only-small-loops enabled.
|
||||
* loop-init.cc (pass_rtl_unroll_loops::gate): Do not enable
|
||||
loop unrolling for -O2-speed.
|
||||
(pass_rtl_unroll_loops::execute): Rmove
|
||||
targetm.loop_unroll_adjust check.
|
||||
|
||||
gcc/testsuite/ChangeLog:
|
||||
|
||||
PR target/107692
|
||||
* gcc.dg/guality/loop-1.c: Remove additional option for ia32.
|
||||
* gcc.target/i386/pr86270.c: Add -fno-unroll-loops.
|
||||
* gcc.target/i386/pr93002.c: Likewise.
|
||||
---
|
||||
gcc/common/config/i386/i386-common.cc | 8 ++++++
|
||||
gcc/config/i386/i386-options.cc | 34 ++++++++++++++++++++++---
|
||||
gcc/config/i386/i386.cc | 18 ++++---------
|
||||
gcc/loop-init.cc | 11 +++-----
|
||||
gcc/testsuite/gcc.dg/guality/loop-1.c | 2 --
|
||||
gcc/testsuite/gcc.target/i386/pr86270.c | 2 +-
|
||||
gcc/testsuite/gcc.target/i386/pr93002.c | 2 +-
|
||||
7 files changed, 49 insertions(+), 28 deletions(-)
|
||||
|
||||
diff --git a/gcc/common/config/i386/i386-common.cc b/gcc/common/config/i386/i386-common.cc
|
||||
index e1c1fb07d8a..5e777849f91 100644
|
||||
--- a/gcc/common/config/i386/i386-common.cc
|
||||
+++ b/gcc/common/config/i386/i386-common.cc
|
||||
@@ -1687,7 +1687,15 @@ static const struct default_options ix86_option_optimization_table[] =
|
||||
/* The STC algorithm produces the smallest code at -Os, for x86. */
|
||||
{ OPT_LEVELS_2_PLUS, OPT_freorder_blocks_algorithm_, NULL,
|
||||
REORDER_BLOCKS_ALGORITHM_STC },
|
||||
+
|
||||
+ /* Turn on -funroll-loops with -munroll-only-small-loops to enable small
|
||||
+ loop unrolling at -O2. */
|
||||
+ { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_funroll_loops, NULL, 1 },
|
||||
{ OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_munroll_only_small_loops, NULL, 1 },
|
||||
+ /* Turns off -frename-registers and -fweb which are enabled by
|
||||
+ funroll-loops. */
|
||||
+ { OPT_LEVELS_ALL, OPT_frename_registers, NULL, 0 },
|
||||
+ { OPT_LEVELS_ALL, OPT_fweb, NULL, 0 },
|
||||
/* Turn off -fschedule-insns by default. It tends to make the
|
||||
problem with not enough registers even worse. */
|
||||
{ OPT_LEVELS_ALL, OPT_fschedule_insns, NULL, 0 },
|
||||
diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc
|
||||
index 32cc58a764b..b853ff55825 100644
|
||||
--- a/gcc/config/i386/i386-options.cc
|
||||
+++ b/gcc/config/i386/i386-options.cc
|
||||
@@ -1816,8 +1816,37 @@ ix86_recompute_optlev_based_flags (struct gcc_options *opts,
|
||||
void
|
||||
ix86_override_options_after_change (void)
|
||||
{
|
||||
+ /* Default align_* from the processor table. */
|
||||
ix86_default_align (&global_options);
|
||||
+
|
||||
ix86_recompute_optlev_based_flags (&global_options, &global_options_set);
|
||||
+
|
||||
+ /* Disable unrolling small loops when there's explicit
|
||||
+ -f{,no}unroll-loop. */
|
||||
+ if ((OPTION_SET_P (flag_unroll_loops))
|
||||
+ || (OPTION_SET_P (flag_unroll_all_loops)
|
||||
+ && flag_unroll_all_loops))
|
||||
+ {
|
||||
+ if (!OPTION_SET_P (ix86_unroll_only_small_loops))
|
||||
+ ix86_unroll_only_small_loops = 0;
|
||||
+ /* Re-enable -frename-registers and -fweb if funroll-loops
|
||||
+ enabled. */
|
||||
+ if (!OPTION_SET_P (flag_web))
|
||||
+ flag_web = flag_unroll_loops;
|
||||
+ if (!OPTION_SET_P (flag_rename_registers))
|
||||
+ flag_rename_registers = flag_unroll_loops;
|
||||
+ /* -fcunroll-grow-size default follws -f[no]-unroll-loops. */
|
||||
+ if (!OPTION_SET_P (flag_cunroll_grow_size))
|
||||
+ flag_cunroll_grow_size = flag_unroll_loops
|
||||
+ || flag_peel_loops
|
||||
+ || optimize >= 3;
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ if (!OPTION_SET_P (flag_cunroll_grow_size))
|
||||
+ flag_cunroll_grow_size = flag_peel_loops || optimize >= 3;
|
||||
+ }
|
||||
+
|
||||
}
|
||||
|
||||
/* Clear stack slot assignments remembered from previous functions.
|
||||
@@ -2329,7 +2358,7 @@ ix86_option_override_internal (bool main_args_p,
|
||||
|
||||
set_ix86_tune_features (opts, ix86_tune, opts->x_ix86_dump_tunes);
|
||||
|
||||
- ix86_recompute_optlev_based_flags (opts, opts_set);
|
||||
+ ix86_override_options_after_change ();
|
||||
|
||||
ix86_tune_cost = processor_cost_table[ix86_tune];
|
||||
/* TODO: ix86_cost should be chosen at instruction or function granuality
|
||||
@@ -2360,9 +2389,6 @@ ix86_option_override_internal (bool main_args_p,
|
||||
|| TARGET_64BIT_P (opts->x_ix86_isa_flags))
|
||||
opts->x_ix86_regparm = REGPARM_MAX;
|
||||
|
||||
- /* Default align_* from the processor table. */
|
||||
- ix86_default_align (opts);
|
||||
-
|
||||
/* Provide default for -mbranch-cost= value. */
|
||||
SET_OPTION_IF_UNSET (opts, opts_set, ix86_branch_cost,
|
||||
ix86_tune_cost->branch_cost);
|
||||
diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
|
||||
index 39b2468799c..000415c0e2e 100644
|
||||
--- a/gcc/config/i386/i386.cc
|
||||
+++ b/gcc/config/i386/i386.cc
|
||||
@@ -23563,20 +23563,12 @@ ix86_loop_unroll_adjust (unsigned nunroll, class loop *loop)
|
||||
|
||||
/* Unroll small size loop when unroll factor is not explicitly
|
||||
specified. */
|
||||
- if (!(flag_unroll_loops
|
||||
- || flag_unroll_all_loops
|
||||
- || loop->unroll))
|
||||
+ if (ix86_unroll_only_small_loops && !loop->unroll)
|
||||
{
|
||||
- nunroll = 1;
|
||||
-
|
||||
- /* Any explicit -f{no-}unroll-{all-}loops turns off
|
||||
- -munroll-only-small-loops. */
|
||||
- if (ix86_unroll_only_small_loops
|
||||
- && !OPTION_SET_P (flag_unroll_loops)
|
||||
- && loop->ninsns <= ix86_cost->small_unroll_ninsns)
|
||||
- nunroll = ix86_cost->small_unroll_factor;
|
||||
-
|
||||
- return nunroll;
|
||||
+ if (loop->ninsns <= ix86_cost->small_unroll_ninsns)
|
||||
+ return MIN (nunroll, ix86_cost->small_unroll_factor);
|
||||
+ else
|
||||
+ return 1;
|
||||
}
|
||||
|
||||
if (!TARGET_ADJUST_UNROLL)
|
||||
diff --git a/gcc/loop-init.cc b/gcc/loop-init.cc
|
||||
index 84336865ef7..ed1b2f6ebab 100644
|
||||
--- a/gcc/loop-init.cc
|
||||
+++ b/gcc/loop-init.cc
|
||||
@@ -565,12 +565,10 @@ public:
|
||||
{}
|
||||
|
||||
/* opt_pass methods: */
|
||||
- virtual bool gate (function * fun)
|
||||
+ virtual bool gate (function *)
|
||||
{
|
||||
- return (flag_unroll_loops || flag_unroll_all_loops || cfun->has_unroll
|
||||
- || (targetm.loop_unroll_adjust
|
||||
- && optimize >= 2
|
||||
- && optimize_function_for_speed_p (fun)));
|
||||
+ return (flag_unroll_loops || flag_unroll_all_loops
|
||||
+ || cfun->has_unroll);
|
||||
}
|
||||
|
||||
virtual unsigned int execute (function *);
|
||||
@@ -586,8 +584,7 @@ pass_rtl_unroll_loops::execute (function *fun)
|
||||
if (dump_file)
|
||||
df_dump (dump_file);
|
||||
|
||||
- if (flag_unroll_loops
|
||||
- || targetm.loop_unroll_adjust)
|
||||
+ if (flag_unroll_loops)
|
||||
flags |= UAP_UNROLL;
|
||||
if (flag_unroll_all_loops)
|
||||
flags |= UAP_UNROLL_ALL;
|
||||
diff --git a/gcc/testsuite/gcc.dg/guality/loop-1.c b/gcc/testsuite/gcc.dg/guality/loop-1.c
|
||||
index a32ea445a3f..1b1f6d32271 100644
|
||||
--- a/gcc/testsuite/gcc.dg/guality/loop-1.c
|
||||
+++ b/gcc/testsuite/gcc.dg/guality/loop-1.c
|
||||
@@ -1,7 +1,5 @@
|
||||
/* { dg-do run } */
|
||||
/* { dg-options "-fno-tree-scev-cprop -fno-tree-vectorize -g" } */
|
||||
-/* { dg-additional-options "-mno-unroll-only-small-loops" { target ia32 } } */
|
||||
-
|
||||
|
||||
#include "../nop.h"
|
||||
|
||||
diff --git a/gcc/testsuite/gcc.target/i386/pr86270.c b/gcc/testsuite/gcc.target/i386/pr86270.c
|
||||
index cbc9fbb0450..98b012caf23 100644
|
||||
--- a/gcc/testsuite/gcc.target/i386/pr86270.c
|
||||
+++ b/gcc/testsuite/gcc.target/i386/pr86270.c
|
||||
@@ -1,5 +1,5 @@
|
||||
/* { dg-do compile } */
|
||||
-/* { dg-options "-O2 -mno-unroll-only-small-loops" } */
|
||||
+/* { dg-options "-O2 -fno-unroll-loops" } */
|
||||
|
||||
int *a;
|
||||
long len;
|
||||
diff --git a/gcc/testsuite/gcc.target/i386/pr93002.c b/gcc/testsuite/gcc.target/i386/pr93002.c
|
||||
index f75a847f75d..7e2d869e17b 100644
|
||||
--- a/gcc/testsuite/gcc.target/i386/pr93002.c
|
||||
+++ b/gcc/testsuite/gcc.target/i386/pr93002.c
|
||||
@@ -1,6 +1,6 @@
|
||||
/* PR target/93002 */
|
||||
/* { dg-do compile } */
|
||||
-/* { dg-options "-O2 -mno-unroll-only-small-loops" } */
|
||||
+/* { dg-options "-O2 -fno-unroll-loops" } */
|
||||
/* { dg-final { scan-assembler-not "cmp\[^\n\r]*-1" } } */
|
||||
|
||||
volatile int sink;
|
||||
--
|
||||
2.18.2
|
||||
|
||||
@ -85,7 +85,7 @@
|
||||
Summary: Various compilers (C, C++, Objective-C, ...)
|
||||
Name: %{?scl_prefix}gcc%{gcc_ver}
|
||||
Version: 12.2.1
|
||||
Release: 12
|
||||
Release: 13
|
||||
# libgcc, libgfortran, libgomp, libstdc++ and crtstuff have
|
||||
# GCC Runtime Exception.
|
||||
License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
|
||||
@ -138,6 +138,7 @@ Patch1: 0002-i386-Add-syscall-to-enable-AMX-for-latest-kernels.patch
|
||||
Patch2: 0003-Remove-AVX512_VP2INTERSECT-from-PTA_SAPPHIRERAPIDS.patch
|
||||
Patch3: 0004-Add-attribute-hot-judgement-for-INLINE_HINT_known_ho.patch
|
||||
Patch4: 0005-Enable-small-loop-unrolling-for-O2.patch
|
||||
Patch5: 0006-i386-Only-enable-small-loop-unrolling-in-backend-PR-.patch
|
||||
|
||||
|
||||
# On ARM EABI systems, we do want -gnueabi to be part of the
|
||||
@ -600,6 +601,7 @@ not stable, so plugins must be rebuilt any time GCC is updated.
|
||||
%patch2 -p1
|
||||
%patch3 -p1
|
||||
%patch4 -p1
|
||||
%patch5 -p1
|
||||
|
||||
echo 'openEuler %{version}-%{release}' > gcc/DEV-PHASE
|
||||
|
||||
@ -2660,6 +2662,9 @@ end
|
||||
%doc rpm.doc/changelogs/libcc1/ChangeLog*
|
||||
|
||||
%changelog
|
||||
* Tue Nov 29 2022 Hongyu Wang <hongyu.wang@intel.com> 12.2.1-13
|
||||
- i386: Only enable small loop unrolling in backend [PR 107692]
|
||||
|
||||
* Tue Nov 29 2022 Hongyu Wang <hongyu.wang@intel.com> 12.2.1-12
|
||||
- Enable small loop unrolling for O2
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user