public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: "Martin Liška" <mliska@suse.cz>
Cc: Richard Biener <richard.guenther@gmail.com>,
	       GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Speed-up use-after-scope (re-writing to SSA) (version 2)
Date: Tue, 17 Jan 2017 16:55:00 -0000	[thread overview]
Message-ID: <20170117164721.GE1867@tucnak> (raw)
In-Reply-To: <7e7f795d-a7a7-584e-8c77-61ea01207c40@suse.cz>

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

On Tue, Jan 17, 2017 at 05:16:44PM +0100, Martin Liška wrote:
> > If it did, we would ICE because ASAN_POISON_USE would survive this way until
> > expansion.  A quick fix for the ICE (if it can ever happen) would be easy,
> > in sanopt remove ASAN_POISON_USE calls which have argument that is not lhs
> > of ASAN_POISON (all other ASAN_POISON_USE calls will be handled by my
> > incremental patch).  Of course that would also mean in that case we'd report
> > a read rather than write.  But if it can't happen or is very unlikely to
> > happen, then it is a non-issue.
> 
> Thank you Jakub for working on that.
> 
> The patch is fine, I added DCE support and a test-case. Please see attached patch.
> asan.exp regression tests look fine and I've been building linux kernel with KASAN
> enabled. I'll also do asan-boostrap.
> 
> I would like to commit the patch soon, should I squash both patches together, or would it
> be preferred to separate basic optimization and support for stores?

Your choice, either is fine.  If the two patches pass bootstrap/regtest
(ideally also asan-bootstrap), they are ok for trunk.  Just one nit:

> --- a/gcc/tree-ssa-dce.c
> +++ b/gcc/tree-ssa-dce.c
> @@ -1384,6 +1384,10 @@ eliminate_unnecessary_stmts (void)
>  		  case IFN_MUL_OVERFLOW:
>  		    maybe_optimize_arith_overflow (&gsi, MULT_EXPR);
>  		    break;
> +		  case IFN_ASAN_POISON:
> +		    if (!gimple_has_lhs (stmt))
> +		      remove_dead_stmt (&gsi, bb);
> +		    break;
>  		  default:
>  		    break;
>  		  }

This doesn't seem to be the best spot for it.  At least when looking at
say:
int
foo (int x)
{
  int *ptr = 0;

  if (x < 127)
    return 5;

  {
    int a;
    ptr = &a;
    *ptr = 12345;
  }

  if (x == 34)
    return *ptr;
  return 7;
}
where the ASAN_POISON is initially used and only after evrp becomes dead,
then cddce1 calls eliminate_unnecessary_stmts and removes the lhs of the
ASAN_POISON only (and not the whole stmt, unlike how e.g. GOMP_SIMD_LANE is
handled), and only next dce pass tons of passes later removes the
ASAN_POISON call.
So IMHO you need one of these (untested) patches.  The former assumes that
the DCE pass is the only one that can drop the lhs of ASAN_POISON.  If that
is not the case, then perhaps the second patch is better, by removing the
stmt regardless if we've removed the lhs in the current dce pass or in
whatever earlier pass.  I think it shouldn't break IFN_*_OVERFLOW, because
maybe_optimize_arith_overflow starts with
tree lhs = gimple_call_lhs (stmt);
if (lhs == NULL_TREE || ...)
  return;

	Jakub

[-- Attachment #2: 4 --]
[-- Type: text/plain, Size: 852 bytes --]

--- gcc/tree-ssa-dce.c.jj	2017-01-01 12:45:38.380670110 +0100
+++ gcc/tree-ssa-dce.c	2017-01-17 17:35:43.650902141 +0100
@@ -1367,10 +1367,18 @@ eliminate_unnecessary_stmts (void)
 		  update_stmt (stmt);
 		  release_ssa_name (name);
 
-		  /* GOMP_SIMD_LANE without lhs is not needed.  */
-		  if (gimple_call_internal_p (stmt)
-		      && gimple_call_internal_fn (stmt) == IFN_GOMP_SIMD_LANE)
-		    remove_dead_stmt (&gsi, bb);
+		  /* GOMP_SIMD_LANE or ASAN_POISON without lhs is not
+		     needed.  */
+		  if (gimple_call_internal_p (stmt))
+		    switch (gimple_call_internal_fn (stmt))
+		      {
+		      case IFN_GOMP_SIMD_LANE:
+		      case IFN_ASAN_POISON:
+			remove_dead_stmt (&gsi, bb);
+			break;
+		      default:
+			break;
+		      }
 		}
 	      else if (gimple_call_internal_p (stmt))
 		switch (gimple_call_internal_fn (stmt))

[-- Attachment #3: 3 --]
[-- Type: text/plain, Size: 1080 bytes --]

--- gcc/tree-ssa-dce.c.jj	2017-01-01 12:45:38.380670110 +0100
+++ gcc/tree-ssa-dce.c	2017-01-17 17:37:38.639427099 +0100
@@ -1366,13 +1366,8 @@ eliminate_unnecessary_stmts (void)
 		  maybe_clean_or_replace_eh_stmt (stmt, stmt);
 		  update_stmt (stmt);
 		  release_ssa_name (name);
-
-		  /* GOMP_SIMD_LANE without lhs is not needed.  */
-		  if (gimple_call_internal_p (stmt)
-		      && gimple_call_internal_fn (stmt) == IFN_GOMP_SIMD_LANE)
-		    remove_dead_stmt (&gsi, bb);
 		}
-	      else if (gimple_call_internal_p (stmt))
+	      if (gimple_call_internal_p (stmt))
 		switch (gimple_call_internal_fn (stmt))
 		  {
 		  case IFN_ADD_OVERFLOW:
@@ -1384,6 +1379,13 @@ eliminate_unnecessary_stmts (void)
 		  case IFN_MUL_OVERFLOW:
 		    maybe_optimize_arith_overflow (&gsi, MULT_EXPR);
 		    break;
+		  /* GOMP_SIMD_LANE or ASAN_POISON without lhs is not
+		     needed.  */
+		  case IFN_GOMP_SIMD_LANE:
+		  case IFN_ASAN_POISON:
+		    if (gimple_call_lhs (stmt) == NULL_TREE)
+		      remove_dead_stmt (&gsi, bb);
+		    break;
 		  default:
 		    break;
 		  }

  reply	other threads:[~2017-01-17 16:47 UTC|newest]

Thread overview: 111+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-06 11:04 [PATCH, RFC] Introduce -fsanitize=use-after-scope Martin Liška
2016-05-06 11:08 ` [PATCH] Introduce tests for -fsanitize=use-after-scope Martin Liška
2016-05-11 12:56   ` Martin Liška
2016-05-06 11:16 ` [PATCH, RFC] Introduce -fsanitize=use-after-scope Martin Liška
2016-05-06 11:48 ` Yury Gribov
2016-05-06 12:39   ` Jakub Jelinek
2016-05-06 13:07     ` Martin Liška
2016-05-06 14:22     ` Yury Gribov
2016-05-06 14:39       ` Jakub Jelinek
2016-05-10 15:03         ` Martin Liška
2016-05-10 15:15           ` Jakub Jelinek
2016-05-06 13:17   ` Martin Liška
2016-05-06 13:25     ` Jakub Jelinek
2016-05-06 14:41       ` Martin Liška
2016-05-06 14:46         ` Jakub Jelinek
2016-05-06 12:22 ` Jakub Jelinek
2016-05-11 12:54   ` Martin Liška
2016-05-12 10:42     ` Jakub Jelinek
2016-05-12 14:12       ` Martin Liška
2016-08-12 12:42         ` Martin Liška
2016-08-18 13:36         ` Jakub Jelinek
2016-10-03  9:27           ` [PATCH, RFC] Introduce -fsanitize=use-after-scope (v2) Martin Liška
2016-10-03  9:30             ` [PATCH, 02/N] Introduce tests for -fsanitize-address-use-after-scope Martin Liška
2016-11-07 10:04               ` [PATCH, 02/N] Introduce tests for -fsanitize-address-use-after-scope (v3) Martin Liška
2016-11-07 10:09                 ` Jakub Jelinek
2016-10-03  9:39             ` [PATCH, RFC] Introduce -fsanitize=use-after-scope (v2) Jakub Jelinek
2016-10-07 11:13             ` Jakub Jelinek
2016-10-12 14:08               ` Martin Liška
2016-10-21 14:26                 ` Jakub Jelinek
2016-10-25 13:18                   ` Martin Liška
2016-10-27 14:40                   ` Martin Liška
2016-10-27 17:24                     ` Jakub Jelinek
2016-11-01 14:48                       ` Martin Liška
2016-11-01 14:54                         ` Jakub Jelinek
2016-11-01 15:01                           ` Martin Liška
2016-11-02  9:36                           ` Martin Liška
2016-11-02  9:59                             ` Jakub Jelinek
2016-11-02 10:09                               ` Martin Liška
2016-11-02 10:11                               ` Jakub Jelinek
2016-11-02 14:20                                 ` Marek Polacek
2016-11-02 14:27                                   ` Martin Liška
2016-11-02 14:35                                     ` Jakub Jelinek
2016-11-04  9:17                                       ` Martin Liška
2016-11-04  9:33                                         ` Jakub Jelinek
2016-11-04 10:59                                           ` Martin Liška
2016-11-07 10:03                                             ` [PATCH, RFC] Introduce -fsanitize=use-after-scope (v3) Martin Liška
2016-11-07 10:08                                               ` Jakub Jelinek
2016-11-08  8:58                                                 ` Question about lambda function variables Martin Liška
2016-11-08  9:12                                                   ` Jakub Jelinek
2016-11-08  9:35                                                     ` Martin Liška
2016-11-07 16:07                                               ` Fix build of jit (was Re: [PATCH, RFC] Introduce -fsanitize=use-after-scope (v3)) David Malcolm
2016-11-07 16:17                                                 ` Jakub Jelinek
2016-11-08  9:38                                                   ` Martin Liška
2016-11-08  9:41                                                     ` Jakub Jelinek
2016-11-08 12:00                                                       ` [PATCH] use-after-scope fallout Martin Liška
2016-11-08 12:10                                                         ` Jakub Jelinek
2016-11-08 18:05                                                         ` David Malcolm
2016-11-01 14:54                       ` [PATCH, RFC] Introduce -fsanitize=use-after-scope (v2) Martin Liška
2016-11-01 15:12                         ` Jakub Jelinek
2016-11-02  9:40                           ` Richard Biener
2016-11-02  9:44                             ` Martin Liška
2016-11-02  9:52                             ` Jakub Jelinek
2016-11-02 12:36                               ` Richard Biener
2016-11-02 12:56                                 ` Jakub Jelinek
2016-11-02 12:59                                   ` Richard Biener
2016-11-02 13:06                                     ` Jakub Jelinek
2016-11-02 13:16                                       ` Richard Biener
2016-11-02 14:38                                         ` Martin Liška
2016-11-02 14:51                                           ` Jakub Jelinek
2016-11-02 15:25                                             ` Martin Liška
2016-11-03 13:34                                             ` Martin Liška
2016-11-03 13:44                                               ` Jakub Jelinek
2016-11-03 14:02                                                 ` Martin Liška
2016-11-03 14:04                                                   ` Jakub Jelinek
2016-11-03 14:18                                                     ` Martin Liška
2016-11-16 12:25                                         ` [RFC][PATCH] Speed-up use-after-scope (re-writing to SSA) Martin Liška
2016-11-16 12:53                                           ` Martin Liška
2016-11-16 13:07                                           ` Jakub Jelinek
2016-11-16 16:01                                             ` Martin Liška
2016-11-16 16:28                                               ` Jakub Jelinek
2016-11-22 11:55                                                 ` Martin Liška
2016-11-23 13:57                                                   ` Martin Liška
2016-11-23 14:14                                                     ` Jakub Jelinek
2016-12-01 16:30                                                       ` Martin Liška
2016-12-02 12:29                                                         ` Richard Biener
2016-12-08 12:51                                                           ` Martin Liška
2016-12-13 14:16                                                             ` Richard Biener
2016-12-20 11:34                                                 ` [PATCH] Speed-up use-after-scope (re-writing to SSA) (version 2) Martin Liška
2016-12-21  9:19                                                   ` Jakub Jelinek
2016-12-22 17:11                                                     ` Martin Liška
2016-12-22 17:28                                                       ` Jakub Jelinek
2017-01-09 14:58                                                         ` Martin Liška
2017-01-16 14:20                                                           ` Jakub Jelinek
2017-01-17 16:22                                                             ` Martin Liška
2017-01-17 16:55                                                               ` Jakub Jelinek [this message]
2017-01-18 15:37                                                                 ` Martin Liška
2017-01-19 16:43                                                                   ` Jakub Jelinek
2017-01-20 11:55                                                                     ` Martin Liška
2017-01-20 14:27                                                                       ` Martin Liška
2017-01-20 14:30                                                                         ` Jakub Jelinek
2017-01-20 14:42                                                                           ` Markus Trippelsdorf
2017-01-23  9:38                                                                           ` Martin Liška
2017-01-23  9:39                                                                             ` Jakub Jelinek
2017-01-23 12:07                                                                               ` Martin Liška
2017-01-26  9:04                                                                             ` Thomas Schwinge
2017-01-26 10:55                                                                               ` Jakub Jelinek
2017-01-26 20:45                                                                                 ` Thomas Schwinge
2017-01-26 20:52                                                                                   ` Jakub Jelinek
2016-11-16 16:09                                             ` [RFC][PATCH] Speed-up use-after-scope (re-writing to SSA) Martin Liška
2016-11-02  9:52                           ` [PATCH, RFC] Introduce -fsanitize=use-after-scope (v2) Martin Liška
2016-09-03 15:23         ` [PATCH, RFC] Introduce -fsanitize=use-after-scope Jakub Jelinek

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=20170117164721.GE1867@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mliska@suse.cz \
    --cc=richard.guenther@gmail.com \
    /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).