public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Cc: Jan Hubicka <jh@suse.de>
Subject: [PATCH] Fix PR84986
Date: Tue, 20 Mar 2018 10:35:00 -0000	[thread overview]
Message-ID: <alpine.LSU.2.20.1803201100430.18265@zhemvz.fhfr.qr> (raw)


With the x86 vectorizer cost-model rewrite we ended up costing
scalar conversions as nothing.  After my patch using the proper
target cost estimates for the scalar version this now exposes
underestimating scalar cost and thus no longer vectorizing
the testcase in this PR.  This fix is to restrict zero-costing
to sign-conversions, all other conversions are possibly
value-changing.  I guess some zero-extensions are free as well
but I didn't want to get too fancy as I'm not sure about
QImode -> SImode conversions for example since whether
that's free (can just use %eax instead of %ax) likely depends on 
context.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

OK?

Thanks,
Richard.

2018-03-20  Richard Biener  <rguenther@suse.de>

	PR target/84986
	* config/i386/i386.c (ix86_add_stmt_cost): Only cost
	sign-conversions as zero, fall back to standard scalar_stmt
	cost for the rest.

	* gcc.dg/vect/costmodel/x86_64/costmodel-pr84986.c: New testcase.

Index: gcc/config/i386/i386.c
===================================================================
--- gcc/config/i386/i386.c	(revision 258674)
+++ gcc/config/i386/i386.c	(working copy)
@@ -50462,7 +50462,11 @@ ix86_add_stmt_cost (void *data, int coun
 	  }
 	  break;
 	case NOP_EXPR:
-	  stmt_cost = 0;
+	  /* Only sign-conversions are free.  */
+	  if (tree_nop_conversion_p
+	        (TREE_TYPE (gimple_assign_lhs (stmt_info->stmt)),
+		 TREE_TYPE (gimple_assign_rhs1 (stmt_info->stmt))))
+	    stmt_cost = 0;
 	  break;
 
 	case BIT_IOR_EXPR:
Index: gcc/testsuite/gcc.dg/vect/costmodel/x86_64/costmodel-pr84986.c
===================================================================
--- gcc/testsuite/gcc.dg/vect/costmodel/x86_64/costmodel-pr84986.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/vect/costmodel/x86_64/costmodel-pr84986.c	(working copy)
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target vect_long } */
+
+int N;
+long fn1(void) {
+  short i;
+  long a;
+  i = a = 0;
+  while (i < N)
+    a -= i++;
+  return a;
+}
+
+/* { dg-final { scan-tree-dump "vectorized 1 loops" "vect" } } */

             reply	other threads:[~2018-03-20 10:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-20 10:35 Richard Biener [this message]
2018-03-20 11:37 ` Jakub Jelinek
2018-03-20 10:50   ` Richard Biener
2018-03-20 13:36     ` Jakub Jelinek
2018-03-20 11:09       ` Richard Biener
2018-03-20 13:53     ` Jan Hubicka
2018-03-24 17:42 ` H.J. Lu

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=alpine.LSU.2.20.1803201100430.18265@zhemvz.fhfr.qr \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jh@suse.de \
    /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).