$subject. Bootstrap ongoing on x86_64-unknown-linux-gnu.
Richard. 2014-08-20 Richard Biener <rguent...@suse.de> * genmatch.c (copy_reverse): New function. (parse_simplify): Support nested inner ifs. * match-comparison.pd: Use nested inner ifs. Index: match-and-simplify/gcc/genmatch.c =================================================================== *** match-and-simplify.orig/gcc/genmatch.c 2014-08-20 14:41:39.517805937 +0200 --- match-and-simplify/gcc/genmatch.c 2014-08-20 15:15:01.272668118 +0200 *************** parse_op (cpp_reader *r) *** 2223,2231 **** return op; } /* Parse ! (simplify "<ident>" ! <op> <op>) */ static void parse_simplify (cpp_reader *r, source_location match_location, --- 2223,2245 ---- return op; } + /* Return a reversed copy of V. */ + + static vec<operand *> + copy_reverse (vec<operand *> v) + { + vec<operand *> c = vNULL; + for (int i = v.length ()-1; i >= 0; --i) + c.safe_push (v[i]); + return c; + } + /* Parse ! 'simplify' [ <ident> ] <expr> <result-op> ! with ! <result-op> = <op> | <cond-result> ! <cond-result> = '(' 'if' '(' <c-expr> ')' <result-op> ')' ! and fill SIMPLIFIERS with the results. */ static void parse_simplify (cpp_reader *r, source_location match_location, *************** parse_simplify (cpp_reader *r, source_lo *** 2249,2290 **** token = peek (r); ! operand *result = NULL; ! source_location result_loc; ! while (!result ! && token->type == CPP_OPEN_PAREN) { ! eat_token (r, CPP_OPEN_PAREN); ! if (peek_ident (r, "if")) { ! vec<operand *> ifexprs = vNULL; ! eat_ident (r, "if"); ! ifexprs.safe_push (parse_c_expr (r, CPP_OPEN_PAREN)); ! /* ??? Support nested (if ...) here. */ ! token = peek (r); ! simplifiers.safe_push ! (new simplify (id, match, match_location, parse_op (r), ! token->src_loc, ifexprs)); } else { ! result_loc = token->src_loc; ! result = parse_expr (r); } - eat_token (r, CPP_CLOSE_PAREN); token = peek (r); } - - if (!result - && token->type != CPP_CLOSE_PAREN) - { - result_loc = token->src_loc; - result = parse_op (r); - } - - if (result) - simplifiers.safe_push - (new simplify (id, match, match_location, result, result_loc)); } void parse_pattern (cpp_reader *, vec<simplify *>&); --- 2263,2323 ---- token = peek (r); ! auto_vec<operand *> ifexprs; ! while (1) { ! if (token->type == CPP_OPEN_PAREN) { ! eat_token (r, CPP_OPEN_PAREN); ! if (peek_ident (r, "if")) ! { ! eat_ident (r, "if"); ! ifexprs.safe_push (parse_c_expr (r, CPP_OPEN_PAREN)); ! } ! else ! { ! simplifiers.safe_push ! (new simplify (id, match, match_location, parse_expr (r), ! token->src_loc, copy_reverse (ifexprs))); ! eat_token (r, CPP_CLOSE_PAREN); ! /* A "default" result closes the enclosing scope. */ ! if (ifexprs.length () > 0) ! { ! eat_token (r, CPP_CLOSE_PAREN); ! ifexprs.pop (); ! } ! else ! return; ! } ! } ! else if (token->type == CPP_CLOSE_PAREN) ! { ! /* Close a scope if requested. */ ! if (ifexprs.length () > 0) ! { ! eat_token (r, CPP_CLOSE_PAREN); ! ifexprs.pop (); ! token = peek (r); ! } ! else ! return; } else { ! simplifiers.safe_push ! (new simplify (id, match, match_location, parse_op (r), ! token->src_loc, copy_reverse (ifexprs))); ! /* A "default" result closes the enclosing scope. */ ! if (ifexprs.length () > 0) ! { ! eat_token (r, CPP_CLOSE_PAREN); ! ifexprs.pop (); ! } ! else ! return; } token = peek (r); } } void parse_pattern (cpp_reader *, vec<simplify *>&); Index: match-and-simplify/gcc/match-comparison.pd =================================================================== *** match-and-simplify.orig/gcc/match-comparison.pd 2014-08-20 14:41:39.517805937 +0200 --- match-and-simplify/gcc/match-comparison.pd 2014-08-20 15:02:09.222721273 +0200 *************** *** 7,16 **** to use by using swap_tree_comparison. Here we manage to use only two patterns by swapping the operands instead of changing the comparison code. */ ! (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)) ! && tree_int_cst_sgn (@1) > 0) ! (op @0 @2)) ! (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)) ! && tree_int_cst_sgn (@1) < 0) ! (op @2 @0)))) --- 7,15 ---- to use by using swap_tree_comparison. Here we manage to use only two patterns by swapping the operands instead of changing the comparison code. */ ! (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))) ! (if (tree_int_cst_sgn (@1) > 0) ! (op @0 @2)) ! (if (tree_int_cst_sgn (@1) < 0) ! (op @2 @0)))))