public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [rtlanal] Do a better job of costing parallel sets containing flag-setting operations.
@ 2017-06-19 13:47 Richard Earnshaw (lists)
  2017-06-19 14:08 ` Segher Boessenkool
  2017-06-30  9:03 ` Richard Earnshaw (lists)
  0 siblings, 2 replies; 11+ messages in thread
From: Richard Earnshaw (lists) @ 2017-06-19 13:47 UTC (permalink / raw)
  To: gcc-patches; +Cc: Segher Boessenkool

[-- Attachment #1: Type: text/plain, Size: 905 bytes --]

Many parallel set insns are of the form of a single set that also sets
the condition code flags.  In this case the cost of such an insn is
normally the cost of the part that doesn't set the flags, since updating
the condition flags is simply a side effect.

At present all such insns are treated as having unknown cost (ie 0) and
combine assumes that such insns are infinitely more expensive than any
other insn sequence with a non-zero cost.

This patch addresses this problem by allowing insn_rtx_cost to ignore
the condition setting part of a PARALLEL iff there is exactly one
comparison set and one non-comparison set.  If the only set operation is
a comparison we still use that as the basis of the insn cost.

	* rtlanal.c (insn_rtx_cost): If a parallel contains exactly one
	comparison set and one other set, use the cost of the
	non-comparison set.

Bootstrapped on aarch64-none-linuxgnu

OK?

R.

[-- Attachment #2: insn-costs.patch --]
[-- Type: text/x-patch, Size: 1285 bytes --]

diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c
index d9f57c3..5cae793 100644
--- a/gcc/rtlanal.c
+++ b/gcc/rtlanal.c
@@ -5260,23 +5260,41 @@ insn_rtx_cost (rtx pat, bool speed)
   int i, cost;
   rtx set;
 
-  /* Extract the single set rtx from the instruction pattern.
-     We can't use single_set since we only have the pattern.  */
+  /* Extract the single set rtx from the instruction pattern.  We
+     can't use single_set since we only have the pattern.  We also
+     consider PARALLELs of a normal set and and a single comparison.
+     In that case we use the cost of the non-comparison SET operation,
+     which is most-likely to be the real cost of this operation.  */
   if (GET_CODE (pat) == SET)
     set = pat;
   else if (GET_CODE (pat) == PARALLEL)
     {
       set = NULL_RTX;
+      rtx comparison = NULL_RTX;
+
       for (i = 0; i < XVECLEN (pat, 0); i++)
 	{
 	  rtx x = XVECEXP (pat, 0, i);
 	  if (GET_CODE (x) == SET)
 	    {
-	      if (set)
-		return 0;
-	      set = x;
+	      if (GET_CODE (SET_SRC (x)) == COMPARE)
+		{
+		  if (comparison)
+		    return 0;
+		  comparison = x;
+		}
+	      else
+		{
+		  if (set)
+		    return 0;
+		  set = x;
+		}
 	    }
 	}
+
+      if (!set && comparison)
+	set = comparison;
+
       if (!set)
 	return 0;
     }

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

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

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-19 13:47 [rtlanal] Do a better job of costing parallel sets containing flag-setting operations Richard Earnshaw (lists)
2017-06-19 14:08 ` Segher Boessenkool
2017-06-19 14:28   ` Richard Earnshaw (lists)
2017-06-19 15:06     ` Segher Boessenkool
2017-06-19 14:45   ` Richard Earnshaw (lists)
2017-06-19 15:09     ` Segher Boessenkool
2017-06-19 16:01       ` Richard Earnshaw (lists)
2017-06-19 17:41         ` Segher Boessenkool
2017-06-20 12:55           ` Segher Boessenkool
2017-06-30  9:03 ` Richard Earnshaw (lists)
2017-06-30 15:20   ` Jeff Law

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