public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Use CONVERT_EXPR_P and friends in the middle-end
@ 2014-10-31 11:39 Richard Biener
  2014-10-31 19:02 ` Joseph S. Myers
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2014-10-31 11:39 UTC (permalink / raw)
  To: GCC Patches

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

This fixes the few places where explicit checks for NOP_EXPR
or CONVERT_EXPRs crept in.

A noticable change may be the tree-eh.c one where we previously
considered FP NOP_EXPRs trapping if flag_trapping_math
("Any fp arithmetic may trap") but now like FP CONVERT_EXPRs
only when honor_nans (but for some reason the honor_nans
cases don't check flag_trapping_math).  I'm not 100% sure which
variant is more correct (this is FP <-> FP conversions thus
widenings, truncations, converts from/to DFP).

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Richard.

2014-10-31  Richard Biener  <rguenther@suse.de>

        * builtins.c (fold_builtin_atomic_always_lock_free): Use
        CONVERT_EXPR_P, CONVERT_EXPR_CODE_P and CASE_CONVERT where
        approprate.
        (fold_builtin_expect): Likewise.
        (integer_valued_real_p): Likewise.
        * cfgexpand.c (expand_debug_expr): Likewise.
        * ipa-inline-analysis.c (eliminated_by_inlining_prob): Likewise.
        (find_foldable_builtin_expect): Likewise.
        * trans-mem.c (thread_private_new_memory): Likewise.
        * tree-affine.c (aff_combination_expand): Likewise.
        * tree-data-ref.c (initialize_matrix_A): Likewise.
        * tree-eh.c (operation_could_trap_helper_p): Likewise.
        * tree-inline.c (copy_bb): Likewise.
        * tree-pretty-print.c (dump_function_name): Likewise.
        (print_call_name): Likewise.
        * tree-ssa-forwprop.c (constant_pointer_difference): Likewise.
        * tree-ssa-math-opts.c (find_bswap_or_nop_1): Likewise.
        * tree-vect-generic.c (expand_vector_operations_1): Likewise.
        * tree-vect-patterns.c (vect_handle_widen_op_by_const): Likewise.
        (vect_recog_widen_mult_pattern): Likewise.
        (vect_operation_fits_smaller_type): Likewise.
        * tree-vrp.c (find_assert_locations_1): Likewise.
        * tree-ssa-dom.c (initialize_hash_element): Canonicalize
        converts to NOP_EXPR.

[-- Attachment #2: p3 --]
[-- Type: application/octet-stream, Size: 11588 bytes --]

2014-10-31  Richard Biener  <rguenther@suse.de>

	* builtins.c (fold_builtin_atomic_always_lock_free): Use
	CONVERT_EXPR_P, CONVERT_EXPR_CODE_P and CASE_CONVERT where
	approprate.
	(fold_builtin_expect): Likewise.
	(integer_valued_real_p): Likewise.
	* cfgexpand.c (expand_debug_expr): Likewise.
	* ipa-inline-analysis.c (eliminated_by_inlining_prob): Likewise.
	(find_foldable_builtin_expect): Likewise.
	* trans-mem.c (thread_private_new_memory): Likewise.
	* tree-affine.c (aff_combination_expand): Likewise.
	* tree-data-ref.c (initialize_matrix_A): Likewise.
	* tree-eh.c (operation_could_trap_helper_p): Likewise.
	* tree-inline.c (copy_bb): Likewise.
	* tree-pretty-print.c (dump_function_name): Likewise.
	(print_call_name): Likewise.
	* tree-ssa-forwprop.c (constant_pointer_difference): Likewise.
	* tree-ssa-math-opts.c (find_bswap_or_nop_1): Likewise.
	* tree-vect-generic.c (expand_vector_operations_1): Likewise.
	* tree-vect-patterns.c (vect_handle_widen_op_by_const): Likewise.
	(vect_recog_widen_mult_pattern): Likewise.
	(vect_operation_fits_smaller_type): Likewise.
	* tree-vrp.c (find_assert_locations_1): Likewise.
	* tree-ssa-dom.c (initialize_hash_element): Canonicalize
	converts to NOP_EXPR.

Index: gcc/builtins.c
===================================================================
--- gcc/builtins.c	(revision 216952)
+++ gcc/builtins.c	(working copy)
@@ -5551,7 +5551,7 @@ fold_builtin_atomic_always_lock_free (tr
 	 end before anything else has a chance to look at it.  The pointer
 	 parameter at this point is usually cast to a void *, so check for that
 	 and look past the cast.  */
-      if (TREE_CODE (arg1) == NOP_EXPR && POINTER_TYPE_P (ttype)
+      if (CONVERT_EXPR_P (arg1) && POINTER_TYPE_P (ttype)
 	  && VOID_TYPE_P (TREE_TYPE (ttype)))
 	arg1 = TREE_OPERAND (arg1, 0);
 
@@ -6989,7 +6989,7 @@ fold_builtin_expect (location_t loc, tre
   /* Distribute the expected value over short-circuiting operators.
      See through the cast from truthvalue_type_node to long.  */
   inner_arg0 = arg0;
-  while (TREE_CODE (inner_arg0) == NOP_EXPR
+  while (CONVERT_EXPR_P (inner_arg0)
 	 && INTEGRAL_TYPE_P (TREE_TYPE (inner_arg0))
 	 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (inner_arg0, 0))))
     inner_arg0 = TREE_OPERAND (inner_arg0, 0);
@@ -7155,7 +7155,7 @@ integer_valued_real_p (tree t)
     case REAL_CST:
       return real_isinteger (TREE_REAL_CST_PTR (t), TYPE_MODE (TREE_TYPE (t)));
 
-    case NOP_EXPR:
+    CASE_CONVERT:
       {
 	tree type = TREE_TYPE (TREE_OPERAND (t, 0));
 	if (TREE_CODE (type) == INTEGER_TYPE)
Index: gcc/cfgexpand.c
===================================================================
--- gcc/cfgexpand.c	(revision 216952)
+++ gcc/cfgexpand.c	(working copy)
@@ -3882,8 +3882,7 @@ expand_debug_expr (tree exp)
 
     adjust_mode:
     case PAREN_EXPR:
-    case NOP_EXPR:
-    case CONVERT_EXPR:
+    CASE_CONVERT:
       {
 	inner_mode = GET_MODE (op0);
 
Index: gcc/ipa-inline-analysis.c
===================================================================
--- gcc/ipa-inline-analysis.c	(revision 216952)
+++ gcc/ipa-inline-analysis.c	(working copy)
@@ -1617,8 +1617,7 @@ eliminated_by_inlining_prob (gimple stmt
          and stores to return value or parameters are often free after
          inlining dua to SRA and further combining.
          Assume that half of statements goes away.  */
-      if (rhs_code == CONVERT_EXPR
-	  || rhs_code == NOP_EXPR
+      if (CONVERT_EXPR_CODE_P (rhs_code)
 	  || rhs_code == VIEW_CONVERT_EXPR
 	  || rhs_code == ADDR_EXPR
 	  || gimple_assign_rhs_class (stmt) == GIMPLE_SINGLE_RHS)
@@ -2377,7 +2376,7 @@ find_foldable_builtin_expect (basic_bloc
                     match = true;
                     done = true;
                     break;
-                  case NOP_EXPR:
+                  CASE_CONVERT:
                     break;
                   default:
                     done = true;
Index: gcc/trans-mem.c
===================================================================
--- gcc/trans-mem.c	(revision 216952)
+++ gcc/trans-mem.c	(working copy)
@@ -1415,7 +1415,7 @@ thread_private_new_memory (basic_block e
 	  else if (code == POINTER_PLUS_EXPR)
 	    x = gimple_assign_rhs1 (stmt);
 	  /* x = (cast*) foo ==> foo */
-	  else if (code == VIEW_CONVERT_EXPR || code == NOP_EXPR)
+	  else if (code == VIEW_CONVERT_EXPR || CONVERT_EXPR_CODE_P (code))
 	    x = gimple_assign_rhs1 (stmt);
 	  /* x = c ? op1 : op2 == > op1 or op2 just like a PHI */
 	  else if (code == COND_EXPR)
Index: gcc/tree-affine.c
===================================================================
--- gcc/tree-affine.c	(revision 216952)
+++ gcc/tree-affine.c	(working copy)
@@ -648,7 +648,7 @@ aff_combination_expand (aff_tree *comb A
       type = TREE_TYPE (e);
       name = e;
       /* Look through some conversions.  */
-      if (TREE_CODE (e) == NOP_EXPR
+      if (CONVERT_EXPR_P (e)
           && (TYPE_PRECISION (type)
 	      >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (e, 0)))))
 	name = TREE_OPERAND (e, 0);
Index: gcc/tree-data-ref.c
===================================================================
--- gcc/tree-data-ref.c	(revision 216952)
+++ gcc/tree-data-ref.c	(working copy)
@@ -2100,7 +2100,7 @@ initialize_matrix_A (lambda_matrix A, tr
 	return chrec_fold_op (TREE_CODE (chrec), chrec_type (chrec), op0, op1);
       }
 
-    case NOP_EXPR:
+    CASE_CONVERT:
       {
 	tree op = initialize_matrix_A (A, TREE_OPERAND (chrec, 0), index, mult);
 	return chrec_convert (chrec_type (chrec), op, NULL);
Index: gcc/tree-eh.c
===================================================================
--- gcc/tree-eh.c	(revision 216953)
+++ gcc/tree-eh.c	(working copy)
@@ -2436,7 +2436,7 @@ operation_could_trap_helper_p (enum tree
     case UNEQ_EXPR:
       return honor_snans;
 
-    case CONVERT_EXPR:
+    CASE_CONVERT:
     case FIX_TRUNC_EXPR:
       /* Conversion of floating point might trap.  */
       return honor_nans;
Index: gcc/tree-inline.c
===================================================================
--- gcc/tree-inline.c	(revision 216952)
+++ gcc/tree-inline.c	(working copy)
@@ -1686,7 +1686,7 @@ copy_bb (copy_body_data *id, basic_block
       /* With return slot optimization we can end up with
 	 non-gimple (foo *)&this->m, fix that here.  */
       if (is_gimple_assign (stmt)
-	  && gimple_assign_rhs_code (stmt) == NOP_EXPR
+	  && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt))
 	  && !is_gimple_val (gimple_assign_rhs1 (stmt)))
 	{
 	  tree new_rhs;
Index: gcc/tree-pretty-print.c
===================================================================
--- gcc/tree-pretty-print.c	(revision 216952)
+++ gcc/tree-pretty-print.c	(working copy)
@@ -225,7 +225,7 @@ dump_decl_name (pretty_printer *buffer,
 static void
 dump_function_name (pretty_printer *buffer, tree node, int flags)
 {
-  if (TREE_CODE (node) == NOP_EXPR)
+  if (CONVERT_EXPR_P (node))
     node = TREE_OPERAND (node, 0);
   if (DECL_NAME (node) && (flags & TDF_ASMNAME) == 0)
     pp_string (buffer, lang_hooks.decl_printable_name (node, 1));
@@ -3266,7 +3266,7 @@ print_call_name (pretty_printer *buffer,
 
     case ADDR_EXPR:
     case INDIRECT_REF:
-    case NOP_EXPR:
+    CASE_CONVERT:
       op0 = TREE_OPERAND (op0, 0);
       goto again;
 
Index: gcc/tree-ssa-dom.c
===================================================================
--- gcc/tree-ssa-dom.c	(revision 216952)
+++ gcc/tree-ssa-dom.c	(working copy)
@@ -306,7 +306,7 @@ initialize_hash_element (gimple stmt, tr
 	  expr->kind = EXPR_UNARY;
 	  expr->type = TREE_TYPE (gimple_assign_lhs (stmt));
 	  if (CONVERT_EXPR_CODE_P (subcode))
-	    subcode = CONVERT_EXPR;
+	    subcode = NOP_EXPR;
 	  expr->ops.unary.op = subcode;
 	  expr->ops.unary.opnd = gimple_assign_rhs1 (stmt);
 	  break;
Index: gcc/tree-ssa-forwprop.c
===================================================================
--- gcc/tree-ssa-forwprop.c	(revision 216952)
+++ gcc/tree-ssa-forwprop.c	(working copy)
@@ -1487,7 +1487,7 @@ constant_pointer_difference (tree p1, tr
 	      off = size_binop (PLUS_EXPR, off, gimple_assign_rhs2 (stmt));
 	      p = gimple_assign_rhs1 (stmt);
 	    }
-	  else if (code == ADDR_EXPR || code == NOP_EXPR)
+	  else if (code == ADDR_EXPR || CONVERT_EXPR_CODE_P (code))
 	    p = gimple_assign_rhs1 (stmt);
 	  else
 	    break;
Index: gcc/tree-ssa-math-opts.c
===================================================================
--- gcc/tree-ssa-math-opts.c	(revision 216952)
+++ gcc/tree-ssa-math-opts.c	(working copy)
@@ -1867,8 +1867,7 @@ find_bswap_or_nop_1 (gimple stmt, struct
 	  && code != RSHIFT_EXPR
 	  && code != LROTATE_EXPR
 	  && code != RROTATE_EXPR
-	  && code != NOP_EXPR
-	  && code != CONVERT_EXPR)
+	  && !CONVERT_EXPR_CODE_P (code))
 	return NULL;
 
       source_stmt1 = find_bswap_or_nop_1 (rhs1_stmt, n, limit - 1);
Index: gcc/tree-vect-generic.c
===================================================================
--- gcc/tree-vect-generic.c	(revision 216952)
+++ gcc/tree-vect-generic.c	(working copy)
@@ -1449,14 +1449,12 @@ expand_vector_operations_1 (gimple_stmt_
   if (TREE_CODE (type) != VECTOR_TYPE)
     return;
 
-  if (code == NOP_EXPR
+  if (CONVERT_EXPR_CODE_P (code)
       || code == FLOAT_EXPR
       || code == FIX_TRUNC_EXPR
       || code == VIEW_CONVERT_EXPR)
     return;
 
-  gcc_assert (code != CONVERT_EXPR);
-
   /* The signedness is determined from input argument.  */
   if (code == VEC_UNPACK_FLOAT_HI_EXPR
       || code == VEC_UNPACK_FLOAT_LO_EXPR)
Index: gcc/tree-vect-patterns.c
===================================================================
--- gcc/tree-vect-patterns.c	(revision 216952)
+++ gcc/tree-vect-patterns.c	(working copy)
@@ -747,7 +747,7 @@ vect_handle_widen_op_by_const (gimple st
       new_stmt = STMT_VINFO_RELATED_STMT (vinfo_for_stmt (def_stmt));
       /* Check if the already created pattern stmt is what we need.  */
       if (!is_gimple_assign (new_stmt)
-          || gimple_assign_rhs_code (new_stmt) != NOP_EXPR
+          || !CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (new_stmt))
           || TREE_TYPE (gimple_assign_lhs (new_stmt)) != new_type)
         return false;
 
@@ -952,7 +952,7 @@ vect_recog_widen_mult_pattern (vec<gimpl
 
       use_stmt = vect_single_imm_use (last_stmt);
       if (!use_stmt || !is_gimple_assign (use_stmt)
-	  || gimple_assign_rhs_code (use_stmt) != NOP_EXPR)
+	  || !CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (use_stmt)))
         return NULL;
 
       use_lhs = gimple_assign_lhs (use_stmt);
@@ -1429,7 +1429,7 @@ vect_operation_fits_smaller_type (gimple
               new_stmt = STMT_VINFO_RELATED_STMT (vinfo_for_stmt (def_stmt));
               /* Check if the already created pattern stmt is what we need.  */
               if (!is_gimple_assign (new_stmt)
-                  || gimple_assign_rhs_code (new_stmt) != NOP_EXPR
+                  || !CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (new_stmt))
                   || TREE_TYPE (gimple_assign_lhs (new_stmt)) != interm_type)
                 return false;
 
Index: gcc/tree-vrp.c
===================================================================
--- gcc/tree-vrp.c	(revision 216952)
+++ gcc/tree-vrp.c	(working copy)
@@ -6004,7 +6004,8 @@ find_assert_locations_1 (basic_block bb,
 		  gimple def_stmt = SSA_NAME_DEF_STMT (t);
 
 		  while (is_gimple_assign (def_stmt)
-			 && gimple_assign_rhs_code (def_stmt)  == NOP_EXPR
+			 && CONVERT_EXPR_CODE_P
+			     (gimple_assign_rhs_code (def_stmt))
 			 && TREE_CODE
 			     (gimple_assign_rhs1 (def_stmt)) == SSA_NAME
 			 && POINTER_TYPE_P

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Use CONVERT_EXPR_P and friends in the middle-end
  2014-10-31 11:39 [PATCH] Use CONVERT_EXPR_P and friends in the middle-end Richard Biener
@ 2014-10-31 19:02 ` Joseph S. Myers
  2014-11-03 12:01   ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Joseph S. Myers @ 2014-10-31 19:02 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches

On Fri, 31 Oct 2014, Richard Biener wrote:

> This fixes the few places where explicit checks for NOP_EXPR
> or CONVERT_EXPRs crept in.

The goal really should be to eliminate anything that distinguishes the 
two, and then combine them (eliminate NOP_EXPR) (as I said in 
<https://gcc.gnu.org/ml/gcc-patches/2009-09/msg01975.html>).

> A noticable change may be the tree-eh.c one where we previously
> considered FP NOP_EXPRs trapping if flag_trapping_math
> ("Any fp arithmetic may trap") but now like FP CONVERT_EXPRs
> only when honor_nans (but for some reason the honor_nans
> cases don't check flag_trapping_math).  I'm not 100% sure which
> variant is more correct (this is FP <-> FP conversions thus
> widenings, truncations, converts from/to DFP).

Well, use of honor_nans there is confused.  (honor_nans is set in 
operation_could_trap_p in a way that checks flag_trapping_math && 
!flag_finite_math_only - but doesn't check HONOR_NANS on the relevant 
floating-point mode.)

Setting aside for the moment that -ftrapping-math covers both cases where 
actual trap handlers are called, and cases where exception flags are set 
without calling trap handlers (the latter being the only one covered by 
ISO C at present), the following applies:

* Conversions of quiet NaNs from one floating-point type to another do not 
raise exceptions.  Conversions of signaling NaNs do, however, and 
conversions of finite values can raise "inexact" (except for widening from 
a narrower to a wider type with the same radix) and "underflow" (except 
for widening, again, and with an exception to the exception in the case of 
__float80 to __float128 conversion with underflow traps enabled).

* Conversions from floating point to integer (FIX_TRUNC_EXPR) do however 
raise "invalid" for NaN (or infinite) arguments - and for finite arguments 
outside the range of the destination type (this includes -1 and below 
converted to unsigned types).  Whether they raise "inexact" for 
non-integer arguments is unspecified.  To a first approximation, even with 
-ffinite-math-only, assume with -ftrapping-math that "invalid" may be 
raised for such conversions because of out-of-range values (although the 
range of binary16 - currently only supported as ARM __fp16 - is narrow 
enough that if you ignore non-finite values, conversions to some signed 
integer types are guaranteed in-range).

It looks like the honor_nans argument was intended for the case of ordered 
conversions, for which it's correct that quiet NaNs raise exceptions, and 
is being misused for conversions, where fp_operation && flag_trapping_math 
is the right thing to check (although there are certain subcases, 
depending on the types involved, where in fact you can't have traps).  
That in turn is the default, suggesting just removing the CASE_CONVERT and 
FIX_TRUNC_EXPR cases (the effect of which is to treat certain conversions 
as trapping for -ffinite-math-only where previously they weren't treated 
as trapping).

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Use CONVERT_EXPR_P and friends in the middle-end
  2014-10-31 19:02 ` Joseph S. Myers
@ 2014-11-03 12:01   ` Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2014-11-03 12:01 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: GCC Patches

On Fri, Oct 31, 2014 at 6:59 PM, Joseph S. Myers
<joseph@codesourcery.com> wrote:
> On Fri, 31 Oct 2014, Richard Biener wrote:
>
>> This fixes the few places where explicit checks for NOP_EXPR
>> or CONVERT_EXPRs crept in.
>
> The goal really should be to eliminate anything that distinguishes the
> two, and then combine them (eliminate NOP_EXPR) (as I said in
> <https://gcc.gnu.org/ml/gcc-patches/2009-09/msg01975.html>).

Yes,

>> A noticable change may be the tree-eh.c one where we previously
>> considered FP NOP_EXPRs trapping if flag_trapping_math
>> ("Any fp arithmetic may trap") but now like FP CONVERT_EXPRs
>> only when honor_nans (but for some reason the honor_nans
>> cases don't check flag_trapping_math).  I'm not 100% sure which
>> variant is more correct (this is FP <-> FP conversions thus
>> widenings, truncations, converts from/to DFP).
>
> Well, use of honor_nans there is confused.  (honor_nans is set in
> operation_could_trap_p in a way that checks flag_trapping_math &&
> !flag_finite_math_only - but doesn't check HONOR_NANS on the relevant
> floating-point mode.)
>
> Setting aside for the moment that -ftrapping-math covers both cases where
> actual trap handlers are called, and cases where exception flags are set
> without calling trap handlers (the latter being the only one covered by
> ISO C at present), the following applies:
>
> * Conversions of quiet NaNs from one floating-point type to another do not
> raise exceptions.  Conversions of signaling NaNs do, however, and
> conversions of finite values can raise "inexact" (except for widening from
> a narrower to a wider type with the same radix) and "underflow" (except
> for widening, again, and with an exception to the exception in the case of
> __float80 to __float128 conversion with underflow traps enabled).
>
> * Conversions from floating point to integer (FIX_TRUNC_EXPR) do however
> raise "invalid" for NaN (or infinite) arguments - and for finite arguments
> outside the range of the destination type (this includes -1 and below
> converted to unsigned types).  Whether they raise "inexact" for
> non-integer arguments is unspecified.  To a first approximation, even with
> -ffinite-math-only, assume with -ftrapping-math that "invalid" may be
> raised for such conversions because of out-of-range values (although the
> range of binary16 - currently only supported as ARM __fp16 - is narrow
> enough that if you ignore non-finite values, conversions to some signed
> integer types are guaranteed in-range).
>
> It looks like the honor_nans argument was intended for the case of ordered
> conversions, for which it's correct that quiet NaNs raise exceptions, and
> is being misused for conversions, where fp_operation && flag_trapping_math
> is the right thing to check (although there are certain subcases,
> depending on the types involved, where in fact you can't have traps).
> That in turn is the default, suggesting just removing the CASE_CONVERT and
> FIX_TRUNC_EXPR cases (the effect of which is to treat certain conversions
> as trapping for -ffinite-math-only where previously they weren't treated
> as trapping).

Ok, I'll test a patch doing that.

Thanks,
Richard.

> --
> Joseph S. Myers
> joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-11-03 12:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-31 11:39 [PATCH] Use CONVERT_EXPR_P and friends in the middle-end Richard Biener
2014-10-31 19:02 ` Joseph S. Myers
2014-11-03 12:01   ` Richard Biener

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).