From: Richard Biener Date: Fri, 17 Oct 2014 11:32:12 +0000 (+0000) Subject: fold-const.c (fold_comparison): Remove redundant constant folding and operand swapping. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a342326069ab45d77f0e508983321e613c4acac2;p=gcc.git fold-const.c (fold_comparison): Remove redundant constant folding and operand swapping. 2014-10-17 Richard Biener * fold-const.c (fold_comparison): Remove redundant constant folding and operand swapping. (fold_binary_loc): Do comparison operand swapping here. (fold_ternary_loc): Canonicalize operand order for commutative ternary operations. * tree.c (commutative_ternary_tree_code): Add DOT_PROD_EXPR and FMA_EXPR. From-SVN: r216394 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 28ab841634b..b17de87018c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2014-10-17 Richard Biener + + * fold-const.c (fold_comparison): Remove redundant constant + folding and operand swapping. + (fold_binary_loc): Do comparison operand swapping here. + (fold_ternary_loc): Canonicalize operand order for + commutative ternary operations. + * tree.c (commutative_ternary_tree_code): Add DOT_PROD_EXPR + and FMA_EXPR. + 2014-10-17 Jakub Jelinek PR tree-optimization/63464 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 9f1bc098ed3..1e7e9322d17 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -8721,14 +8721,6 @@ fold_comparison (location_t loc, enum tree_code code, tree type, STRIP_SIGN_NOPS (arg0); STRIP_SIGN_NOPS (arg1); - tem = fold_relational_const (code, type, arg0, arg1); - if (tem != NULL_TREE) - return tem; - - /* If one arg is a real or integer constant, put it last. */ - if (tree_swap_operands_p (arg0, arg1, true)) - return fold_build2_loc (loc, swap_tree_comparison (code), type, op1, op0); - /* Transform comparisons of the form X +- C1 CMP C2 to X CMP C2 -+ C1. */ if ((TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR) && (equality_code || TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg0))) @@ -9915,6 +9907,12 @@ fold_binary_loc (location_t loc, && tree_swap_operands_p (arg0, arg1, true)) return fold_build2_loc (loc, code, type, op1, op0); + /* Likewise if this is a comparison, and ARG0 is a constant, move it + to ARG1 to reduce the number of tests below. */ + if (kind == tcc_comparison + && tree_swap_operands_p (arg0, arg1, true)) + return fold_build2_loc (loc, swap_tree_comparison (code), type, op1, op0); + /* ARG0 is the first operand of EXPR, and ARG1 is the second operand. First check for cases where an arithmetic operation is applied to a @@ -13799,6 +13797,12 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type, gcc_assert (IS_EXPR_CODE_CLASS (kind) && TREE_CODE_LENGTH (code) == 3); + /* If this is a commutative operation, and OP0 is a constant, move it + to OP1 to reduce the number of tests below. */ + if (commutative_ternary_tree_code (code) + && tree_swap_operands_p (op0, op1, true)) + return fold_build3_loc (loc, code, type, op1, op0, op2); + /* Strip any conversions that don't change the mode. This is safe for every expression, except for a comparison expression because its signedness is derived from its operands. So, in the latter diff --git a/gcc/tree.c b/gcc/tree.c index fbe35d8cc9c..365e89c4d6c 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -7385,6 +7385,8 @@ commutative_ternary_tree_code (enum tree_code code) { case WIDEN_MULT_PLUS_EXPR: case WIDEN_MULT_MINUS_EXPR: + case DOT_PROD_EXPR: + case FMA_EXPR: return true; default: