[gimplefe] BIT_INSERT_EXPR support

Message ID alpine.LSU.2.20.1905160917030.10704@zhemvz.fhfr.qr
State New
Headers show
Series
  • [gimplefe] BIT_INSERT_EXPR support
Related show

Commit Message

Richard Biener May 16, 2019, 7:17 a.m.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2019-05-16  Richard Biener  <rguenther@suse.de>

	c/
	* gimple-parser.c (c_parser_gimple_statement): Handle __BIT_INSERT.
	(c_parser_gimple_unary_expression): Likewise.

	* gimple-pretty-print.c (dump_ternary_rhs): Dump BIT_INSERT_EXPR
	as __BIT_INSERT with -gimple.

	* gcc.dg/gimplefe-40.c: Amend again.

Patch

Index: gcc/gimple-pretty-print.c
===================================================================
--- gcc/gimple-pretty-print.c	(revision 271210)
+++ gcc/gimple-pretty-print.c	(working copy)
@@ -567,21 +567,35 @@  dump_ternary_rhs (pretty_printer *buffer
       break;
 
     case BIT_INSERT_EXPR:
-      pp_string (buffer, "BIT_INSERT_EXPR <");
-      dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc, flags, false);
-      pp_string (buffer, ", ");
-      dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc, flags, false);
-      pp_string (buffer, ", ");
-      dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc, flags, false);
-      pp_string (buffer, " (");
-      if (INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_rhs2 (gs))))
-	pp_decimal_int (buffer,
-			TYPE_PRECISION (TREE_TYPE (gimple_assign_rhs2 (gs))));
+      if (flags & TDF_GIMPLE)
+	{
+	  pp_string (buffer, "__BIT_INSERT (");
+	  dump_generic_node (buffer, gimple_assign_rhs1 (gs), spc,
+			     flags | TDF_SLIM, false);
+	  pp_string (buffer, ", ");
+	  dump_generic_node (buffer, gimple_assign_rhs2 (gs), spc,
+			     flags | TDF_SLIM, false);
+	  pp_string (buffer, ", ");
+	  dump_generic_node (buffer, gimple_assign_rhs3 (gs), spc,
+			     flags | TDF_SLIM, false);
+	  pp_right_paren (buffer);
+	}
       else
-	dump_generic_node (buffer,
-			   TYPE_SIZE (TREE_TYPE (gimple_assign_rhs2 (gs))),
-			   spc, flags, false);
-      pp_string (buffer, " bits)>");
+	{
+	  pp_string (buffer, "BIT_INSERT_EXPR <");
+	  dump_generic_node (buffer, gimple_assign_rhs1 (gs),
+			     spc, flags, false);
+	  pp_string (buffer, ", ");
+	  dump_generic_node (buffer, gimple_assign_rhs2 (gs),
+			     spc, flags, false);
+	  pp_string (buffer, ", ");
+	  dump_generic_node (buffer, gimple_assign_rhs3 (gs),
+			     spc, flags, false);
+	  pp_string (buffer, " (");
+	  if (INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_rhs2 (gs))))
+	    pp_decimal_int (buffer, TYPE_PRECISION
+				      (TREE_TYPE (gimple_assign_rhs2 (gs))));
+	}
       break;
 
     default:
Index: gcc/c/gimple-parser.c
===================================================================
--- gcc/c/gimple-parser.c	(revision 271210)
+++ gcc/c/gimple-parser.c	(working copy)
@@ -746,6 +746,7 @@  c_parser_gimple_statement (gimple_parser
 	if (strcmp (IDENTIFIER_POINTER (id), "__ABS") == 0
 	    || strcmp (IDENTIFIER_POINTER (id), "__ABSU") == 0
 	    || strcmp (IDENTIFIER_POINTER (id), "__MIN") == 0
+	    || strcmp (IDENTIFIER_POINTER (id), "__BIT_INSERT") == 0
 	    || strcmp (IDENTIFIER_POINTER (id), "__MAX") == 0)
 	  goto build_unary_expr;
 	break;
@@ -1108,6 +1139,37 @@  c_parser_gimple_unary_expression (gimple
 	    return c_parser_gimple_parentized_binary_expression (parser,
 								 op_loc,
 								 MAX_EXPR);
+	  else if (strcmp (IDENTIFIER_POINTER (id), "__BIT_INSERT") == 0)
+	    {
+	      /* __BIT_INSERT '(' postfix-expression, postfix-expression,
+			          integer ')'  */
+	      location_t loc = c_parser_peek_token (parser)->location;
+	      c_parser_consume_token (parser);
+	      if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+		{
+		  c_expr op0 = c_parser_gimple_postfix_expression (parser);
+		  c_parser_skip_until_found (parser, CPP_COMMA,
+					     "expected %<,%>");
+		  c_expr op1 = c_parser_gimple_postfix_expression (parser);
+		  c_parser_skip_until_found (parser, CPP_COMMA,
+					     "expected %<,%>");
+		  c_expr op2 = c_parser_gimple_postfix_expression (parser);
+		  if (TREE_CODE (op2.value) != INTEGER_CST
+		      || !int_fits_type_p (op2.value, bitsizetype))
+		    c_parser_error (parser, "expected constant offset");
+		  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
+					     "expected %<)%>");
+		  if (op0.value != error_mark_node
+		      && op1.value != error_mark_node
+		      && TREE_CODE (op2.value) == INTEGER_CST)
+		    ret.value = build3_loc (loc, BIT_INSERT_EXPR,
+					    TREE_TYPE (op0.value),
+					    op0.value, op1.value,
+					    fold_convert (bitsizetype,
+							  op2.value));
+		}
+	      return ret;
+	    }
 	  else
 	    return c_parser_gimple_postfix_expression (parser);
 	}
Index: gcc/testsuite/gcc.dg/gimplefe-40.c
===================================================================
--- gcc/testsuite/gcc.dg/gimplefe-40.c	(revision 271210)
+++ gcc/testsuite/gcc.dg/gimplefe-40.c	(working copy)
@@ -1,12 +1,13 @@ 
 /* { dg-do compile { target int128 } } */
-/* { dg-options "-fgimple" } */
+/* { dg-options "-fgimple -Wno-psabi -w" } */
 
 typedef float v4sf __attribute__((vector_size(16)));
-float __GIMPLE (ssa)
+v4sf __GIMPLE (ssa)
 load (const void * p)
 {
   __int128 unsigned _3;
   v4sf _4;
+  v4sf _6;
   float _5;
 
   __BB(2):
@@ -17,5 +18,6 @@  load (const void * p)
 #else
   _5 = 1.0f;
 #endif
-  return _5;
+  _6 = __BIT_INSERT (_4, _5, 0);
+  return _6;
 }