public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix (part of) PR77399
@ 2016-09-28 14:26 Richard Biener
  2016-09-30  7:48 ` Richard Biener
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Biener @ 2016-09-28 14:26 UTC (permalink / raw)
  To: gcc-patches


This fixes the original request in PR77399, better handling of

typedef int   v4si __attribute__((vector_size(16)));
typedef float v4sf __attribute__((vector_size(16)));
v4sf vec_cast(v4si f)
{
  return (v4sf){f[0], f[1], f[2], f[3]};
}

which nicely fits into the existing simplify_vector_constructor code.

Bootstrap / regtest pending on x86_64-unknown-linux-gnu.

Richard.

2016-09-28  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/77399
	* tree-ssa-forwprop.c (simplify_vector_constructor): Handle
	float <-> int conversions.

	* gcc.dg/tree-ssa/forwprop-35.c: New testcase.

Index: gcc/tree-ssa-forwprop.c
===================================================================
*** gcc/tree-ssa-forwprop.c	(revision 240565)
--- gcc/tree-ssa-forwprop.c	(working copy)
*************** simplify_vector_constructor (gimple_stmt
*** 1953,1959 ****
    gimple *def_stmt;
    tree op, op2, orig, type, elem_type;
    unsigned elem_size, nelts, i;
!   enum tree_code code;
    constructor_elt *elt;
    unsigned char *sel;
    bool maybe_ident;
--- 1953,1959 ----
    gimple *def_stmt;
    tree op, op2, orig, type, elem_type;
    unsigned elem_size, nelts, i;
!   enum tree_code code, conv_code;
    constructor_elt *elt;
    unsigned char *sel;
    bool maybe_ident;
*************** simplify_vector_constructor (gimple_stmt
*** 1970,1975 ****
--- 1970,1976 ----
  
    sel = XALLOCAVEC (unsigned char, nelts);
    orig = NULL;
+   conv_code = ERROR_MARK;
    maybe_ident = true;
    FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (op), i, elt)
      {
*************** simplify_vector_constructor (gimple_stmt
*** 1984,1989 ****
--- 1985,2008 ----
        if (!def_stmt)
  	return false;
        code = gimple_assign_rhs_code (def_stmt);
+       if (code == FLOAT_EXPR
+ 	  || code == FIX_TRUNC_EXPR)
+ 	{
+ 	  op1 = gimple_assign_rhs1 (def_stmt);
+ 	  if (conv_code == ERROR_MARK)
+ 	    {
+ 	      if (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (elt->value)))
+ 		  != GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1))))
+ 		return false;
+ 	      conv_code = code;
+ 	    }
+ 	  else if (conv_code != code)
+ 	    return false;
+ 	  if (TREE_CODE (op1) != SSA_NAME)
+ 	    return false;
+ 	  def_stmt = SSA_NAME_DEF_STMT (op1);
+ 	  code = gimple_assign_rhs_code (def_stmt);
+ 	}
        if (code != BIT_FIELD_REF)
  	return false;
        op1 = gimple_assign_rhs1 (def_stmt);
*************** simplify_vector_constructor (gimple_stmt
*** 1997,2003 ****
  	{
  	  if (TREE_CODE (ref) != SSA_NAME)
  	    return false;
! 	  if (!useless_type_conversion_p (type, TREE_TYPE (ref)))
  	    return false;
  	  orig = ref;
  	}
--- 2016,2024 ----
  	{
  	  if (TREE_CODE (ref) != SSA_NAME)
  	    return false;
! 	  if (! VECTOR_TYPE_P (TREE_TYPE (ref))
! 	      || ! useless_type_conversion_p (TREE_TYPE (op1),
! 					      TREE_TYPE (TREE_TYPE (ref))))
  	    return false;
  	  orig = ref;
  	}
*************** simplify_vector_constructor (gimple_stmt
*** 2010,2016 ****
      return false;
  
    if (maybe_ident)
!     gimple_assign_set_rhs_from_tree (gsi, orig);
    else
      {
        tree mask_type, *mask_elts;
--- 2031,2043 ----
      return false;
  
    if (maybe_ident)
!     {
!       if (conv_code == ERROR_MARK)
! 	gimple_assign_set_rhs_from_tree (gsi, orig);
!       else
! 	gimple_assign_set_rhs_with_ops (gsi, conv_code, orig,
! 					NULL_TREE, NULL_TREE);
!     }
    else
      {
        tree mask_type, *mask_elts;
*************** simplify_vector_constructor (gimple_stmt
*** 2028,2034 ****
        for (i = 0; i < nelts; i++)
  	mask_elts[i] = build_int_cst (TREE_TYPE (mask_type), sel[i]);
        op2 = build_vector (mask_type, mask_elts);
!       gimple_assign_set_rhs_with_ops (gsi, VEC_PERM_EXPR, orig, orig, op2);
      }
    update_stmt (gsi_stmt (*gsi));
    return true;
--- 2055,2072 ----
        for (i = 0; i < nelts; i++)
  	mask_elts[i] = build_int_cst (TREE_TYPE (mask_type), sel[i]);
        op2 = build_vector (mask_type, mask_elts);
!       if (conv_code == ERROR_MARK)
! 	gimple_assign_set_rhs_with_ops (gsi, VEC_PERM_EXPR, orig, orig, op2);
!       else
! 	{
! 	  gimple *perm
! 	    = gimple_build_assign (make_ssa_name (TREE_TYPE (orig)),
! 				   VEC_PERM_EXPR, orig, orig, op2);
! 	  orig = gimple_assign_lhs (perm);
! 	  gsi_insert_before (gsi, perm, GSI_SAME_STMT);
! 	  gimple_assign_set_rhs_with_ops (gsi, conv_code, orig,
! 					  NULL_TREE, NULL_TREE);
! 	}
      }
    update_stmt (gsi_stmt (*gsi));
    return true;
Index: gcc/testsuite/gcc.dg/tree-ssa/forwprop-35.c
===================================================================
*** gcc/testsuite/gcc.dg/tree-ssa/forwprop-35.c	(revision 0)
--- gcc/testsuite/gcc.dg/tree-ssa/forwprop-35.c	(working copy)
***************
*** 0 ****
--- 1,18 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fdump-tree-cddce1" } */
+ 
+ typedef int v4si __attribute__((vector_size(16)));
+ typedef float v4sf __attribute__((vector_size(16)));
+ 
+ v4sf vec_cast(v4si f)
+ {
+   return (v4sf){f[0], f[1], f[2], f[3]};
+ }
+ 
+ v4sf vec_cast_perm(v4si f)
+ {
+   return (v4sf){f[1], f[1], f[2], f[3]};
+ }
+ 
+ /* { dg-final { scan-tree-dump-times "VEC_PERM_EXPR" 1 "cddce1" } } */
+ /* { dg-final { scan-tree-dump-times "\\\(v4sf\\\) " 2 "cddce1" } } */

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

* Re: [PATCH] Fix (part of) PR77399
  2016-09-28 14:26 [PATCH] Fix (part of) PR77399 Richard Biener
@ 2016-09-30  7:48 ` Richard Biener
  2016-10-01  8:49   ` Andreas Schwab
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Biener @ 2016-09-30  7:48 UTC (permalink / raw)
  To: gcc-patches

On Wed, 28 Sep 2016, Richard Biener wrote:

> 
> This fixes the original request in PR77399, better handling of
> 
> typedef int   v4si __attribute__((vector_size(16)));
> typedef float v4sf __attribute__((vector_size(16)));
> v4sf vec_cast(v4si f)
> {
>   return (v4sf){f[0], f[1], f[2], f[3]};
> }
> 
> which nicely fits into the existing simplify_vector_constructor code.
> 
> Bootstrap / regtest pending on x86_64-unknown-linux-gnu.

This is the variant I applied (with some fixed issues).

Bootstrapped and tested on x86_64-unknown-linux-gnu.

Richard.

2016-09-30  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/77399
	* tree-ssa-forwprop.c (simplify_vector_constructor): Handle
	float <-> int conversions.

	* gcc.dg/tree-ssa/forwprop-35.c: New testcase.

Index: gcc/tree-ssa-forwprop.c
===================================================================
*** gcc/tree-ssa-forwprop.c	(revision 240612)
--- gcc/tree-ssa-forwprop.c	(working copy)
*************** simplify_vector_constructor (gimple_stmt
*** 1953,1959 ****
    gimple *def_stmt;
    tree op, op2, orig, type, elem_type;
    unsigned elem_size, nelts, i;
!   enum tree_code code;
    constructor_elt *elt;
    unsigned char *sel;
    bool maybe_ident;
--- 1953,1959 ----
    gimple *def_stmt;
    tree op, op2, orig, type, elem_type;
    unsigned elem_size, nelts, i;
!   enum tree_code code, conv_code;
    constructor_elt *elt;
    unsigned char *sel;
    bool maybe_ident;
*************** simplify_vector_constructor (gimple_stmt
*** 1970,1975 ****
--- 1970,1976 ----
  
    sel = XALLOCAVEC (unsigned char, nelts);
    orig = NULL;
+   conv_code = ERROR_MARK;
    maybe_ident = true;
    FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (op), i, elt)
      {
*************** simplify_vector_constructor (gimple_stmt
*** 1984,1989 ****
--- 1985,2010 ----
        if (!def_stmt)
  	return false;
        code = gimple_assign_rhs_code (def_stmt);
+       if (code == FLOAT_EXPR
+ 	  || code == FIX_TRUNC_EXPR)
+ 	{
+ 	  op1 = gimple_assign_rhs1 (def_stmt);
+ 	  if (conv_code == ERROR_MARK)
+ 	    {
+ 	      if (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (elt->value)))
+ 		  != GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1))))
+ 		return false;
+ 	      conv_code = code;
+ 	    }
+ 	  else if (conv_code != code)
+ 	    return false;
+ 	  if (TREE_CODE (op1) != SSA_NAME)
+ 	    return false;
+ 	  def_stmt = SSA_NAME_DEF_STMT (op1);
+ 	  if (! is_gimple_assign (def_stmt))
+ 	    return false;
+ 	  code = gimple_assign_rhs_code (def_stmt);
+ 	}
        if (code != BIT_FIELD_REF)
  	return false;
        op1 = gimple_assign_rhs1 (def_stmt);
*************** simplify_vector_constructor (gimple_stmt
*** 1997,2003 ****
  	{
  	  if (TREE_CODE (ref) != SSA_NAME)
  	    return false;
! 	  if (!useless_type_conversion_p (type, TREE_TYPE (ref)))
  	    return false;
  	  orig = ref;
  	}
--- 2018,2026 ----
  	{
  	  if (TREE_CODE (ref) != SSA_NAME)
  	    return false;
! 	  if (! VECTOR_TYPE_P (TREE_TYPE (ref))
! 	      || ! useless_type_conversion_p (TREE_TYPE (op1),
! 					      TREE_TYPE (TREE_TYPE (ref))))
  	    return false;
  	  orig = ref;
  	}
*************** simplify_vector_constructor (gimple_stmt
*** 2009,2016 ****
    if (i < nelts)
      return false;
  
    if (maybe_ident)
!     gimple_assign_set_rhs_from_tree (gsi, orig);
    else
      {
        tree mask_type, *mask_elts;
--- 2032,2050 ----
    if (i < nelts)
      return false;
  
+   if (! VECTOR_TYPE_P (TREE_TYPE (orig))
+       || (TYPE_VECTOR_SUBPARTS (type)
+ 	  != TYPE_VECTOR_SUBPARTS (TREE_TYPE (orig))))
+     return false;
+ 
    if (maybe_ident)
!     {
!       if (conv_code == ERROR_MARK)
! 	gimple_assign_set_rhs_from_tree (gsi, orig);
!       else
! 	gimple_assign_set_rhs_with_ops (gsi, conv_code, orig,
! 					NULL_TREE, NULL_TREE);
!     }
    else
      {
        tree mask_type, *mask_elts;
*************** simplify_vector_constructor (gimple_stmt
*** 2028,2034 ****
        for (i = 0; i < nelts; i++)
  	mask_elts[i] = build_int_cst (TREE_TYPE (mask_type), sel[i]);
        op2 = build_vector (mask_type, mask_elts);
!       gimple_assign_set_rhs_with_ops (gsi, VEC_PERM_EXPR, orig, orig, op2);
      }
    update_stmt (gsi_stmt (*gsi));
    return true;
--- 2062,2079 ----
        for (i = 0; i < nelts; i++)
  	mask_elts[i] = build_int_cst (TREE_TYPE (mask_type), sel[i]);
        op2 = build_vector (mask_type, mask_elts);
!       if (conv_code == ERROR_MARK)
! 	gimple_assign_set_rhs_with_ops (gsi, VEC_PERM_EXPR, orig, orig, op2);
!       else
! 	{
! 	  gimple *perm
! 	    = gimple_build_assign (make_ssa_name (TREE_TYPE (orig)),
! 				   VEC_PERM_EXPR, orig, orig, op2);
! 	  orig = gimple_assign_lhs (perm);
! 	  gsi_insert_before (gsi, perm, GSI_SAME_STMT);
! 	  gimple_assign_set_rhs_with_ops (gsi, conv_code, orig,
! 					  NULL_TREE, NULL_TREE);
! 	}
      }
    update_stmt (gsi_stmt (*gsi));
    return true;
Index: gcc/testsuite/gcc.dg/tree-ssa/forwprop-35.c
===================================================================
*** gcc/testsuite/gcc.dg/tree-ssa/forwprop-35.c	(revision 0)
--- gcc/testsuite/gcc.dg/tree-ssa/forwprop-35.c	(working copy)
***************
*** 0 ****
--- 1,18 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fdump-tree-cddce1" } */
+ 
+ typedef int v4si __attribute__((vector_size(16)));
+ typedef float v4sf __attribute__((vector_size(16)));
+ 
+ v4sf vec_cast(v4si f)
+ {
+   return (v4sf){f[0], f[1], f[2], f[3]};
+ }
+ 
+ v4sf vec_cast_perm(v4si f)
+ {
+   return (v4sf){f[1], f[1], f[2], f[3]};
+ }
+ 
+ /* { dg-final { scan-tree-dump-times "VEC_PERM_EXPR" 1 "cddce1" } } */
+ /* { dg-final { scan-tree-dump-times "\\\(v4sf\\\) " 2 "cddce1" } } */

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

* Re: [PATCH] Fix (part of) PR77399
  2016-09-30  7:48 ` Richard Biener
@ 2016-10-01  8:49   ` Andreas Schwab
  2016-10-01 14:43     ` Richard Biener
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2016-10-01  8:49 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

/usr/local/gcc/gcc-20161001/gcc/testsuite/gcc.dg/tree-ssa/forwprop-35.c:9:10: internal compiler error: in expand_float, at optabs.c:4774
0x4000000000af810f expand_float(rtx_def*, rtx_def*, int)
        ../../gcc/optabs.c:4774
0x4000000000699f6f expand_expr_real_2(separate_ops*, rtx_def*, machine_mode, expand_modifier)
        ../../gcc/expr.c:8867
0x400000000067ae4f expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool)
        ../../gcc/expr.c:9720
0x400000000068be5f expand_normal
        ../../gcc/expr.h:285
0x400000000068be5f copy_blkmode_to_reg(machine_mode, tree_node*)
        ../../gcc/expr.c:2716
0x400000000042e16f expand_return
        ../../gcc/cfgexpand.c:3516
0x400000000042e16f expand_gimple_stmt_1
        ../../gcc/cfgexpand.c:3618
0x400000000042e16f expand_gimple_stmt
        ../../gcc/cfgexpand.c:3745
0x400000000043145f expand_gimple_basic_block
        ../../gcc/cfgexpand.c:5752
0x400000000044006f execute
        ../../gcc/cfgexpand.c:6363

/daten/aranym/gcc/gcc-20161001/gcc/testsuite/gcc.dg/tree-ssa/forwprop-35.c:9:10: internal compiler error: in expand_float, at optabs.c:4774
0x9da792 expand_float(rtx_def*, rtx_def*, int)
        ../../gcc/optabs.c:4774
0x7b6a86 expand_expr_real_2(separate_ops*, rtx_def*, machine_mode, expand_modifier)
        ../../gcc/expr.c:8867
0x7a534b expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool)
        ../../gcc/expr.c:9720
0x7ae0b1 store_expr_with_bounds(tree_node*, rtx_def*, int, bool, bool, tree_node*)
        ../../gcc/expr.c:5550
0x7b04e5 expand_assignment(tree_node*, tree_node*, bool)
        ../../gcc/expr.c:5316
0x6a307c expand_gimple_stmt_1
        ../../gcc/cfgexpand.c:3649
0x6a307c expand_gimple_stmt
        ../../gcc/cfgexpand.c:3745
0x6a4e96 expand_gimple_basic_block
        ../../gcc/cfgexpand.c:5752
0x6aa806 execute
        ../../gcc/cfgexpand.c:6363

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: [PATCH] Fix (part of) PR77399
  2016-10-01  8:49   ` Andreas Schwab
@ 2016-10-01 14:43     ` Richard Biener
  2016-10-01 15:11       ` Andreas Schwab
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Biener @ 2016-10-01 14:43 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: gcc-patches

On Sat, 1 Oct 2016, Andreas Schwab wrote:

> /usr/local/gcc/gcc-20161001/gcc/testsuite/gcc.dg/tree-ssa/forwprop-35.c:9:10: internal compiler error: in expand_float, at optabs.c:4774
> 0x4000000000af810f expand_float(rtx_def*, rtx_def*, int)
>         ../../gcc/optabs.c:4774
> 0x4000000000699f6f expand_expr_real_2(separate_ops*, rtx_def*, machine_mode, expand_modifier)
>         ../../gcc/expr.c:8867
> 0x400000000067ae4f expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool)
>         ../../gcc/expr.c:9720
> 0x400000000068be5f expand_normal
>         ../../gcc/expr.h:285
> 0x400000000068be5f copy_blkmode_to_reg(machine_mode, tree_node*)
>         ../../gcc/expr.c:2716
> 0x400000000042e16f expand_return
>         ../../gcc/cfgexpand.c:3516
> 0x400000000042e16f expand_gimple_stmt_1
>         ../../gcc/cfgexpand.c:3618
> 0x400000000042e16f expand_gimple_stmt
>         ../../gcc/cfgexpand.c:3745
> 0x400000000043145f expand_gimple_basic_block
>         ../../gcc/cfgexpand.c:5752
> 0x400000000044006f execute
>         ../../gcc/cfgexpand.c:6363
> 
> /daten/aranym/gcc/gcc-20161001/gcc/testsuite/gcc.dg/tree-ssa/forwprop-35.c:9:10: internal compiler error: in expand_float, at optabs.c:4774
> 0x9da792 expand_float(rtx_def*, rtx_def*, int)
>         ../../gcc/optabs.c:4774
> 0x7b6a86 expand_expr_real_2(separate_ops*, rtx_def*, machine_mode, expand_modifier)
>         ../../gcc/expr.c:8867
> 0x7a534b expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool)
>         ../../gcc/expr.c:9720
> 0x7ae0b1 store_expr_with_bounds(tree_node*, rtx_def*, int, bool, bool, tree_node*)
>         ../../gcc/expr.c:5550
> 0x7b04e5 expand_assignment(tree_node*, tree_node*, bool)
>         ../../gcc/expr.c:5316
> 0x6a307c expand_gimple_stmt_1
>         ../../gcc/cfgexpand.c:3649
> 0x6a307c expand_gimple_stmt
>         ../../gcc/cfgexpand.c:3745
> 0x6a4e96 expand_gimple_basic_block
>         ../../gcc/cfgexpand.c:5752
> 0x6aa806 execute
>         ../../gcc/cfgexpand.c:6363

Which architecture?

Richard.

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

* Re: [PATCH] Fix (part of) PR77399
  2016-10-01 14:43     ` Richard Biener
@ 2016-10-01 15:11       ` Andreas Schwab
  0 siblings, 0 replies; 5+ messages in thread
From: Andreas Schwab @ 2016-10-01 15:11 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

On Okt 01 2016, Richard Biener <rguenther@suse.de> wrote:

> Which architecture?

http://gcc.gnu.org/ml/gcc-testresults/2016-10/msg00021.html
http://gcc.gnu.org/ml/gcc-testresults/2016-10/msg00049.html

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

end of thread, other threads:[~2016-10-01 15:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-28 14:26 [PATCH] Fix (part of) PR77399 Richard Biener
2016-09-30  7:48 ` Richard Biener
2016-10-01  8:49   ` Andreas Schwab
2016-10-01 14:43     ` Richard Biener
2016-10-01 15:11       ` Andreas Schwab

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