diff mbox series

[2/2] Support {MIN,MAX}_EXPR in GIMPLE FE.

Message ID 19db1384-0d24-2131-436e-6da86363ae79@suse.cz
State New
Headers show
Series [stage1] Support profile (BB counts and edge probabilities) in GIMPLE FE. | expand

Commit Message

Martin Liška May 6, 2019, 8 a.m. UTC
Hi.

The patch is about support of a new GIMPLE expr.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

Comments

Richard Biener May 6, 2019, 11:35 a.m. UTC | #1
On Mon, May 6, 2019 at 10:00 AM Martin Liška <mliska@suse.cz> wrote:
>
> Hi.
>
> The patch is about support of a new GIMPLE expr.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?

Can you please avoid using/changing parser_build_binary_op?  The other
binary expression handling just does

  if (lhs.value != error_mark_node && rhs.value != error_mark_node)
    ret.value = build2_loc (ret_loc, code, ret_type, lhs.value, rhs.value);

which should work equally well here.  I think for future expansion
splitting out the ( op, op ) parsing and expression building into
a function might be nicer so that c_parser_gimple_unary_expression
reads

  if (strcmp (INDENTIFIER_POINTER (id), "__MIN") == 0)
    return c_parser_gimple_parentized_binary_expression (op_loc, MIN_EXPR);
  else if (...)

OK with such change/factoring.

Thanks,
Richard.

> Thanks,
> Martin
Martin Liška May 7, 2019, 12:01 p.m. UTC | #2
On 5/6/19 1:35 PM, Richard Biener wrote:
> On Mon, May 6, 2019 at 10:00 AM Martin Liška <mliska@suse.cz> wrote:
>>
>> Hi.
>>
>> The patch is about support of a new GIMPLE expr.
>>
>> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>>
>> Ready to be installed?
> 
> Can you please avoid using/changing parser_build_binary_op?  The other
> binary expression handling just does
> 
>   if (lhs.value != error_mark_node && rhs.value != error_mark_node)
>     ret.value = build2_loc (ret_loc, code, ret_type, lhs.value, rhs.value);
> 
> which should work equally well here.  I think for future expansion
> splitting out the ( op, op ) parsing and expression building into
> a function might be nicer so that c_parser_gimple_unary_expression
> reads
> 
>   if (strcmp (INDENTIFIER_POINTER (id), "__MIN") == 0)
>     return c_parser_gimple_parentized_binary_expression (op_loc, MIN_EXPR);
>   else if (...)
> 
> OK with such change/factoring.

I've done all what you pointed out.

Martin

> 
> Thanks,
> Richard.
> 
>> Thanks,
>> Martin
Richard Biener May 7, 2019, 12:58 p.m. UTC | #3
On Tue, May 7, 2019 at 2:01 PM Martin Liška <mliska@suse.cz> wrote:
>
> On 5/6/19 1:35 PM, Richard Biener wrote:
> > On Mon, May 6, 2019 at 10:00 AM Martin Liška <mliska@suse.cz> wrote:
> >>
> >> Hi.
> >>
> >> The patch is about support of a new GIMPLE expr.
> >>
> >> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> >>
> >> Ready to be installed?
> >
> > Can you please avoid using/changing parser_build_binary_op?  The other
> > binary expression handling just does
> >
> >   if (lhs.value != error_mark_node && rhs.value != error_mark_node)
> >     ret.value = build2_loc (ret_loc, code, ret_type, lhs.value, rhs.value);
> >
> > which should work equally well here.  I think for future expansion
> > splitting out the ( op, op ) parsing and expression building into
> > a function might be nicer so that c_parser_gimple_unary_expression
> > reads
> >
> >   if (strcmp (INDENTIFIER_POINTER (id), "__MIN") == 0)
> >     return c_parser_gimple_parentized_binary_expression (op_loc, MIN_EXPR);
> >   else if (...)
> >
> > OK with such change/factoring.
>
> I've done all what you pointed out.

OK.

Thanks,
Richard.

> Martin
>
> >
> > Thanks,
> > Richard.
> >
> >> Thanks,
> >> Martin
>
diff mbox series

Patch

From a4f23fe8d876f2d8a0628feb57127e276348aab0 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Fri, 3 May 2019 13:54:40 +0200
Subject: [PATCH 2/2] Support {MIN,MAX}_EXPR in GIMPLE FE.

gcc/ChangeLog:

2019-05-03  Martin Liska  <mliska@suse.cz>

	* gimple-pretty-print.c (dump_binary_rhs): Dump MIN_EXPR
	and MAX_EXPR in GIMPLE FE format.

gcc/c/ChangeLog:

2019-05-03  Martin Liska  <mliska@suse.cz>

	* c-typeck.c (build_binary_op): Handle MIN_EXPR and MAX_EXPR
	with flag_gimple.
	* gimple-parser.c (c_parser_gimple_statement): Support __MIN and
	__MAX.
	(c_parser_gimple_unary_expression): Parse also binary expression
	__MIN and __MAX.

gcc/testsuite/ChangeLog:

2019-05-03  Martin Liska  <mliska@suse.cz>

	* gcc.dg/gimplefe-39.c: New test.
---
 gcc/c/c-typeck.c                   | 10 ++++++++++
 gcc/c/gimple-parser.c              | 21 ++++++++++++++++++++-
 gcc/gimple-pretty-print.c          | 15 ++++++++++++++-
 gcc/testsuite/gcc.dg/gimplefe-39.c | 21 +++++++++++++++++++++
 4 files changed, 65 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/gimplefe-39.c

diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 4e443754002..d0ae9c51f6b 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -12193,6 +12193,16 @@  build_binary_op (location_t location, enum tree_code code,
 	maybe_warn_bool_compare (location, code, orig_op0, orig_op1);
       break;
 
+    case MIN_EXPR:
+    case MAX_EXPR:
+      if (flag_gimple)
+	{
+	  result_type = c_common_type (type0, type1);
+	  break;
+	}
+      else
+	gcc_unreachable ();
+
     default:
       gcc_unreachable ();
     }
diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c
index 6558770873f..f3e0d2f94ad 100644
--- a/gcc/c/gimple-parser.c
+++ b/gcc/c/gimple-parser.c
@@ -747,7 +747,9 @@  c_parser_gimple_statement (gimple_parser &parser, gimple_seq *seq)
       {
 	tree id = c_parser_peek_token (parser)->value;
 	if (strcmp (IDENTIFIER_POINTER (id), "__ABS") == 0
-	    || strcmp (IDENTIFIER_POINTER (id), "__ABSU") == 0)
+	    || strcmp (IDENTIFIER_POINTER (id), "__ABSU") == 0
+	    || strcmp (IDENTIFIER_POINTER (id), "__MIN") == 0
+	    || strcmp (IDENTIFIER_POINTER (id), "__MAX") == 0)
 	  goto build_unary_expr;
 	break;
       }
@@ -1062,6 +1064,7 @@  c_parser_gimple_unary_expression (gimple_parser &parser)
 	}
     case CPP_NAME:
 	{
+	  bool is_min;
 	  tree id = c_parser_peek_token (parser)->value;
 	  if (strcmp (IDENTIFIER_POINTER (id), "__ABS") == 0)
 	    {
@@ -1075,6 +1078,22 @@  c_parser_gimple_unary_expression (gimple_parser &parser)
 	      op = c_parser_gimple_postfix_expression (parser);
 	      return parser_build_unary_op (op_loc, ABSU_EXPR, op);
 	    }
+	  else if ((is_min = strcmp (IDENTIFIER_POINTER (id), "__MIN") == 0)
+		   || strcmp (IDENTIFIER_POINTER (id), "__MAX") == 0)
+	    {
+	      c_parser_consume_token (parser);
+	      if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+		return ret;
+	      c_expr op1 = c_parser_gimple_postfix_expression (parser);
+	      if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
+		return ret;
+	      c_expr op2 = c_parser_gimple_postfix_expression (parser);
+	      if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
+		return ret;
+	      return parser_build_binary_op (op_loc,
+					     is_min ? MIN_EXPR : MAX_EXPR,
+					     op1, op2);
+	    }
 	  else
 	    return c_parser_gimple_postfix_expression (parser);
 	}
diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c
index 7e3916bff86..58212c4dcc1 100644
--- a/gcc/gimple-pretty-print.c
+++ b/gcc/gimple-pretty-print.c
@@ -423,9 +423,22 @@  dump_binary_rhs (pretty_printer *buffer, gassign *gs, int spc,
   enum tree_code code = gimple_assign_rhs_code (gs);
   switch (code)
     {
-    case COMPLEX_EXPR:
     case MIN_EXPR:
     case MAX_EXPR:
+      if (flags & TDF_GIMPLE)
+	{
+	  pp_string (buffer, code == MIN_EXPR ? "__MIN (" : "__MAX (");
+	  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, ")");
+	  break;
+	}
+      else
+	gcc_fallthrough ();
+    case COMPLEX_EXPR:
     case VEC_WIDEN_MULT_HI_EXPR:
     case VEC_WIDEN_MULT_LO_EXPR:
     case VEC_WIDEN_MULT_EVEN_EXPR:
diff --git a/gcc/testsuite/gcc.dg/gimplefe-39.c b/gcc/testsuite/gcc.dg/gimplefe-39.c
new file mode 100644
index 00000000000..30677356d5b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gimplefe-39.c
@@ -0,0 +1,21 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -fgimple -fdump-tree-optimized" } */
+
+int a, b;
+
+int __GIMPLE (ssa,guessed_local(1073741824))
+main (int argc)
+{
+  int _1;
+  int _2;
+  int _4;
+
+  __BB(2,guessed_local(1073741824)):
+  _1 = a;
+  _2 = b;
+  _4 = __MAX (_1, _2);
+  return _4;
+
+}
+
+/* { dg-final { scan-tree-dump "MAX_EXPR" "optimized" } } */
-- 
2.21.0