This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch tree-optimization]: Improve handling of conditional-branches on targets with high branch costs
- From: Kai Tietz <ktietz at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Richard Guenther <richard dot guenther at gmail dot com>, Richard Henderson <rth at redhat dot com>
- Date: Thu, 06 Oct 2011 05:22:17 -0400 (EDT)
- Subject: [patch tree-optimization]: Improve handling of conditional-branches on targets with high branch costs
Hello,
this patch improves in fold_truth_andor the generation of branch-conditions for targets having LOGICAL_OP_NON_SHORT_CIRCUIT set. If right-hand side operation of a TRUTH_(OR|AND)IF_EXPR is simple operand, has no side-effects, and doesn't trap, then try to convert expression to a TRUTH_(AND|OR)_EXPR, if left-hand operand is a simple operand, and has no side-effects.
ChangeLog
2011-10-06 Kai Tietz <ktietz@redhat.com>
* fold-const.c (fold_truth_andor): Convert TRUTH_(AND|OR)IF_EXPR
to TRUTH_OR_EXPR, if suitable.
Bootstrapped and tested for all languages (including Ada and Obj-C++) on host x86_64-unknown-linux-gnu. Ok for apply?
Regards,
Kai
Index: gcc/gcc/fold-const.c
===================================================================
--- gcc.orig/gcc/fold-const.c
+++ gcc/gcc/fold-const.c
@@ -8386,6 +8390,33 @@ fold_truth_andor (location_t loc, enum t
if ((tem = fold_truthop (loc, code, type, arg0, arg1)) != 0)
return tem;
+ if ((code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR)
+ && !TREE_SIDE_EFFECTS (arg1)
+ && simple_operand_p (arg1)
+ && LOGICAL_OP_NON_SHORT_CIRCUIT
+ && !FLOAT_TYPE_P (TREE_TYPE (arg1))
+ && ((TREE_CODE_CLASS (TREE_CODE (arg1)) != tcc_comparison
+ && TREE_CODE (TREE_CODE (arg1)) != TRUTH_NOT_EXPR)
+ || !FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (arg1, 0)))))
+ {
+ if (TREE_CODE (arg0) == code
+ && !TREE_SIDE_EFFECTS (TREE_OPERAND (arg0, 1))
+ && simple_operand_p (TREE_OPERAND (arg0, 1)))
+ {
+ tem = build2_loc (loc,
+ (code == TRUTH_ANDIF_EXPR ? TRUTH_AND_EXPR
+ (code == TRUTH_ANDIF_EXPR ? TRUTH_AND_EXPR
+ : TRUTH_OR_EXPR),
+ type, TREE_OPERAND (arg0, 1), arg1);
+ return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), tem);
+ }
+ if (!TREE_SIDE_EFFECTS (arg0)
+ && simple_operand_p (arg0))
+ return build2_loc (loc,
+ (code == TRUTH_ANDIF_EXPR ? TRUTH_AND_EXPR
+ : TRUTH_OR_EXPR),
+ type, arg0, arg1);
+ }
+
return NULL_TREE;
}