This moves handling of constant folding and operand order canonicalization to the folding worker instead of doing that only when building a stmt as fallback. Matches what fold_unary vs. fold_build does.
Applied to branch. Richard. 2014-03-11 Richard Biener <rguent...@suse.de> * gimple-fold.c (gimple_build): Move constant folding and operand order canonicalization ... * gimple-match-head.c (gimple_match_and_simplify): ... here. Index: gcc/gimple-fold.c =================================================================== *** gcc/gimple-fold.c (revision 208478) --- gcc/gimple-fold.c (working copy) *************** gimple_build (gimple_seq *seq, location_ *** 3637,3649 **** enum tree_code code, tree type, tree op0, tree (*valueize)(tree)) { - if (CONSTANT_CLASS_P (op0)) - { - tree res = fold_unary_to_constant (code, type, op0); - if (res != NULL_TREE) - return res; - } - tree res = gimple_match_and_simplify (code, type, op0, seq, valueize); if (!res) { --- 3637,3642 ---- *************** gimple_build (gimple_seq *seq, location_ *** 3674,3698 **** enum tree_code code, tree type, tree op0, tree op1, tree (*valueize)(tree)) { - if (CONSTANT_CLASS_P (op0) && CONSTANT_CLASS_P (op1)) - { - tree res = fold_binary_to_constant (code, type, op0, op1); - /* ??? We can't assert that we fold this to a constant as - for example we can't fold things like 1 / 0. */ - if (res != NULL_TREE) - return res; - } - - /* Canonicalize operand order both for matching and fallback stmt - generation. */ - if (commutative_tree_code (code) - && tree_swap_operands_p (op0, op1, false)) - { - tree tem = op0; - op0 = op1; - op1 = tem; - } - tree res = gimple_match_and_simplify (code, type, op0, op1, seq, valueize); if (!res) { --- 3667,3672 ---- *************** gimple_build (gimple_seq *seq, location_ *** 3716,3740 **** enum tree_code code, tree type, tree op0, tree op1, tree op2, tree (*valueize)(tree)) { - if (CONSTANT_CLASS_P (op0) && CONSTANT_CLASS_P (op1) - && CONSTANT_CLASS_P (op2)) - { - tree res = fold_ternary/*_to_constant */ (code, type, op0, op1, op2); - if (res != NULL_TREE - && CONSTANT_CLASS_P (res)) - return res; - } - - /* Canonicalize operand order both for matching and fallback stmt - generation. */ - if (commutative_ternary_tree_code (code) - && tree_swap_operands_p (op0, op1, false)) - { - tree tem = op0; - op0 = op1; - op1 = tem; - } - tree res = gimple_match_and_simplify (code, type, op0, op1, op2, seq, valueize); if (!res) --- 3690,3695 ---- *************** gimple_build (gimple_seq *seq, location_ *** 3765,3779 **** enum built_in_function fn, tree type, tree arg0, tree (*valueize)(tree)) { - if (CONSTANT_CLASS_P (arg0)) - { - tree decl = builtin_decl_implicit (fn); - tree res = fold_builtin_n (loc, decl, &arg0, 1, false); - gcc_assert (res != NULL_TREE - && CONSTANT_CLASS_P (res)); - return res; - } - tree res = gimple_match_and_simplify (fn, type, arg0, seq, valueize); if (!res) { --- 3720,3725 ---- Index: gcc/gimple-match-head.c =================================================================== *** gcc/gimple-match-head.c (revision 208478) --- gcc/gimple-match-head.c (working copy) *************** gimple_match_and_simplify (enum tree_cod *** 247,252 **** --- 247,259 ---- tree op0, gimple_seq *seq, tree (*valueize)(tree)) { + if (CONSTANT_CLASS_P (op0)) + { + tree res = fold_unary_to_constant (code, type, op0); + if (res != NULL_TREE) + return res; + } + code_helper rcode; tree ops[3] = {}; if (!gimple_match_and_simplify (code, type, op0, *************** gimple_match_and_simplify (enum tree_cod *** 260,265 **** --- 267,291 ---- tree op0, tree op1, gimple_seq *seq, tree (*valueize)(tree)) { + if (CONSTANT_CLASS_P (op0) && CONSTANT_CLASS_P (op1)) + { + tree res = fold_binary_to_constant (code, type, op0, op1); + /* ??? We can't assert that we fold this to a constant as + for example we can't fold things like 1 / 0. */ + if (res != NULL_TREE) + return res; + } + + /* Canonicalize operand order both for matching and fallback stmt + generation. */ + if (commutative_tree_code (code) + && tree_swap_operands_p (op0, op1, false)) + { + tree tem = op0; + op0 = op1; + op1 = tem; + } + code_helper rcode; tree ops[3] = {}; if (!gimple_match_and_simplify (code, type, op0, op1, *************** gimple_match_and_simplify (enum tree_cod *** 273,278 **** --- 299,323 ---- tree op0, tree op1, tree op2, gimple_seq *seq, tree (*valueize)(tree)) { + if (CONSTANT_CLASS_P (op0) && CONSTANT_CLASS_P (op1) + && CONSTANT_CLASS_P (op2)) + { + tree res = fold_ternary/*_to_constant */ (code, type, op0, op1, op2); + if (res != NULL_TREE + && CONSTANT_CLASS_P (res)) + return res; + } + + /* Canonicalize operand order both for matching and fallback stmt + generation. */ + if (commutative_ternary_tree_code (code) + && tree_swap_operands_p (op0, op1, false)) + { + tree tem = op0; + op0 = op1; + op1 = tem; + } + code_helper rcode; tree ops[3] = {}; if (!gimple_match_and_simplify (code, type, op0, op1, op2, *************** gimple_match_and_simplify (enum built_in *** 286,291 **** --- 331,345 ---- tree arg0, gimple_seq *seq, tree (*valueize)(tree)) { + if (CONSTANT_CLASS_P (arg0)) + { + tree decl = builtin_decl_implicit (fn); + tree res = fold_builtin_n (UNKNOWN_LOCATION, decl, &arg0, 1, false); + if (res != NULL_TREE + && CONSTANT_CLASS_P (res)) + return res; + } + code_helper rcode; tree ops[3] = {}; if (!gimple_match_and_simplify (fn, type, arg0,