From 85e50b6ba8ca2221593838878ab8d804b37faf44 Mon Sep 17 00:00:00 2001
From: David Edelsohn <edelsohn@gnu.org>
Date: Tue, 22 Apr 2003 15:01:18 +0000
Subject: [PATCH] fold-const.c (fold_range_test): Use
 RANGE_TEST_NON_SHORT_CIRCUIT macro defaulting to original BRANCH_COST
 heuristic.

        * fold-const.c (fold_range_test): Use RANGE_TEST_NON_SHORT_CIRCUIT
        macro defaulting to original BRANCH_COST heuristic.
        * doc/tm.texi (RANGE_TEST_NON_SHORT_CIRCUIT): Document.

        * config/rs6000/rs6000.h (RANGE_TEST_NON_SHORT_CIRCUIT): Define.

From-SVN: r65942
---
 gcc/ChangeLog              | 8 ++++++++
 gcc/config/rs6000/rs6000.h | 4 ++++
 gcc/doc/tm.texi            | 6 ++++++
 gcc/fold-const.c           | 6 +++++-
 4 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9f7fa317af89..722ce66ba2cf 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2003-04-22  David Edelsohn  <edelsohn@gnu.org>
+
+	* fold-const.c (fold_range_test): Use RANGE_TEST_NON_SHORT_CIRCUIT
+	macro defaulting to original BRANCH_COST heuristic.
+	* doc/tm.texi (RANGE_TEST_NON_SHORT_CIRCUIT): Document.
+
+	* config/rs6000/rs6000.h (RANGE_TEST_NON_SHORT_CIRCUIT): Define.
+
 2003-04-22  Aldy Hernandez  <aldyh@redhat.com>
 
         * config/rs6000/t-spe: Merge in t-fprules into file.
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index b566619e7a91..994f67af8bee 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -992,6 +992,10 @@ extern int rs6000_default_long_calls;
 
 #define BRANCH_COST 3
 
+/* Override BRANCH_COST heuristic which empirically produces worse
+   performance for fold_range_test().  */
+
+#define RANGE_TEST_NON_SHORT_CIRCUIT 0
 
 /* A fixed register used at prologue and epilogue generation to fix
    addressing modes.  The SPE needs heavy addressing fixes at the last
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 092e400dcec1..88ad237291a1 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -5529,6 +5529,12 @@ function address than to call an address kept in a register.
 Define this macro if it is as good or better for a function to call
 itself with an explicit address than to call an address kept in a
 register.
+
+@findex RANGE_TEST_NON_SHORT_CIRCUIT
+@item RANGE_TEST_NON_SHORT_CIRCUIT
+Define this macro if a non-short-circuit operation produced by
+@samp{fold_range_test ()} is optimal.  This macro defaults to true if
+@code{BRANCH_COST} is greater than or equal to the value 2.
 @end table
 
 @deftypefn {Target Hook} bool TARGET_RTX_COSTS (rtx @var{x}, int @var{code}, int @var{outer_code}, int *@var{total})
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 146f40f97ac8..eb65795e913e 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -3414,6 +3414,10 @@ merge_ranges (pin_p, plow, phigh, in0_p, low0, high0, in1_p, low1, high1)
   return 1;
 }
 
+#ifndef RANGE_TEST_NON_SHORT_CIRCUIT
+#define RANGE_TEST_NON_SHORT_CIRCUIT (BRANCH_COST >= 2)
+#endif
+
 /* EXP is some logical combination of boolean tests.  See if we can
    merge it into some range test.  Return the new tree if so.  */
 
@@ -3450,7 +3454,7 @@ fold_range_test (exp)
   /* On machines where the branch cost is expensive, if this is a
      short-circuited branch and the underlying object on both sides
      is the same, make a non-short-circuit operation.  */
-  else if (BRANCH_COST >= 2
+  else if (RANGE_TEST_NON_SHORT_CIRCUIT
 	   && lhs != 0 && rhs != 0
 	   && (TREE_CODE (exp) == TRUTH_ANDIF_EXPR
 	       || TREE_CODE (exp) == TRUTH_ORIF_EXPR)
-- 
GitLab