public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Kugan <kugan.vivekanandarajah@linaro.org>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Richard Henderson <rth@redhat.com>,
	 "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH 1/2] Enable setting sign and unsigned promoted mode (SPR_SIGNED_AND_UNSIGNED)
Date: Mon, 07 Jul 2014 06:52:00 -0000	[thread overview]
Message-ID: <53BA43B7.6050901@linaro.org> (raw)
In-Reply-To: <53B26F8E.7050205@linaro.org>

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

On 01/07/14 18:21, Kugan wrote:
> On 26/06/14 20:12, Jakub Jelinek wrote:
>> On Thu, Jun 26, 2014 at 07:41:22PM +1000, Kugan wrote:
>>> 2014-06-26  Kugan Vivekanandarajah  <kuganv@linaro.org>
>>>
>>> 	* calls.c (precompute_arguments): Use new SUBREG_PROMOTED_SET
>>> 	instead of SUBREG_PROMOTED_UNSIGNED_SET
>>
>> Missing full stop.
>>
>>> --- a/gcc/cfgexpand.c
>>> +++ b/gcc/cfgexpand.c
>>> @@ -3297,7 +3297,7 @@ expand_gimple_stmt_1 (gimple stmt)
>>>  	      ;
>>>  	    else if (promoted)
>>>  	      {
>>> -		int unsignedp = SUBREG_PROMOTED_UNSIGNED_P (target);
>>> +		int unsignedp = SUBREG_PROMOTED_GET (target) & SRP_UNSIGNED;
>>
>> From what I understand, here you want the -1/0/1 value and not 2,
>> so that is
>> int unsignedp = SUBREG_PROMOTED_GET (target);
>> if (unsignedp == SRP_SIGNED_AND_UNSIGNED) unsignedp = SRP_UNSIGNED;
>> I think.  Do you agree?
> 
> I agree.
> 
> 
>> BTW, the final patch will probably need to be tested on one of the weirdo
>> ptr_extend targets (ia64-hpux or x86_64-linux -mx32).
> 
> I am now looking at testing on such targets. I just want to double check
> that x86_64-linux -mx32 is OK for this. When I looked at the src, it
> looked to me #define POINTERS_EXTEND_UNSIGNED -1 is needed for this to
> happen. x86_64-linux -mx32 doesnt seem to fall into thss.
> 
> In addition, I will also test AArch64 ILP32 (#define
> POINTERS_EXTEND_UNSIGNED 1), ARM and x86_64 before posting the patch.
> 
>>> --- a/gcc/expr.c
>>> +++ b/gcc/expr.c
>>> @@ -329,7 +329,7 @@ convert_move (rtx to, rtx from, int unsignedp)
>>>    if (GET_CODE (from) == SUBREG && SUBREG_PROMOTED_VAR_P (from)
>>>        && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from)))
>>>  	  >= GET_MODE_PRECISION (to_mode))
>>> -      && SUBREG_PROMOTED_UNSIGNED_P (from) == unsignedp)
>>> +      && SUBREG_CHECK_PROMOTED_SIGN (from, unsignedp))
>>
>> I think unsignedp (misnamed) may be -1/0/1 here, so either
>> SUBREG_CHECK_PROMOTED_SIGN needs to handle those 3, or you need to use
>> something else.  If it handles all 3 values, then it would be say
>> ((SIGN) == SRP_POINTER ? SUBREG_PROMOTED_GET (RTX) == SRP_POINTER
>>  : (SIGN) == SRP_SIGNED ? SUBREG_PROMOTED_SIGNED_P (RTX)
>>  : SUBREG_PROMOTED_UNSIGNED_P (RTX))
>> or so.
> 
> I have changed it. I have defined a macro SUBREG_PROMOTED_SIGN for this.
> 
>>
>>>      from = gen_lowpart (to_mode, from), from_mode = to_mode;
>>>  
>>>    gcc_assert (GET_CODE (to) != SUBREG || !SUBREG_PROMOTED_VAR_P (to));
>>> @@ -703,7 +703,7 @@ convert_modes (enum machine_mode mode, enum machine_mode oldmode, rtx x, int uns
>>>  
>>>    if (GET_CODE (x) == SUBREG && SUBREG_PROMOTED_VAR_P (x)
>>>        && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) >= GET_MODE_SIZE (mode)
>>> -      && SUBREG_PROMOTED_UNSIGNED_P (x) == unsignedp)
>>> +      && SUBREG_CHECK_PROMOTED_SIGN (x, unsignedp))
>>>      x = gen_lowpart (mode, SUBREG_REG (x));
>>
>> Similarly.
> 
> 
> I have changed it too.
> 
>>
>>> @@ -5203,24 +5203,25 @@ store_expr (tree exp, rtx target, int call_param_p, bool nontemporal)
>>>  	     == TYPE_PRECISION (TREE_TYPE (exp)))
>>>  	{
>>>  	  if (TYPE_UNSIGNED (TREE_TYPE (exp))
>>> -	      != SUBREG_PROMOTED_UNSIGNED_P (target))
>>> +	      != SUBREG_PROMOTED_GET (target) & SRP_UNSIGNED)
>>
>> Here TYPE_UNSIGNED is 0 or 1, so if you define SUBREG_PROMOTED_CHECK_SIGN
>> the way suggested above, this would be SUBREG_PROMOTED_CHECK_SIGN then,
>> or if (TYPE_UNSIGNED (TREE_TYPE (exp))
>>        ? SUBREG_PROMOTED_UNSIGNED_P (target)
>>        : SUBREG_PROMOTED_SIGNED_P (target))
>>
>>>  	    {
>>>  	      /* Some types, e.g. Fortran's logical*4, won't have a signed
>>>  		 version, so use the mode instead.  */
>>>  	      tree ntype
>>>  		= (signed_or_unsigned_type_for
>>> -		   (SUBREG_PROMOTED_UNSIGNED_P (target), TREE_TYPE (exp)));
>>> +		   (SUBREG_PROMOTED_GET (target) & SRP_UNSIGNED,
>>
>> I'd just use TYPE_UNSIGNED (TREE_TYPE (exp)) here instead,
>> no reason to repeat what the guarding condition did.
> 
> Did you mean !TYPE_UNSIGNED (TREE_TYPE (exp))?. isn’t it better to use
> the macro SUBREG_PROMOTED_SIGN (defined earlier as you suggested) here?
> It might be more readable. I am happy to do what you like.
> 
>>
>>> +		    TREE_TYPE (exp)));
>>>  	      if (ntype == NULL)
>>>  		ntype = lang_hooks.types.type_for_mode
>>>  		  (TYPE_MODE (TREE_TYPE (exp)),
>>> -		   SUBREG_PROMOTED_UNSIGNED_P (target));
>>> +		   SUBREG_PROMOTED_GET (target) & SRP_UNSIGNED);
>>>  
>>>  	      exp = fold_convert_loc (loc, ntype, exp);
>>>  	    }
>>>  
>>>  	  exp = fold_convert_loc (loc, lang_hooks.types.type_for_mode
>>>  				  (GET_MODE (SUBREG_REG (target)),
>>> -				   SUBREG_PROMOTED_UNSIGNED_P (target)),
>>> +				   SUBREG_PROMOTED_GET (target) & SRP_UNSIGNED),
>>>  				  exp);
>>
>> I believe fold_convert only considers zero and non-zero, so no idea
>> what we want here for SRP_POINTER.  Doing what we used to do would
>> be SUBREG_PROMOTED_GET (target) != SRP_SIGNED.
>>>  
>>>  	  inner_target = SUBREG_REG (target);
>>> @@ -5234,14 +5235,14 @@ store_expr (tree exp, rtx target, int call_param_p, bool nontemporal)
>>>        if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
>>>  	{
>>>  	  temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
>>> -				temp, SUBREG_PROMOTED_UNSIGNED_P (target));
>>> +				temp, SUBREG_PROMOTED_GET (target) & SRP_UNSIGNED);
>>>  	  temp = convert_modes (GET_MODE (SUBREG_REG (target)),
>>>  			        GET_MODE (target), temp,
>>> -			        SUBREG_PROMOTED_UNSIGNED_P (target));
>>> +			        SUBREG_PROMOTED_GET (target) & SRP_UNSIGNED);
>>>  	}
>>>  
>>>        convert_move (SUBREG_REG (target), temp,
>>> -		    SUBREG_PROMOTED_UNSIGNED_P (target));
>>> +		    SUBREG_PROMOTED_GET (target) & SRP_UNSIGNED);
>>
>> In all 3 cases here you want -1/0/1 and treat SRP_SIGNED_AND_UNSIGNED as
>> probably 1, so supposedly you want a macro for that and use it
>> in the 3 cases here, in expand_gimple_stmt_1 etc.
> 
> I have changed this.
> 
>>> --- a/gcc/rtl.h
>>> +++ b/gcc/rtl.h
>>> @@ -1585,29 +1585,67 @@ get_full_set_src_cost (rtx x, struct full_rtx_costs *c)
>>>  #define SUBREG_PROMOTED_VAR_P(RTX)					\
>>>    (RTL_FLAG_CHECK1 ("SUBREG_PROMOTED", (RTX), SUBREG)->in_struct)
>>>  
>>> -#define SUBREG_PROMOTED_UNSIGNED_SET(RTX, VAL)				\
>>> -do {									\
>>> -  rtx const _rtx = RTL_FLAG_CHECK1 ("SUBREG_PROMOTED_UNSIGNED_SET",	\
>>> -				    (RTX), SUBREG);			\
>>> -  if ((VAL) < 0)							\
>>> -    _rtx->volatil = 1;							\
>>> -  else {								\
>>> -    _rtx->volatil = 0;							\
>>> -    _rtx->unchanging = (VAL);						\
>>> -  }									\
>>> -} while (0)
>>> -
>>>  /* Valid for subregs which are SUBREG_PROMOTED_VAR_P().  In that case
>>>     this gives the necessary extensions:
>>> -   0  - signed
>>> -   1  - normal unsigned
>>> +   0  - signed (SPR_SIGNED)
>>> +   1  - normal unsigned (SPR_UNSIGNED)
>>> +   2  - value is both sign and unsign extended for mode
>>> +	(SPR_SIGNED_AND_UNSIGNED).
>>>     -1 - pointer unsigned, which most often can be handled like unsigned
>>>          extension, except for generating instructions where we need to
>>> -	emit special code (ptr_extend insns) on some architectures.  */
>>> +	emit special code (ptr_extend insns) on some architectures
>>> +	(SPR_POINTER). */
>>> +
>>> +const unsigned int SRP_POINTER = -1;
>>> +const unsigned int SRP_SIGNED = 0;
>>> +const unsigned int SRP_UNSIGNED = 1;
>>> +const unsigned int SRP_SIGNED_AND_UNSIGNED = 2;
>>> +
>>> +/* Sets promoted mode for SUBREG_PROMOTED_VAR_P().  */
>>> +#define SUBREG_PROMOTED_SET(RTX, VAL)		                        \
>>> +do {								        \
>>> +  rtx const _rtx = RTL_FLAG_CHECK1 ("SUBREG_PROMOTED_SET",		\
>>> +                                    (RTX), SUBREG);			\
>>> +  switch ((VAL))							\
>>
>> Please avoid the extra ()s, switch (VAL) is enough.
>>
>>> +/* Checks if RTX of SUBREG_PROMOTED_VAR_P() is promotd for given SIGN.  */
>>
>> promoted, typo.
>>
>>> +#define SUBREG_CHECK_PROMOTED_SIGN(RTX, SIGN)	\
>>> +  ((SIGN) ? SUBREG_PROMOTED_GET ((RTX)) != SRP_SIGNED	\
>>> +   : SUBREG_PROMOTED_SIGNED_P ((RTX)))
>>
>> See above.  And note the ((RTX)) should have been (RTX) anyway.
>>
>>> @@ -5587,7 +5587,8 @@ simplify_subreg (enum machine_mode outermode, rtx op,
>>>  	{
>>>  	  newx = gen_rtx_SUBREG (outermode, SUBREG_REG (op), final_offset);
>>>  	  if (SUBREG_PROMOTED_VAR_P (op)
>>> -	      && SUBREG_PROMOTED_UNSIGNED_P (op) >= 0
>>> +	      && (SUBREG_PROMOTED_UNSIGNED_P (op)
>>> +		  || (SUBREG_PROMOTED_SIGNED_P (op)))
>>
>> SUBREG_PROMOTED_GET (op) != SRP_POINTER ?
>> Also note the extra ()s.
>>
>>>  	      && GET_MODE_CLASS (outermode) == MODE_INT
>>>  	      && IN_RANGE (GET_MODE_SIZE (outermode),
>>>  			   GET_MODE_SIZE (innermode),
>>> @@ -5595,8 +5596,7 @@ simplify_subreg (enum machine_mode outermode, rtx op,
>>>  	      && subreg_lowpart_p (newx))
>>>  	    {
>>>  	      SUBREG_PROMOTED_VAR_P (newx) = 1;
>>> -	      SUBREG_PROMOTED_UNSIGNED_SET
>>> -		(newx, SUBREG_PROMOTED_UNSIGNED_P (op));
>>> +	      SUBREG_PROMOTED_SET (newx, SUBREG_PROMOTED_GET (op));
>>>  	    }
>>>  	  return newx;
>>>  	}
>>
> 
> I have changed the above as well. I will post the patch after testing
> for all the necessary targets.
> 

Hi Jakub,

Please find the patch that addresses these comments.

I have bootstrapped on x86_64-unknown-linux-gnu and regression tested
for x86_64-unknown-linux-gnu, arm-none-linux-gnueabi (using qemu),
aarch64_be-none-elf (Foundation model), aarch64-none-elf
--with-abi=ilp32 (Foundation model) and s390x-ibm-linux (64bit, using
qemu) with no new regression.

Is this OK?

Thanks,
Kugan


gcc/
2014-07-07  Kugan Vivekanandarajah  <kuganv@linaro.org>

	* calls.c (precompute_arguments): Use new SUBREG_PROMOTED_SET
	instead of SUBREG_PROMOTED_UNSIGNED_SET.
	(expand_call): Likewise.
	* cfgexpand.c (expand_gimple_stmt_1): Use SUBREG_PROMOTED_SIGN
	to get promoted mode.
	* combine.c (record_promoted_value): Skip > 0 comparison with
	SUBREG_PROMOTED_UNSIGNED_P as it now returns only 0 or 1.
	* expr.c (convert_move): Use SUBREG_CHECK_PROMOTED_SIGN instead
	of SUBREG_PROMOTED_UNSIGNED_P.
	(convert_modes): Likewise.
	(store_expr): Use SUBREG_PROMOTED_SIGN to get promoted mode.
	Use SUBREG_CHECK_PROMOTED_SIGN instead of SUBREG_PROMOTED_UNSIGNED_P.
	(expand_expr_real_1): Use new SUBREG_PROMOTED_SET instead of
	SUBREG_PROMOTED_UNSIGNED_SET.
	* function.c (assign_parm_setup_reg): Use new SUBREG_PROMOTED_SET
	instead of SUBREG_PROMOTED_UNSIGNED_SET.
	* ifcvt.c (noce_emit_cmove): Updated to use SUBREG_PROMOTED_GET and
	SUBREG_PROMOTED_SET.
	* internal-fn.c (ubsan_expand_si_overflow_mul_check): Use
	SUBREG_PROMOTED_SET instead of SUBREG_PROMOTED_UNSIGNED_SET.
	* optabs.c (widen_operand): Use SUBREG_CHECK_PROMOTED_SIGN instead
	of SUBREG_PROMOTED_UNSIGNED_P.
	* rtl.h (SUBREG_PROMOTED_UNSIGNED_SET): Remove.
	(SUBREG_PROMOTED_SET): New define.
	(SUBREG_PROMOTED_GET): Likewise.
	(SUBREG_PROMOTED_SIGN): Likewise.
	(SUBREG_PROMOTED_SIGNED_P): Likewise.
	(SUBREG_CHECK_PROMOTED_SIGN): Likewise.
	(SUBREG_PROMOTED_UNSIGNED_P): Updated.
	* rtlanal.c (unsigned_reg_p): Use new SUBREG_PROMOTED_SIGN
	instead of SUBREG_PROMOTED_UNSIGNED_GET.
	(nonzero_bits1): Skip > 0 comparison with the results as
	SUBREG_PROMOTED_UNSIGNED_P now returns only 0 or 1.
	(num_sign_bit_copies1): Use SUBREG_PROMOTED_SIGNED_P instead
	of !SUBREG_PROMOTED_UNSIGNED_P.
	* simplify-rtx.c (simplify_unary_operation_1): Use new
	SUBREG_PROMOTED_SIGNED_P instead of !SUBREG_PROMOTED_UNSIGNED_P.
	(simplify_subreg): Use new SUBREG_PROMOTED_SIGNED_P,
	and SUBREG_PROMOTED_SET.



[-- Attachment #2: p1.txt --]
[-- Type: text/plain, Size: 14657 bytes --]

diff --git a/gcc/calls.c b/gcc/calls.c
index 78fe7d8..a3e6faa 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -1484,8 +1484,7 @@ precompute_arguments (int num_actuals, struct arg_data *args)
 	      args[i].initial_value
 		= gen_lowpart_SUBREG (mode, args[i].value);
 	      SUBREG_PROMOTED_VAR_P (args[i].initial_value) = 1;
-	      SUBREG_PROMOTED_UNSIGNED_SET (args[i].initial_value,
-					    args[i].unsignedp);
+	      SUBREG_PROMOTED_SET (args[i].initial_value, args[i].unsignedp);
 	    }
 	}
     }
@@ -3365,7 +3364,7 @@ expand_call (tree exp, rtx target, int ignore)
 
 	  target = gen_rtx_SUBREG (TYPE_MODE (type), target, offset);
 	  SUBREG_PROMOTED_VAR_P (target) = 1;
-	  SUBREG_PROMOTED_UNSIGNED_SET (target, unsignedp);
+	  SUBREG_PROMOTED_SET (target, unsignedp);
 	}
 
       /* If size of args is variable or this was a constructor call for a stack
diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index e8cd87f..b7a34a2 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -3297,7 +3297,7 @@ expand_gimple_stmt_1 (gimple stmt)
 	      ;
 	    else if (promoted)
 	      {
-		int unsignedp = SUBREG_PROMOTED_UNSIGNED_P (target);
+		int unsignedp = SUBREG_PROMOTED_SIGN (target);
 		/* If TEMP is a VOIDmode constant, use convert_modes to make
 		   sure that we properly convert it.  */
 		if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
diff --git a/gcc/combine.c b/gcc/combine.c
index 4e7ef55..15ecf1a 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -12427,7 +12427,7 @@ record_promoted_value (rtx insn, rtx subreg)
       rsp = &reg_stat[regno];
       if (rsp->last_set == insn)
 	{
-	  if (SUBREG_PROMOTED_UNSIGNED_P (subreg) > 0)
+	  if (SUBREG_PROMOTED_UNSIGNED_P (subreg))
 	    rsp->last_set_nonzero_bits &= GET_MODE_MASK (mode);
 	}
 
diff --git a/gcc/expr.c b/gcc/expr.c
index 512c024..10f4a96 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -329,7 +329,7 @@ convert_move (rtx to, rtx from, int unsignedp)
   if (GET_CODE (from) == SUBREG && SUBREG_PROMOTED_VAR_P (from)
       && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from)))
 	  >= GET_MODE_PRECISION (to_mode))
-      && SUBREG_PROMOTED_UNSIGNED_P (from) == unsignedp)
+      && SUBREG_CHECK_PROMOTED_SIGN (from, unsignedp))
     from = gen_lowpart (to_mode, from), from_mode = to_mode;
 
   gcc_assert (GET_CODE (to) != SUBREG || !SUBREG_PROMOTED_VAR_P (to));
@@ -703,7 +703,7 @@ convert_modes (enum machine_mode mode, enum machine_mode oldmode, rtx x, int uns
 
   if (GET_CODE (x) == SUBREG && SUBREG_PROMOTED_VAR_P (x)
       && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) >= GET_MODE_SIZE (mode)
-      && SUBREG_PROMOTED_UNSIGNED_P (x) == unsignedp)
+      && SUBREG_CHECK_PROMOTED_SIGN (x, unsignedp))
     x = gen_lowpart (mode, SUBREG_REG (x));
 
   if (GET_MODE (x) != VOIDmode)
@@ -5202,25 +5202,25 @@ store_expr (tree exp, rtx target, int call_param_p, bool nontemporal)
 	  && GET_MODE_PRECISION (GET_MODE (target))
 	     == TYPE_PRECISION (TREE_TYPE (exp)))
 	{
-	  if (TYPE_UNSIGNED (TREE_TYPE (exp))
-	      != SUBREG_PROMOTED_UNSIGNED_P (target))
+	  if (!SUBREG_CHECK_PROMOTED_SIGN (target,
+					  TYPE_UNSIGNED (TREE_TYPE (exp))))
 	    {
 	      /* Some types, e.g. Fortran's logical*4, won't have a signed
 		 version, so use the mode instead.  */
 	      tree ntype
 		= (signed_or_unsigned_type_for
-		   (SUBREG_PROMOTED_UNSIGNED_P (target), TREE_TYPE (exp)));
+		   (SUBREG_PROMOTED_SIGN (target), TREE_TYPE (exp)));
 	      if (ntype == NULL)
 		ntype = lang_hooks.types.type_for_mode
 		  (TYPE_MODE (TREE_TYPE (exp)),
-		   SUBREG_PROMOTED_UNSIGNED_P (target));
+		   SUBREG_PROMOTED_SIGN (target));
 
 	      exp = fold_convert_loc (loc, ntype, exp);
 	    }
 
 	  exp = fold_convert_loc (loc, lang_hooks.types.type_for_mode
 				  (GET_MODE (SUBREG_REG (target)),
-				   SUBREG_PROMOTED_UNSIGNED_P (target)),
+				   SUBREG_PROMOTED_SIGN (target)),
 				  exp);
 
 	  inner_target = SUBREG_REG (target);
@@ -5234,14 +5234,14 @@ store_expr (tree exp, rtx target, int call_param_p, bool nontemporal)
       if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
 	{
 	  temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
-				temp, SUBREG_PROMOTED_UNSIGNED_P (target));
+				temp, SUBREG_PROMOTED_SIGN (target));
 	  temp = convert_modes (GET_MODE (SUBREG_REG (target)),
 			        GET_MODE (target), temp,
-			        SUBREG_PROMOTED_UNSIGNED_P (target));
+				SUBREG_PROMOTED_SIGN (target));
 	}
 
       convert_move (SUBREG_REG (target), temp,
-		    SUBREG_PROMOTED_UNSIGNED_P (target));
+		    SUBREG_PROMOTED_SIGN (target));
 
       return NULL_RTX;
     }
@@ -9513,7 +9513,7 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
 
 	  temp = gen_lowpart_SUBREG (mode, decl_rtl);
 	  SUBREG_PROMOTED_VAR_P (temp) = 1;
-	  SUBREG_PROMOTED_UNSIGNED_SET (temp, unsignedp);
+	  SUBREG_PROMOTED_SET (temp, unsignedp);
 	  return temp;
 	}
 
diff --git a/gcc/function.c b/gcc/function.c
index 441289e..9509622 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -3093,7 +3093,7 @@ assign_parm_setup_reg (struct assign_parm_data_all *all, tree parm,
 	  /* The argument is already sign/zero extended, so note it
 	     into the subreg.  */
 	  SUBREG_PROMOTED_VAR_P (tempreg) = 1;
-	  SUBREG_PROMOTED_UNSIGNED_SET (tempreg, unsignedp);
+	  SUBREG_PROMOTED_SET (tempreg, unsignedp);
 	}
 
       /* TREE_USED gets set erroneously during expand_assignment.  */
diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c
index 816cdaa..56e2f3a 100644
--- a/gcc/ifcvt.c
+++ b/gcc/ifcvt.c
@@ -1448,8 +1448,8 @@ noce_emit_cmove (struct noce_if_info *if_info, rtx x, enum rtx_code code,
 	  || byte_vtrue != byte_vfalse
 	  || (SUBREG_PROMOTED_VAR_P (vtrue)
 	      != SUBREG_PROMOTED_VAR_P (vfalse))
-	  || (SUBREG_PROMOTED_UNSIGNED_P (vtrue)
-	      != SUBREG_PROMOTED_UNSIGNED_P (vfalse)))
+	  || (SUBREG_PROMOTED_GET (vtrue)
+	      != SUBREG_PROMOTED_GET (vfalse)))
 	return NULL_RTX;
 
       promoted_target = gen_reg_rtx (GET_MODE (reg_vtrue));
@@ -1463,7 +1463,7 @@ noce_emit_cmove (struct noce_if_info *if_info, rtx x, enum rtx_code code,
 
       target = gen_rtx_SUBREG (GET_MODE (vtrue), promoted_target, byte_vtrue);
       SUBREG_PROMOTED_VAR_P (target) = SUBREG_PROMOTED_VAR_P (vtrue);
-      SUBREG_PROMOTED_UNSIGNED_SET (target, SUBREG_PROMOTED_UNSIGNED_P (vtrue));
+      SUBREG_PROMOTED_SET (target, SUBREG_PROMOTED_GET (vtrue));
       emit_move_insn (x, target);
       return x;
     }
diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c
index 78f59d6..4e0b964 100644
--- a/gcc/internal-fn.c
+++ b/gcc/internal-fn.c
@@ -584,12 +584,12 @@ ubsan_expand_si_overflow_mul_check (gimple stmt)
 	  if (GET_CODE (lopart0) == SUBREG)
 	    {
 	      SUBREG_PROMOTED_VAR_P (lopart0) = 1;
-	      SUBREG_PROMOTED_UNSIGNED_SET (lopart0, 0);
+	      SUBREG_PROMOTED_SET (lopart0, 0);
 	    }
 	  if (GET_CODE (lopart1) == SUBREG)
 	    {
 	      SUBREG_PROMOTED_VAR_P (lopart1) = 1;
-	      SUBREG_PROMOTED_UNSIGNED_SET (lopart1, 0);
+	      SUBREG_PROMOTED_SET (lopart1, 0);
 	    }
 	  tree halfstype = build_nonstandard_integer_type (hprec, 0);
 	  ops.op0 = make_tree (halfstype, lopart0);
diff --git a/gcc/optabs.c b/gcc/optabs.c
index ca1c194..a00b383 100644
--- a/gcc/optabs.c
+++ b/gcc/optabs.c
@@ -368,7 +368,7 @@ widen_operand (rtx op, enum machine_mode mode, enum machine_mode oldmode,
      a promoted object differs from our extension.  */
   if (! no_extend
       || (GET_CODE (op) == SUBREG && SUBREG_PROMOTED_VAR_P (op)
-	  && SUBREG_PROMOTED_UNSIGNED_P (op) == unsignedp))
+	  && SUBREG_CHECK_PROMOTED_SIGN (op, unsignedp)))
     return convert_modes (mode, oldmode, op, unsignedp);
 
   /* If MODE is no wider than a single word, we return a lowpart or paradoxical
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 6ec91a8..38f9f69 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -1585,35 +1585,81 @@ get_full_set_src_cost (rtx x, struct full_rtx_costs *c)
 #define SUBREG_PROMOTED_VAR_P(RTX)					\
   (RTL_FLAG_CHECK1 ("SUBREG_PROMOTED", (RTX), SUBREG)->in_struct)
 
-#define SUBREG_PROMOTED_UNSIGNED_SET(RTX, VAL)				\
-do {									\
-  rtx const _rtx = RTL_FLAG_CHECK1 ("SUBREG_PROMOTED_UNSIGNED_SET",	\
-				    (RTX), SUBREG);			\
-  if ((VAL) < 0)							\
-    _rtx->volatil = 1;							\
-  else {								\
-    _rtx->volatil = 0;							\
-    _rtx->unchanging = (VAL);						\
-  }									\
-} while (0)
-
 /* Valid for subregs which are SUBREG_PROMOTED_VAR_P().  In that case
    this gives the necessary extensions:
-   0  - signed
-   1  - normal unsigned
+   0  - signed (SPR_SIGNED)
+   1  - normal unsigned (SPR_UNSIGNED)
+   2  - value is both sign and unsign extended for mode
+	(SPR_SIGNED_AND_UNSIGNED).
    -1 - pointer unsigned, which most often can be handled like unsigned
         extension, except for generating instructions where we need to
-	emit special code (ptr_extend insns) on some architectures.  */
+	emit special code (ptr_extend insns) on some architectures
+	(SPR_POINTER). */
+
+const int SRP_POINTER = -1;
+const int SRP_SIGNED = 0;
+const int SRP_UNSIGNED = 1;
+const int SRP_SIGNED_AND_UNSIGNED = 2;
+
+/* Sets promoted mode for SUBREG_PROMOTED_VAR_P().  */
+#define SUBREG_PROMOTED_SET(RTX, VAL)		                        \
+do {								        \
+  rtx const _rtx = RTL_FLAG_CHECK1 ("SUBREG_PROMOTED_SET",		\
+                                    (RTX), SUBREG);			\
+  switch (VAL)								\
+  {									\
+    case SRP_POINTER:							\
+      _rtx->volatil = 0;						\
+      _rtx->unchanging = 0;						\
+      break;								\
+    case SRP_SIGNED:							\
+      _rtx->volatil = 0;						\
+      _rtx->unchanging = 1;						\
+      break;								\
+    case SRP_UNSIGNED:							\
+      _rtx->volatil = 1;						\
+      _rtx->unchanging = 0;						\
+      break;								\
+    case SRP_SIGNED_AND_UNSIGNED:					\
+      _rtx->volatil = 1;						\
+      _rtx->unchanging = 1;						\
+      break;								\
+  }									\
+} while (0)
 
+/* Gets the value stored in promoted mode for SUBREG_PROMOTED_VAR_P(),
+   including SRP_SIGNED_AND_UNSIGNED if promoted for
+   both signed and unsigned.  */
+#define SUBREG_PROMOTED_GET(RTX)	\
+  (2 * (RTL_FLAG_CHECK1 ("SUBREG_PROMOTED_GET", (RTX), SUBREG)->volatil)\
+   + (RTX)->unchanging - 1)
+
+/* Predicate to check if RTX of SUBREG_PROMOTED_VAR_P() is promoted
+   for SIGNED type.  */
+#define SUBREG_PROMOTED_SIGNED_P(RTX)	\
+  (RTL_FLAG_CHECK1 ("SUBREG_PROMOTED_SIGNED_P", (RTX), SUBREG)->unchanging)
+
+/* Predicate to check if RTX of SUBREG_PROMOTED_VAR_P() is promoted
+   for UNSIGNED type.  */
 #define SUBREG_PROMOTED_UNSIGNED_P(RTX)	\
-  ((RTL_FLAG_CHECK1 ("SUBREG_PROMOTED_UNSIGNED_P", (RTX), SUBREG)->volatil) \
-   ? -1 : (int) (RTX)->unchanging)
+  (RTL_FLAG_CHECK1 ("SUBREG_PROMOTED_UNSIGNED_P", (RTX), SUBREG)->volatil)
+
+/* Checks if RTX of SUBREG_PROMOTED_VAR_P() is promoted for given SIGN.  */
+#define SUBREG_CHECK_PROMOTED_SIGN(RTX, SIGN)	\
+((SIGN) == SRP_POINTER ? SUBREG_PROMOTED_GET (RTX) == SRP_POINTER	\
+ : (SIGN) == SRP_SIGNED ? SUBREG_PROMOTED_SIGNED_P (RTX)		\
+ : SUBREG_PROMOTED_UNSIGNED_P (RTX))
 
 /* True if the subreg was generated by LRA for reload insns.  Such
    subregs are valid only during LRA.  */
 #define LRA_SUBREG_P(RTX)	\
   (RTL_FLAG_CHECK1 ("LRA_SUBREG_P", (RTX), SUBREG)->jump)
 
+/* Returns sign of promoted mode for SUBREG_PROMOTED_VAR_P().  */
+#define SUBREG_PROMOTED_SIGN(RTX)	\
+  ((RTL_FLAG_CHECK1 ("SUBREG_PROMOTED_SIGN", (RTX), SUBREG)->volatil) ? 1\
+   : (RTX)->unchanging - 1)
+
 /* Access various components of an ASM_OPERANDS rtx.  */
 
 #define ASM_OPERANDS_TEMPLATE(RTX) XCSTR (RTX, 0, ASM_OPERANDS)
diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c
index 82cfc1bf..76e7628 100644
--- a/gcc/rtlanal.c
+++ b/gcc/rtlanal.c
@@ -670,7 +670,7 @@ unsigned_reg_p (rtx op)
     return true;
 
   if (GET_CODE (op) == SUBREG
-      && SUBREG_PROMOTED_UNSIGNED_P (op))
+      && SUBREG_PROMOTED_SIGN (op))
     return true;
 
   return false;
@@ -4309,7 +4309,7 @@ nonzero_bits1 (const_rtx x, enum machine_mode mode, const_rtx known_x,
 	 been zero-extended, we know that at least the high-order bits
 	 are zero, though others might be too.  */
 
-      if (SUBREG_PROMOTED_VAR_P (x) && SUBREG_PROMOTED_UNSIGNED_P (x) > 0)
+      if (SUBREG_PROMOTED_VAR_P (x) && SUBREG_PROMOTED_UNSIGNED_P (x))
 	nonzero = GET_MODE_MASK (GET_MODE (x))
 		  & cached_nonzero_bits (SUBREG_REG (x), GET_MODE (x),
 					 known_x, known_mode, known_ret);
@@ -4619,7 +4619,7 @@ num_sign_bit_copies1 (const_rtx x, enum machine_mode mode, const_rtx known_x,
 	 and we are looking at it in a wider mode, we know that at least the
 	 high-order bits are known to be sign bit copies.  */
 
-      if (SUBREG_PROMOTED_VAR_P (x) && ! SUBREG_PROMOTED_UNSIGNED_P (x))
+      if (SUBREG_PROMOTED_VAR_P (x) && SUBREG_PROMOTED_SIGNED_P (x))
 	{
 	  num0 = cached_num_sign_bit_copies (SUBREG_REG (x), mode,
 					     known_x, known_mode, known_ret);
diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
index 181b56f..6a35a5f 100644
--- a/gcc/simplify-rtx.c
+++ b/gcc/simplify-rtx.c
@@ -1352,7 +1352,7 @@ simplify_unary_operation_1 (enum rtx_code code, enum machine_mode mode, rtx op)
 	 target mode is the same as the variable's promotion.  */
       if (GET_CODE (op) == SUBREG
 	  && SUBREG_PROMOTED_VAR_P (op)
-	  && ! SUBREG_PROMOTED_UNSIGNED_P (op)
+	  && SUBREG_PROMOTED_SIGNED_P (op)
 	  && GET_MODE_SIZE (mode) <= GET_MODE_SIZE (GET_MODE (XEXP (op, 0))))
 	{
 	  temp = rtl_hooks.gen_lowpart_no_emit (mode, op);
@@ -1419,7 +1419,7 @@ simplify_unary_operation_1 (enum rtx_code code, enum machine_mode mode, rtx op)
 	 target mode is the same as the variable's promotion.  */
       if (GET_CODE (op) == SUBREG
 	  && SUBREG_PROMOTED_VAR_P (op)
-	  && SUBREG_PROMOTED_UNSIGNED_P (op) > 0
+	  && SUBREG_PROMOTED_UNSIGNED_P (op)
 	  && GET_MODE_SIZE (mode) <= GET_MODE_SIZE (GET_MODE (XEXP (op, 0))))
 	{
 	  temp = rtl_hooks.gen_lowpart_no_emit (mode, op);
@@ -5587,7 +5587,7 @@ simplify_subreg (enum machine_mode outermode, rtx op,
 	{
 	  newx = gen_rtx_SUBREG (outermode, SUBREG_REG (op), final_offset);
 	  if (SUBREG_PROMOTED_VAR_P (op)
-	      && SUBREG_PROMOTED_UNSIGNED_P (op) >= 0
+	      && SUBREG_PROMOTED_SIGN (op) >= 0
 	      && GET_MODE_CLASS (outermode) == MODE_INT
 	      && IN_RANGE (GET_MODE_SIZE (outermode),
 			   GET_MODE_SIZE (innermode),
@@ -5595,8 +5595,7 @@ simplify_subreg (enum machine_mode outermode, rtx op,
 	      && subreg_lowpart_p (newx))
 	    {
 	      SUBREG_PROMOTED_VAR_P (newx) = 1;
-	      SUBREG_PROMOTED_UNSIGNED_SET
-		(newx, SUBREG_PROMOTED_UNSIGNED_P (op));
+	      SUBREG_PROMOTED_SET (newx, SUBREG_PROMOTED_GET (op));
 	    }
 	  return newx;
 	}

  reply	other threads:[~2014-07-07  6:52 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-24 11:48 [PATCH 0/2] Zext/sext elimination using value range Kugan
2014-06-24 11:51 ` [PATCH 1/2] Enable setting sign and unsigned promoted mode (SPR_SIGNED_AND_UNSIGNED) Kugan
2014-06-24 12:18   ` Jakub Jelinek
2014-06-25  7:21     ` Kugan
2014-06-25  7:50       ` Jakub Jelinek
2014-06-26  1:06         ` Kugan
2014-06-26  2:48           ` Kugan
2014-06-26  5:50           ` Jakub Jelinek
2014-06-26  9:41             ` Kugan
2014-06-26 10:12               ` Jakub Jelinek
2014-06-26 10:42                 ` Jakub Jelinek
2014-07-01  8:21                 ` Kugan
2014-07-07  6:52                   ` Kugan [this message]
2014-07-07  8:06                     ` Jakub Jelinek
2014-06-26 10:25               ` Andreas Schwab
2014-07-01  8:28                 ` Kugan
2014-06-24 11:53 ` [PATCH 2/2] Enable elimination of zext/sext Kugan
2014-06-24 12:21   ` Jakub Jelinek
2014-06-25  8:15     ` Kugan
2014-06-25  8:36       ` Jakub Jelinek
2014-07-07  6:55         ` Kugan
2014-07-10 12:15           ` Richard Biener
2014-07-11 11:52             ` Kugan
2014-07-11 12:47               ` Richard Biener
2014-07-14  2:58                 ` Kugan
2014-07-14 20:11                   ` Bernhard Reutner-Fischer
2014-07-23 14:22                   ` Richard Biener
2014-08-01  4:51                     ` Kugan
2014-08-01 11:16                       ` Richard Biener
2014-08-01 16:04                         ` Kugan
2014-08-03 23:56                           ` Kugan
2014-08-05 14:18                           ` Richard Biener
2014-08-05 14:21                             ` Jakub Jelinek
2014-08-06 12:09                               ` Richard Biener
2014-08-06 13:22                                 ` Kugan
2014-08-06 13:29                                   ` Richard Biener
2014-08-07  5:25                                     ` Kugan
2014-08-07  8:09                                       ` 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=53BA43B7.6050901@linaro.org \
    --to=kugan.vivekanandarajah@linaro.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=rth@redhat.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).