From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2066) id BB7253858D28; Mon, 19 Jun 2023 03:27:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB7253858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687145277; bh=gXsjUldS1xHNjRHh2CGOrPLW4UJh5ua5jPFqM4+4WbM=; h=From:To:Subject:Date:From; b=CHoOc2nI4QaI3M7YJA0jPpk6BYMvnRCrX+XI2AzREXVy7OJAUyV8864aIPSNHSPz0 gA4I34YfLKHPzhN8m0sKVhkbSTw9KVgmXoUpCIcPsWx+M0FQgZKi7SNAgP6tKSG/LK xEv4htkd+6fOxnxlQFAzX1iLzQGwaNBf0/fQ8wX4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jiu Fu Guo To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-1919] rs6000: Enable const_anchor for 'addi' X-Act-Checkin: gcc X-Git-Author: Jiufu Guo X-Git-Refname: refs/heads/master X-Git-Oldrev: c0bd79300e8fad52ec0fac7c65838a525d544a25 X-Git-Newrev: 41f42d120c4a6643f2f54952c180847d03405e3b Message-Id: <20230619032757.BB7253858D28@sourceware.org> Date: Mon, 19 Jun 2023 03:27:57 +0000 (GMT) List-Id: https://gcc.gnu.org/g:41f42d120c4a6643f2f54952c180847d03405e3b commit r14-1919-g41f42d120c4a6643f2f54952c180847d03405e3b Author: Jiufu Guo Date: Sat Oct 8 12:57:51 2022 +0800 rs6000: Enable const_anchor for 'addi' There is a functionality as const_anchor in cse.cc. This const_anchor supports to generate new constants through adding small gap/offsets to existing constant. For example: void __attribute__ ((noinline)) foo (long long *a) { *a++ = 0x2351847027482577LL; *a++ = 0x2351847027482578LL; } The second constant (0x2351847027482578LL) can be compated by adding '1' to the first constant (0x2351847027482577LL). This is profitable if more than one instructions are need to build the second constant. * For rs6000, we can enable this functionality, as the instruction 'addi' is just for this when gap is smaller than 0x8000. * One potential side effect of this feature: Comparing with "r101=0x2351847027482577LL ... r201=0x2351847027482578LL" The new r201 will be "r201=r101+1", and then r101 will live longer, and would increase pressure when allocating registers. But I feel, this would be acceptable for this const_anchor feature. With this feature, for GCC source code and SPEC object files, the significant changes are the improvement that: "addi" vs. "2 or more insns: lis+or.."; it also exposes some other optimizations opportunities: like combine/jump2. While the side effect is also occurring in few cases, but it does not impact overall performance. gcc/ChangeLog: * config/rs6000/rs6000.cc (TARGET_CONST_ANCHOR): New define. gcc/testsuite/ChangeLog: * gcc.target/powerpc/const_anchors.c: New test. * gcc.target/powerpc/try_const_anchors_ice.c: New test. Diff: --- gcc/config/rs6000/rs6000.cc | 4 ++++ gcc/testsuite/gcc.target/powerpc/const_anchors.c | 20 ++++++++++++++++++++ .../gcc.target/powerpc/try_const_anchors_ice.c | 16 ++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index ea68ca6faef..546c353029b 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -1760,6 +1760,10 @@ static const struct attribute_spec rs6000_attribute_table[] = #undef TARGET_UPDATE_IPA_FN_TARGET_INFO #define TARGET_UPDATE_IPA_FN_TARGET_INFO rs6000_update_ipa_fn_target_info + +#undef TARGET_CONST_ANCHOR +#define TARGET_CONST_ANCHOR 0x8000 + /* Processor table. */ diff --git a/gcc/testsuite/gcc.target/powerpc/const_anchors.c b/gcc/testsuite/gcc.target/powerpc/const_anchors.c new file mode 100644 index 00000000000..542e2674b12 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/const_anchors.c @@ -0,0 +1,20 @@ +/* { dg-do compile { target has_arch_ppc64 } } */ +/* { dg-options "-O2" } */ + +#define C1 0x2351847027482577ULL +#define C2 0x2351847027482578ULL + +void __attribute__ ((noinline)) foo (long long *a) +{ + *a++ = C1; + *a++ = C2; +} + +void __attribute__ ((noinline)) foo1 (long long *a, long long b) +{ + *a++ = C1; + if (b) + *a++ = C2; +} + +/* { dg-final { scan-assembler-times {\maddi\M} 2 } } */ diff --git a/gcc/testsuite/gcc.target/powerpc/try_const_anchors_ice.c b/gcc/testsuite/gcc.target/powerpc/try_const_anchors_ice.c new file mode 100644 index 00000000000..565b75a8279 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/try_const_anchors_ice.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +/* __builtin_stack_restore could generates {[%1:DI]=0;} in BLK mode, + it could assert in try_const_anchors which only accepts SCALAR_INT. */ + +long +foo (const int val) +{ + if (val == (0)) + return 0; + void *p = __builtin_stack_save (); + char c = val; + __builtin_stack_restore (p); + return c; +}