Patchwork [tree-optimization] : Improve handling of conditional-branches on targets with high branch costs

login
register
mail settings
Submitter Kai Tietz
Date Oct. 6, 2011, 9:22 a.m.
Message ID <503a466e-2de1-4e7b-a8bb-819d5d1f155c@zmail06.collab.prod.int.phx2.redhat.com>
Download mbox | patch
Permalink /patch/117979/
State New
Headers show

Comments

Kai Tietz - Oct. 6, 2011, 9:22 a.m.
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

Patch

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;
 }