diff mbox

[4/4,AArch64] Cost CCMP instruction sequences to choose better expand order

Message ID AM3PR08MB0088F7FED788CA7D0090F21683C70@AM3PR08MB0088.eurprd08.prod.outlook.com
State New
Headers show

Commit Message

Wilco Dijkstra Jan. 25, 2016, 8:09 p.m. UTC
Andreas Schwab <schwab@linux-m68k.org> wrote:

> FAIL: gcc.target/aarch64/ccmp_1.c scan-assembler-times \tcmp\tw[0-9]+, 0 4
> FAIL: gcc.target/aarch64/ccmp_1.c scan-assembler adds\t
> FAIL: gcc.target/aarch64/ccmp_1.c scan-assembler-times fccmpe\t.*0\\.0 1

Yes I noticed those too, and here is the fix. Richard's recent change added UNSPEC to the CCMP patterns to stop combine optimizing the CCMP CCmode immediate in a rare case. This requires a change to the CCMP cost calculation as the CCMP instruction with unspec is no longer recognized.

Fix the ccmp_1.c test to allow both '0' and 'wzr' on cmp - BTW is there a regular expression that correctly implements (0|xzr)? If I use that the test still fails somehow but \[0wzr\]+ works fine... Is the correct syntax documented somewhere?

Finally to ensure FCCMPE is emitted on relational compares, add -ffinite-math-only.

ChangeLog:
2016-01-25  Wilco Dijkstra  <wdijkstr@arm.com>

gcc/
	* config/aarch64/aarch64.c (aarch64_if_then_else_costs):
	Remove CONST_INT_P check in CCMP cost calculation.

gcc/testsuite/
	* gcc.target/aarch64/ccmp_1.c: Fix test issues.

---

Comments

Richard Henderson Jan. 25, 2016, 8:45 p.m. UTC | #1
On 01/25/2016 12:09 PM, Wilco Dijkstra wrote:
> BTW is there a regular expression that correctly implements (0|xzr)? 

(0|wzr) works fine for me; I've got exactly that fix in one of my trees.


r~
James Greenhalgh Jan. 28, 2016, 2:33 p.m. UTC | #2
On Mon, Jan 25, 2016 at 08:09:39PM +0000, Wilco Dijkstra wrote:
> Andreas Schwab <schwab@linux-m68k.org> wrote:
> 
> > FAIL: gcc.target/aarch64/ccmp_1.c scan-assembler-times \tcmp\tw[0-9]+, 0 4
> > FAIL: gcc.target/aarch64/ccmp_1.c scan-assembler adds\t
> > FAIL: gcc.target/aarch64/ccmp_1.c scan-assembler-times fccmpe\t.*0\\.0 1
> 
> Yes I noticed those too, and here is the fix. Richard's recent change added
> UNSPEC to the CCMP patterns to stop combine optimizing the CCMP CCmode
> immediate in a rare case. This requires a change to the CCMP cost calculation
> as the CCMP instruction with unspec is no longer recognized.
> 
> Fix the ccmp_1.c test to allow both '0' and 'wzr' on cmp - BTW is there a
> regular expression that correctly implements (0|xzr)? If I use that the test
> still fails somehow but \[0wzr\]+ works fine... Is the correct syntax
> documented somewhere?
> 
> Finally to ensure FCCMPE is emitted on relational compares, add
> -ffinite-math-only.

OK.

Thanks,
James

> 
> ChangeLog:
> 2016-01-25  Wilco Dijkstra  <wdijkstr@arm.com>
> 
> gcc/
> 	* config/aarch64/aarch64.c (aarch64_if_then_else_costs):
> 	Remove CONST_INT_P check in CCMP cost calculation.
> 
> gcc/testsuite/
> 	* gcc.target/aarch64/ccmp_1.c: Fix test issues.
>
James Greenhalgh Feb. 3, 2016, 9:58 a.m. UTC | #3
On Thu, Jan 28, 2016 at 02:33:20PM +0000, James Greenhalgh wrote:
> On Mon, Jan 25, 2016 at 08:09:39PM +0000, Wilco Dijkstra wrote:
> > Andreas Schwab <schwab@linux-m68k.org> wrote:
> > 
> > > FAIL: gcc.target/aarch64/ccmp_1.c scan-assembler-times \tcmp\tw[0-9]+, 0 4
> > > FAIL: gcc.target/aarch64/ccmp_1.c scan-assembler adds\t
> > > FAIL: gcc.target/aarch64/ccmp_1.c scan-assembler-times fccmpe\t.*0\\.0 1
> > 
> > Yes I noticed those too, and here is the fix. Richard's recent change added
> > UNSPEC to the CCMP patterns to stop combine optimizing the CCMP CCmode
> > immediate in a rare case. This requires a change to the CCMP cost calculation
> > as the CCMP instruction with unspec is no longer recognized.
> > 
> > Fix the ccmp_1.c test to allow both '0' and 'wzr' on cmp - BTW is there a
> > regular expression that correctly implements (0|xzr)? If I use that the test
> > still fails somehow but \[0wzr\]+ works fine... Is the correct syntax
> > documented somewhere?
> > 
> > Finally to ensure FCCMPE is emitted on relational compares, add
> > -ffinite-math-only.
> > 
> > ChangeLog:
> > 2016-01-25  Wilco Dijkstra  <wdijkstr@arm.com>
> > 
> > gcc/
> > 	* config/aarch64/aarch64.c (aarch64_if_then_else_costs):
> > 	Remove CONST_INT_P check in CCMP cost calculation.
> > 
> > gcc/testsuite/
> > 	* gcc.target/aarch64/ccmp_1.c: Fix test issues.

I'm still seeing:

  FAIL: gcc.target/aarch64/ccmp_1.c scan-assembler-times \\tcmp\\tw[0-9]+, (0|wzr) 4

Looking at the assembly generated for me with this testcase I see ccmp
with zero in 5 places:

  f3:
	cmp	w1, 34
	ccmp	w0, 19, 0, eq
	cset	w0, eq
	ret
  f4:
	cmp	w0, 35
	ccmp	w1, 20, 0, eq
	cset	w0, eq
	ret

  f7:
	cmp	w0, 0
	ccmp	w1, 7, 0, eq
	cset	w0, eq
	ret

  f8:
	cmp	w1, 0
	ccmp	w0, 9, 0, eq
	cset	w0, eq
	ret

  f11:
	fcmpe	d0, #0.0
	ccmp	w0, 30, 0, mi
	cset	w0, eq
	ret

Are these all expected? If so, can you spin the "obvious" patch to bump
this number to 5.

Thanks,
James
Wilco Dijkstra Feb. 3, 2016, 11:57 a.m. UTC | #4
James Greenhalgh wrote:
> I'm still seeing:
>
>  FAIL: gcc.target/aarch64/ccmp_1.c scan-assembler-times \\tcmp\\tw[0-9]+, (0|wzr) 4

That's because "(0|wzr)" is not correctly matching due to the weird regular expression syntax used in the testsuite (I tried with several escapes to no avail). It looks like Richard committed that, perhaps accidentally? I'll change it back to "0" (count 4 is right as it only matches CMP, not CCMP).

Wilco
diff mbox

Patch

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 6c570c7db1cfbd0415e73fb110ce5d70aa09b540..7f304b78a3e48862bf5aaf855e307fe90969dd8c 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -6014,7 +6014,7 @@  aarch64_if_then_else_costs (rtx op0, rtx op1, rtx op2, int *cost, bool speed)
   else if (GET_MODE_CLASS (GET_MODE (inner)) == MODE_CC)
     {
       /* CCMP.  */
-      if ((GET_CODE (op1) == COMPARE) && CONST_INT_P (op2))
+      if (GET_CODE (op1) == COMPARE)
 	{
 	  /* Increase cost of CCMP reg, 0, imm, CC to prefer CMP reg, 0.  */
 	  if (XEXP (op1, 1) == const0_rtx)
diff --git a/gcc/testsuite/gcc.target/aarch64/ccmp_1.c b/gcc/testsuite/gcc.target/aarch64/ccmp_1.c
index 7c39b61a585a1d4d662b0736e1c80e06bdc6b4ce..8e3f8629f802eec64c95080a23f320712333471b 100644
--- a/gcc/testsuite/gcc.target/aarch64/ccmp_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/ccmp_1.c
@@ -1,5 +1,5 @@ 
 /* { dg-do compile } */
-/* { dg-options "-O2" } */
+/* { dg-options "-O2 -ffinite-math-only" } */
 
 int
 f1 (int a)
@@ -85,7 +85,7 @@  f13 (int a, int b)
 /* { dg-final { scan-assembler "cmp\t(.)+34" } } */
 /* { dg-final { scan-assembler "cmp\t(.)+35" } } */
 
-/* { dg-final { scan-assembler-times "\tcmp\tw\[0-9\]+, 0" 4 } } */
+/* { dg-final { scan-assembler-times "\tcmp\tw\[0-9\]+, \[0wzr\]+" 4 } } */
 /* { dg-final { scan-assembler-times "fcmpe\t(.)+0\\.0" 2 } } */
 /* { dg-final { scan-assembler-times "fcmp\t(.)+0\\.0" 2 } } */