From: Martin Liska Date: Thu, 9 May 2019 13:03:45 +0000 (+0200) Subject: Support {MIN,MAX}_EXPR in GIMPLE FE. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fd4485aa04b5db3f0fc367ce7aefc8431112e1a1;p=gcc.git Support {MIN,MAX}_EXPR in GIMPLE FE. 2019-05-09 Martin Liska * gimple-pretty-print.c (dump_binary_rhs): Dump MIN_EXPR and MAX_EXPR in GIMPLE FE format. 2019-05-09 Martin Liska * 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 * gcc.dg/gimplefe-39.c: New test. From-SVN: r271035 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 45360fa18ff..126a15053b6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2019-05-09 Martin Liska + + * gimple-pretty-print.c (dump_binary_rhs): Dump MIN_EXPR + and MAX_EXPR in GIMPLE FE format. + 2019-05-09 Martin Liska * tree-cfg.c (dump_function_to_file): Dump entry BB count. diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 67f0e082f00..cb8bfcbd5e8 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,11 @@ +2019-05-09 Martin Liska + + * 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 * gimple-parser.c (struct gimple_parser): Add probability. 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/ChangeLog b/gcc/testsuite/ChangeLog index 4c384eac044..a95271ccf0a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-05-09 Martin Liska + + * gcc.dg/gimplefe-39.c: New test. + 2019-05-09 Martin Liska * gcc.dg/gimplefe-37.c: New test. 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" } } */