From: Sudi Das <Sudi.Das@arm.com>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Cc: nd <nd@arm.com>, Marcus Shawcroft <Marcus.Shawcroft@arm.com>,
"Richard Earnshaw" <Richard.Earnshaw@arm.com>,
James Greenhalgh <James.Greenhalgh@arm.com>
Subject: [PATCH][AArch64] Allow CMP+SHIFT when comparing with zero
Date: Thu, 16 Mar 2017 11:26:00 -0000 [thread overview]
Message-ID: <VI1PR08MB0640AE02B80EBC2F697C574398260@VI1PR08MB0640.eurprd08.prod.outlook.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1013 bytes --]
Hi all
The backend pattern for combining a CMP+SHIFT was missing out on a case when comparing with zero. This was happening because aarch64_select_cc_mode (SELECT_CC_MODE) was not returning the correct mode (in this case CC_SWP) which was needed to identify the combine. This patch adds this missing case.
For the test case :
int f3 (int x, int y)
{
int res = x << 3;
return res != 0;
}
We are now generating (at -O2)
f3:
cmp wzr, w0, lsl 3
cset w0, ne
ret
instead of :
f3:
lsl w0, w0, 3
cmp w0, 0
cset w0, ne
ret
Added this new test and checked for regressions on bootstrapped aarch64-none-linux-gnu.
Ok for stage 1?
Thanks
Sudi
2017-03-10 Sudakshina Das <sudi.das@arm.com>
* config/aarch64/aarch64.c (aarch64_select_cc_mode): Return CC_SWP for
comparision with zero.
2017-03-10 Sudakshina Das <sudi.das@arm.com>
* gcc.target/aarch64/cmp_shifted_reg_1.c: New Test.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch-7201.diff --]
[-- Type: text/x-patch; name="patch-7201.diff", Size: 1171 bytes --]
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 714bb79..01af2a7 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -4707,7 +4707,7 @@ aarch64_select_cc_mode (RTX_CODE code, rtx x, rtx y)
the comparison will have to be swapped when we emit the assembly
code. */
if ((GET_MODE (x) == SImode || GET_MODE (x) == DImode)
- && (REG_P (y) || GET_CODE (y) == SUBREG)
+ && (REG_P (y) || GET_CODE (y) == SUBREG || y == const0_rtx)
&& (GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT
|| GET_CODE (x) == LSHIFTRT
|| GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND))
diff --git a/gcc/testsuite/gcc.target/aarch64/cmp_shifted_reg_1.c b/gcc/testsuite/gcc.target/aarch64/cmp_shifted_reg_1.c
new file mode 100644
index 0000000..cacecf4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/cmp_shifted_reg_1.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 " } */
+
+int f3 (int x, int y)
+{
+ int res = x << 3;
+ return res != 0;
+}
+
+/* We should combine the shift and compare */
+/* { dg-final { scan-assembler "cmp\.*\twzr, w\[0-9\]+, lsl 3" } } */
next reply other threads:[~2017-03-16 11:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-16 11:26 Sudi Das [this message]
2017-06-02 15:33 ` James Greenhalgh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=VI1PR08MB0640AE02B80EBC2F697C574398260@VI1PR08MB0640.eurprd08.prod.outlook.com \
--to=sudi.das@arm.com \
--cc=James.Greenhalgh@arm.com \
--cc=Marcus.Shawcroft@arm.com \
--cc=Richard.Earnshaw@arm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=nd@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).