public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][AArch64] Allow CMP+SHIFT when comparing with zero
@ 2017-03-16 11:26 Sudi Das
  2017-06-02 15:33 ` James Greenhalgh
  0 siblings, 1 reply; 2+ messages in thread
From: Sudi Das @ 2017-03-16 11:26 UTC (permalink / raw)
  To: gcc-patches; +Cc: nd, Marcus Shawcroft, Richard Earnshaw, James Greenhalgh

[-- 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" } } */

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH][AArch64] Allow CMP+SHIFT when comparing with zero
  2017-03-16 11:26 [PATCH][AArch64] Allow CMP+SHIFT when comparing with zero Sudi Das
@ 2017-06-02 15:33 ` James Greenhalgh
  0 siblings, 0 replies; 2+ messages in thread
From: James Greenhalgh @ 2017-06-02 15:33 UTC (permalink / raw)
  To: Sudi Das; +Cc: gcc-patches, nd, Marcus Shawcroft, Richard Earnshaw

On Thu, Mar 16, 2017 at 11:26:27AM +0000, Sudi Das wrote:
> 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?

This is OK. I've applied it on your behalf as revision 248836.

Thanks,
James

> 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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-06-02 15:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-16 11:26 [PATCH][AArch64] Allow CMP+SHIFT when comparing with zero Sudi Das
2017-06-02 15:33 ` James Greenhalgh

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).