public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Kugan <kugan.vivekanandarajah@linaro.org>
To: Richard Biener <richard.guenther@gmail.com>
Cc: Michael Matz <matz@suse.de>,
	"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [5/7] Allow gimple debug stmt in widen mode
Date: Sun, 18 Oct 2015 20:51:00 -0000	[thread overview]
Message-ID: <5623FB27.6090301@linaro.org> (raw)
In-Reply-To: <CAFiYyc2FbbAaT4rs1siPJEAfPA7QgyL6QL-XvWF5SZds+6cm-g@mail.gmail.com>

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


> You remove
> 
> 
> @@ -5269,16 +5268,6 @@ expand_debug_locations (void)
> 
>         if (!val)
>           val = gen_rtx_UNKNOWN_VAR_LOC ();
> -       else
> -         {
> -           mode = GET_MODE (INSN_VAR_LOCATION (insn));
> -
> -           gcc_assert (mode == GET_MODE (val)
> -                       || (GET_MODE (val) == VOIDmode
> -                           && (CONST_SCALAR_INT_P (val)
> -                               || GET_CODE (val) == CONST_FIXED
> -                               || GET_CODE (val) == LABEL_REF)));
> -         }
> 
> which is in place to ensure the debug insns are "valid" in some form(?)
> On what kind of insn does the assert trigger with your patch so that
> you have to remove it?

Thanks for the review. Please find the attached patch this removes it
and does the conversion as part of the GIMPLE_DEBUG.

Does this look better?


Thanks,
Kugan



gcc/ChangeLog:

2015-10-19  Kugan Vivekanandarajah  <kuganv@linaro.org>

	* gimple-ssa-type-promote.c (fixup_uses): For GIMPLE_DEBUG stmts,
	convert the values computed in promoted_type to original and bind.


> 
> +
> +             switch (TREE_CODE_CLASS (TREE_CODE (op)))
> +               {
> +               case tcc_exceptional:
> +               case tcc_unary:
> +                   {
> 
> Hmm.  So when we promote _1 in
> 
>   _1 = ...;
>  # DEBUG i = _1 + 7;
> 
> to sth else it would probably best to instead of doing conversion of operands
> where necessary introduce a debug temporary like
> 
>  # DEBUG D#1 = (type-of-_1) replacement-of-_1;
> 
> and replace debug uses of _1 with D#1


[-- Attachment #2: 0005-debug-stmt-in-widen-mode.patch --]
[-- Type: text/x-diff, Size: 3165 bytes --]

From 47469bb461dcafdf0ce5fe5f020faed0e8d6d4d9 Mon Sep 17 00:00:00 2001
From: Kugan Vivekanandarajah <kugan.vivekanandarajah@linaro.org>
Date: Tue, 1 Sep 2015 08:40:40 +1000
Subject: [PATCH 5/7] debug stmt in widen mode

---
 gcc/gimple-ssa-type-promote.c | 82 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 79 insertions(+), 3 deletions(-)

diff --git a/gcc/gimple-ssa-type-promote.c b/gcc/gimple-ssa-type-promote.c
index d4ca1a3..660bd3f 100644
--- a/gcc/gimple-ssa-type-promote.c
+++ b/gcc/gimple-ssa-type-promote.c
@@ -589,10 +589,86 @@ fixup_uses (tree use, tree promoted_type, tree old_type)
 	{
 	case GIMPLE_DEBUG:
 	    {
-	      gsi = gsi_for_stmt (stmt);
-	      gsi_remove (&gsi, true);
-	      break;
+	      /* Change the GIMPLE_DEBUG stmt such that the value bound is
+		 computed in promoted_type and then converted to required
+		 type.  */
+	      tree op, new_op = NULL_TREE;
+	      gdebug *copy = NULL, *gs = as_a <gdebug *> (stmt);
+	      enum tree_code code;
+
+	      /* Get the value that is bound in debug stmt.  */
+	      switch (gs->subcode)
+		{
+		case GIMPLE_DEBUG_BIND:
+		  op = gimple_debug_bind_get_value (gs);
+		  break;
+		case GIMPLE_DEBUG_SOURCE_BIND:
+		  op = gimple_debug_source_bind_get_value (gs);
+		  break;
+		default:
+		  gcc_unreachable ();
+		}
+
+	      code = TREE_CODE (op);
+	      /* Convert the value computed in promoted_type to
+		 old_type.  */
+	      if (code == SSA_NAME && use == op)
+		new_op = build1 (NOP_EXPR, old_type, use);
+	      else if (TREE_CODE_CLASS (TREE_CODE (op)) == tcc_unary
+		       && code != NOP_EXPR)
+		{
+		  tree op0 = TREE_OPERAND (op, 0);
+		  if (op0 == use)
+		    {
+		      tree temp = build1 (code, promoted_type, op0);
+		      new_op = build1 (NOP_EXPR, old_type, temp);
+		    }
+		}
+	      else if (TREE_CODE_CLASS (TREE_CODE (op)) == tcc_binary
+		       /* Skip codes that are rejected in safe_to_promote_use_p.  */
+		       && code != LROTATE_EXPR
+		       && code != RROTATE_EXPR
+		       && code != COMPLEX_EXPR)
+		{
+		  tree op0 = TREE_OPERAND (op, 0);
+		  tree op1 = TREE_OPERAND (op, 1);
+		  if (op0 == use || op1 == use)
+		    {
+		      if (TREE_CODE (op0) == INTEGER_CST)
+			op0 = convert_int_cst (promoted_type, op0, SIGNED);
+		      if (TREE_CODE (op1) == INTEGER_CST)
+			op1 = convert_int_cst (promoted_type, op1, SIGNED);
+		      tree temp = build2 (code, promoted_type, op0, op1);
+		      new_op = build1 (NOP_EXPR, old_type, temp);
+		    }
+		}
+
+	      /* Create new GIMPLE_DEBUG stmt with the new value (new_op) to
+		 be bound, if new value has been calculated */
+	      if (new_op)
+		{
+		  if (gimple_debug_bind_p (stmt))
+		    {
+		      copy = gimple_build_debug_bind
+			(gimple_debug_bind_get_var (stmt),
+			 new_op,
+			 stmt);
+		    }
+		  if (gimple_debug_source_bind_p (stmt))
+		    {
+		      copy = gimple_build_debug_source_bind
+			(gimple_debug_source_bind_get_var (stmt), new_op,
+			 stmt);
+		    }
+
+		  if (copy)
+		    {
+		      gsi = gsi_for_stmt (stmt);
+		      gsi_replace (&gsi, copy, false);
+		    }
+		}
 	    }
+	  break;
 
 	case GIMPLE_ASM:
 	case GIMPLE_CALL:
-- 
1.9.1


  reply	other threads:[~2015-10-18 20:04 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-07  2:55 [0/7] Type promotion pass and elimination of zext/sext Kugan
2015-09-07  2:57 ` [1/7] Add new tree code SEXT_EXPR Kugan
2015-09-15 13:20   ` Richard Biener
2015-10-11 10:35     ` Kugan
2015-10-12 12:22       ` Richard Biener
2015-10-15  5:49         ` Kugan
2015-10-21 10:49           ` Richard Biener
2015-09-07  2:58 ` [2/7] Add new type promotion pass Kugan
2015-10-15  5:52   ` Kugan
2015-10-15 22:47     ` Richard Henderson
2015-09-07  3:00 ` [3/7] Optimize ZEXT_EXPR with tree-vrp Kugan
2015-09-15 13:18   ` Richard Biener
2015-10-06 23:12     ` kugan
2015-10-07  8:20       ` Richard Biener
2015-10-07 23:40         ` Kugan
2015-10-09 10:29           ` Richard Biener
2015-10-11  2:56             ` Kugan
2015-10-12 12:13               ` Richard Biener
2015-09-07  3:01 ` [4/7] Use correct promoted mode sign for result of GIMPLE_CALL Kugan
2015-09-07 13:16   ` Michael Matz
2015-09-08  0:00     ` Kugan
2015-09-08 15:45       ` Jeff Law
2015-09-08 22:09         ` Jim Wilson
2015-09-15 12:51           ` Richard Biener
2015-10-07  1:03             ` kugan
2015-09-07  3:01 ` [5/7] Allow gimple debug stmt in widen mode Kugan
2015-09-07 13:46   ` Michael Matz
2015-09-08  0:01     ` Kugan
2015-09-15 13:02       ` Richard Biener
2015-10-15  5:45         ` Kugan
2015-10-16  9:27           ` Richard Biener
2015-10-18 20:51             ` Kugan [this message]
2015-09-07  3:03 ` [6/7] Temporary workaround to get aarch64 bootstrap Kugan
2015-09-07  3:03 ` [5/7] Allow gimple debug stmt in widen mode Kugan
2015-09-07  5:54 ` [7/7] Adjust-arm-test cases Kugan
2015-11-02 11:43   ` Richard Earnshaw
2015-10-20 20:13 ` [0/7] Type promotion pass and elimination of zext/sext Kugan
2015-10-21 12:56   ` Richard Biener
2015-10-21 13:57     ` Richard Biener
2015-10-21 17:17       ` Joseph Myers
2015-10-21 18:11       ` Richard Henderson
2015-10-22 12:48         ` Richard Biener
2015-10-22 11:01     ` Kugan
2015-10-22 14:24       ` Richard Biener
2015-10-27  1:48         ` kugan
2015-10-28 15:51           ` Richard Biener
2015-11-02  9:17             ` Kugan
2015-11-03 14:40               ` Richard Biener
2015-11-08  9:43                 ` Kugan
2015-11-10 14:13                   ` Richard Biener
2015-11-12  6:08                     ` Kugan
2015-11-14  1:15                     ` Kugan
2015-11-18 14:04                       ` Richard Biener
2015-11-18 15:06                         ` Richard Biener
2015-11-24  2:52                           ` Kugan
2015-12-10  0:27                             ` Kugan
2015-12-16 13:18                               ` 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=5623FB27.6090301@linaro.org \
    --to=kugan.vivekanandarajah@linaro.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=matz@suse.de \
    --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).