diff mbox

[5/7] Allow gimple debug stmt in widen mode

Message ID 5623FB27.6090301@linaro.org
State New
Headers show

Commit Message

Kugan Vivekanandarajah Oct. 18, 2015, 8:03 p.m. UTC
> 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
diff mbox

Patch

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