public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Martin Liška" <mliska@suse.cz>
To: Richard Biener <richard.guenther@gmail.com>
Cc: "Joseph S. Myers" <joseph@codesourcery.com>,
	Jan Hubicka <hubicka@ucw.cz>,
	GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH 2/2] Support {MIN,MAX}_EXPR in GIMPLE FE.
Date: Tue, 07 May 2019 12:01:00 -0000	[thread overview]
Message-ID: <5eb4bac2-4483-2621-d606-05fa02a80df1@suse.cz> (raw)
In-Reply-To: <CAFiYyc1ZpBFyL9mkL5FBRa9QfoTchM_M01+L=Z-LrXM2XCfsaw@mail.gmail.com>

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

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


[-- Attachment #2: 0002-Support-MIN-MAX-_EXPR-in-GIMPLE-FE.patch --]
[-- Type: text/x-patch, Size: 4775 bytes --]

From fe7fc3a153e404c485fa1d8dcd428c4a8ebc8f67 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>

	* gimple-parser.c (c_parser_gimple_statement): Support __MIN and
	__MAX.
	(c_parser_gimple_unary_expression): Parse also binary expression
	__MIN and __MAX.
	(c_parser_gimple_parentized_binary_expression): New function.

gcc/testsuite/ChangeLog:

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

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

diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c
index ede5a927c3d..99f764710b2 100644
--- a/gcc/c/gimple-parser.c
+++ b/gcc/c/gimple-parser.c
@@ -750,7 +750,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;
       }
@@ -989,6 +991,32 @@ c_parser_gimple_binary_expression (gimple_parser &parser)
   return ret;
 }
 
+/* Parse a gimple parentized binary expression.  */
+
+static c_expr
+c_parser_gimple_parentized_binary_expression (gimple_parser &parser,
+					      location_t op_loc,
+					      tree_code code)
+{
+  struct c_expr ret;
+  ret.set_error ();
+
+  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;
+
+  if (op1.value != error_mark_node && op2.value != error_mark_node)
+    ret.value = build2_loc (op_loc,
+			    code, TREE_TYPE (op1.value), op1.value, op2.value);
+  return ret;
+}
+
 /* Parse gimple unary expression.
 
    gimple-unary-expression:
@@ -1078,6 +1106,14 @@ 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 (strcmp (IDENTIFIER_POINTER (id), "__MIN") == 0)
+	    return c_parser_gimple_parentized_binary_expression (parser,
+								 op_loc,
+								 MIN_EXPR);
+	  else if (strcmp (IDENTIFIER_POINTER (id), "__MAX") == 0)
+	    return c_parser_gimple_parentized_binary_expression (parser,
+								 op_loc,
+								 MAX_EXPR);
 	  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


  reply	other threads:[~2019-05-07 12:01 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-05 12:32 [PATCH][stage1] Support profile (BB counts and edge probabilities) " Martin Liška
2019-04-08  9:11 ` Richard Biener
2019-04-08 13:35   ` Martin Liška
2019-04-09 13:15     ` Martin Liška
2019-04-09 14:02       ` Jan Hubicka
2019-04-10  9:57         ` Martin Liška
2019-04-26 13:29           ` Richard Biener
2019-04-29 12:54             ` Martin Liška
2019-05-02 12:31               ` Richard Biener
2019-05-06  7:59                 ` Martin Liška
2019-05-06  8:00                   ` [PATCH 2/2] Support {MIN,MAX}_EXPR " Martin Liška
2019-05-06 11:35                     ` Richard Biener
2019-05-07 12:01                       ` Martin Liška [this message]
2019-05-07 12:58                         ` Richard Biener
2019-05-06 14:02                   ` [PATCH][stage1] Support profile (BB counts and edge probabilities) " Richard Biener
2019-05-07 12:00                     ` Martin Liška
2019-05-07 12:56                       ` Richard Biener
2019-05-07 14:33                         ` Martin Liška
2019-05-07 14:44                           ` Richard Biener
2019-05-09 10:01                             ` Martin Liška
2019-05-10  6:39                       ` Bernhard Reutner-Fischer
2019-04-30  2:05             ` Joseph Myers

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=5eb4bac2-4483-2621-d606-05fa02a80df1@suse.cz \
    --to=mliska@suse.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hubicka@ucw.cz \
    --cc=joseph@codesourcery.com \
    --cc=richard.guenther@gmail.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).