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
Subject: Re: [PATCH] Fix PR79201 (half-way)
Date: Tue, 25 Apr 2017 09:31:00 -0000	[thread overview]
Message-ID: <alpine.LSU.2.20.1704251122390.24645@zhemvz.fhfr.qr> (raw)
In-Reply-To: <alpine.LSU.2.20.1704241053350.24645@zhemvz.fhfr.qr>

On Mon, 24 Apr 2017, Richard Biener wrote:

> 
> One issue in PR79201 is that we don't sink pure/const calls which is
> what the following simple patch fixes.
> 
> Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Needed some gimple_assign_lhs -> gimple_get_lhs adjustments and
adjustment of gcc.target/i386/pr22152.c where we now sink the
assignment out of the pointless loop.  Not sure what the original
bug was about (well, reg allocation) so I simply disabled sinking
for it.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2017-04-25  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/79201
	* tree-ssa-sink.c (statement_sink_location): Handle calls.

	* gcc.dg/tree-ssa/ssa-sink-16.c: New testcase.
	* gcc.target/i386/pr22152.c: Disable sinking.

Index: gcc/tree-ssa-sink.c
===================================================================
*** gcc/tree-ssa-sink.c	(revision 247092)
--- gcc/tree-ssa-sink.c	(working copy)
*************** statement_sink_location (gimple *stmt, b
*** 256,263 ****
  
    *zero_uses_p = false;
  
!   /* We only can sink assignments.  */
!   if (!is_gimple_assign (stmt))
      return false;
  
    /* We only can sink stmts with a single definition.  */
--- 257,268 ----
  
    *zero_uses_p = false;
  
!   /* We only can sink assignments and non-looping const/pure calls.  */
!   int cf;
!   if (!is_gimple_assign (stmt)
!       && (!is_gimple_call (stmt)
! 	  || !((cf = gimple_call_flags (stmt)) & (ECF_CONST|ECF_PURE))
! 	  || (cf & ECF_LOOPING_CONST_OR_PURE)))
      return false;
  
    /* We only can sink stmts with a single definition.  */
*************** statement_sink_location (gimple *stmt, b
*** 291,297 ****
    if (stmt_ends_bb_p (stmt)
        || gimple_has_side_effects (stmt)
        || (cfun->has_local_explicit_reg_vars
! 	  && TYPE_MODE (TREE_TYPE (gimple_assign_lhs (stmt))) == BLKmode))
      return false;
  
    /* Return if there are no immediate uses of this stmt.  */
--- 296,302 ----
    if (stmt_ends_bb_p (stmt)
        || gimple_has_side_effects (stmt)
        || (cfun->has_local_explicit_reg_vars
! 	  && TYPE_MODE (TREE_TYPE (gimple_get_lhs (stmt))) == BLKmode))
      return false;
  
    /* Return if there are no immediate uses of this stmt.  */
*************** statement_sink_location (gimple *stmt, b
*** 323,337 ****
  
  	  /* A killing definition is not a use.  */
  	  if ((gimple_has_lhs (use_stmt)
! 	       && operand_equal_p (gimple_assign_lhs (stmt),
  				   gimple_get_lhs (use_stmt), 0))
! 	      || stmt_kills_ref_p (use_stmt, gimple_assign_lhs (stmt)))
  	    {
  	      /* If use_stmt is or might be a nop assignment then USE_STMT
  	         acts as a use as well as definition.  */
  	      if (stmt != use_stmt
  		  && ref_maybe_used_by_stmt_p (use_stmt,
! 					       gimple_assign_lhs (stmt)))
  		return false;
  	      continue;
  	    }
--- 328,342 ----
  
  	  /* A killing definition is not a use.  */
  	  if ((gimple_has_lhs (use_stmt)
! 	       && operand_equal_p (gimple_get_lhs (stmt),
  				   gimple_get_lhs (use_stmt), 0))
! 	      || stmt_kills_ref_p (use_stmt, gimple_get_lhs (stmt)))
  	    {
  	      /* If use_stmt is or might be a nop assignment then USE_STMT
  	         acts as a use as well as definition.  */
  	      if (stmt != use_stmt
  		  && ref_maybe_used_by_stmt_p (use_stmt,
! 					       gimple_get_lhs (stmt)))
  		return false;
  	      continue;
  	    }
Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-16.c
===================================================================
*** gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-16.c	(nonexistent)
--- gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-16.c	(working copy)
***************
*** 0 ****
--- 1,14 ----
+ /* { dg-do compile } */
+ /* Note PRE rotates the loop and blocks the sinking opportunity.  */
+ /* { dg-options "-O2 -fno-tree-pre -fdump-tree-sink -fdump-tree-optimized" } */
+ 
+ int f(int n)
+ {
+   int i,j=0;
+   for (i = 0; i < 31; i++)
+     j = __builtin_ffs(i);
+   return j;
+ }
+ 
+ /* { dg-final { scan-tree-dump "Sinking j_. = __builtin_ffs" "sink" } } */
+ /* { dg-final { scan-tree-dump "return 2;" "optimized" } } */
Index: gcc/testsuite/gcc.target/i386/pr22152.c
===================================================================
*** gcc/testsuite/gcc.target/i386/pr22152.c	(revision 247092)
--- gcc/testsuite/gcc.target/i386/pr22152.c	(working copy)
***************
*** 1,5 ****
  /* { dg-do compile } */
! /* { dg-options "-O2 -msse2 -mtune=core2" } */
  /* { dg-additional-options "-mno-vect8-ret-in-mem" { target *-*-vxworks* } } */
  /* { dg-additional-options "-mabi=sysv" { target x86_64-*-mingw* } } */
  
--- 1,5 ----
  /* { dg-do compile } */
! /* { dg-options "-O2 -fno-tree-sink -msse2 -mtune=core2" } */
  /* { dg-additional-options "-mno-vect8-ret-in-mem" { target *-*-vxworks* } } */
  /* { dg-additional-options "-mabi=sysv" { target x86_64-*-mingw* } } */
  

  reply	other threads:[~2017-04-25  9:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-24  9:06 Richard Biener
2017-04-25  9:31 ` Richard Biener [this message]
2017-05-11 12:21   ` Rainer Orth
2017-05-11 13:00     ` Richard Biener
2017-05-11 13:07       ` Uros Bizjak
2017-05-11 14:06         ` Richard Biener
2017-05-11 15:03           ` Uros Bizjak
2017-05-12  7:22             ` Richard Biener

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