Support {MIN,MAX}_EXPR in GIMPLE FE.

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

	* gimple-pretty-print.c (dump_binary_rhs): Dump MIN_EXPR
	and MAX_EXPR in GIMPLE FE format.
2019-05-09  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.
2019-05-09  Martin Liska  <mliska@suse.cz>

	* gcc.dg/gimplefe-39.c: New test.

From-SVN: r271035
This commit is contained in:
Martin Liska 2019-05-09 15:03:45 +02:00 committed by Martin Liska
parent d276406ac1
commit fd4485aa04
6 changed files with 89 additions and 2 deletions

View File

@ -1,3 +1,8 @@
2019-05-09 Martin Liska <mliska@suse.cz>
* gimple-pretty-print.c (dump_binary_rhs): Dump MIN_EXPR
and MAX_EXPR in GIMPLE FE format.
2019-05-09 Martin Liska <mliska@suse.cz>
* tree-cfg.c (dump_function_to_file): Dump entry BB count.

View File

@ -1,3 +1,11 @@
2019-05-09 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.
2019-05-09 Martin Liska <mliska@suse.cz>
* gimple-parser.c (struct gimple_parser): Add probability.

View File

@ -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);
}

View File

@ -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:

View File

@ -1,3 +1,7 @@
2019-05-09 Martin Liska <mliska@suse.cz>
* gcc.dg/gimplefe-39.c: New test.
2019-05-09 Martin Liska <mliska@suse.cz>
* gcc.dg/gimplefe-37.c: New test.

View File

@ -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" } } */