From patchwork Thu Apr 21 19:02:10 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Meissner X-Patchwork-Id: 92445 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id C7A93B6EDF for ; Fri, 22 Apr 2011 05:03:42 +1000 (EST) Received: (qmail 12010 invoked by alias); 21 Apr 2011 19:03:41 -0000 Received: (qmail 11992 invoked by uid 22791); 21 Apr 2011 19:03:39 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL, BAYES_00, NO_DNS_FOR_FROM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from e2.ny.us.ibm.com (HELO e2.ny.us.ibm.com) (32.97.182.142) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 21 Apr 2011 19:03:25 +0000 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by e2.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p3LIhrdu017205 for ; Thu, 21 Apr 2011 14:43:53 -0400 Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p3LJ2wX4116808 for ; Thu, 21 Apr 2011 15:02:59 -0400 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p3LJ2v3w018741 for ; Thu, 21 Apr 2011 13:02:57 -0600 Received: from hungry-tiger.westford.ibm.com (dyn9033037078.westford.ibm.com [9.33.37.78]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p3LJ2CPZ011540; Thu, 21 Apr 2011 13:02:12 -0600 Received: by hungry-tiger.westford.ibm.com (Postfix, from userid 500) id 0BD7AF7D4A; Thu, 21 Apr 2011 15:02:10 -0400 (EDT) Date: Thu, 21 Apr 2011 15:02:10 -0400 From: Michael Meissner To: gcc-patches@gcc.gnu.org, dje.gcc@gmail.com Subject: [PATCH] PR 48175, Make CASE_VALUES_THRESHOLD settable via --param Message-ID: <20110421190210.GA12527@hungry-tiger.westford.ibm.com> Mail-Followup-To: Michael Meissner , gcc-patches@gcc.gnu.org, dje.gcc@gmail.com MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org In looking at some improvements to the powerpc, we wanted to change the default for when a table jump is generated vs. a series of if statements. Now, we could just add a powerpc specific TARGET_CASE_VALUES_THRESHOLD, but I tend to think that these should be settable on all/most ports with --param. At present, there are only two ports (avr and mn10300) that define their own TARGET_CASE_VALUES_THRESHOLD hook. My first patch does not remove the target hook and modify the avr/mn10300 ports to use maybe_set_param_value, but that can be done if desired. The patch adds two --param values, one for when the port is using the casesi insn, and the other when it uses the more primitive tablejump insn. I have bootstrapped the compiler with this patch and run the test suite with no regressions. Is it ok to apply as is? Should I modify the avr and mn10300 ports to use the parameters and do away with the target hook? Or should I do this just as a powerpc target hook? [gcc] 2011-04-21 Michael Meissner PR rtl-optimization/48715 * params.def (PARAM_CASE_VALUES_THRESHOD_CASESI): New parameter. (PARAM_CASE_VALUES_THRESHOLD_TABLEJUMP): Ditto. * params.h (CASE_VALUES_THRESHOLD_CASESI): Define. (CASE_VALUES_THRESHOLD_TABLEJUMP): Ditto. * targhooks.c (toplevel): Include params.h. (default_case_values_threshold): Use CASE_VALUES_THRESHOLD_CASESI and CASE_VALUES_THRESHOLD_TABLEJUMP. * Makefile.in (targhooks.o): Add $(PARAMS_H) dependency. * doc/invoke.texi (case-values-threshold-casesi): Document. (case-values-threshold-tablejump): Ditto. [gcc/testsuite] 2011-04-21 Michael Meissner PR rtl-optimization/48715 * gcc.target/powerpc/case-threshold1.c: New file to test --param case-values-threshold-tablejump. * gcc.target/powerpc/case-threshold2.c: Ditto. Index: gcc/params.def =================================================================== --- gcc/params.def (revision 172832) +++ gcc/params.def (working copy) @@ -885,6 +885,22 @@ DEFPARAM (PARAM_MAX_STORES_TO_SINK, 2, 0, 0) +/* Threshold for using jump table vs. if statements if the machine supports a + CASESI instruction. */ +DEFPARAM (PARAM_CASE_VALUES_THRESHOLD_CASESI, + "case-values-threshold-casesi", + "Minimum number of case elements to use a jump table instead of" + "if statements if the machine supports a CASESI instruction", + 4, 2, 0) + +/* Threshold for using jump table vs. if statements if the machine does not + support a CASESI instruction. */ +DEFPARAM (PARAM_CASE_VALUES_THRESHOLD_TABLEJUMP, + "case-values-threshold-tablejump", + "Minimum number of case elements to use a jump table instead of" + "if statements if the machine does not support a CASESI instruction", + 5, 2, 0) + /* Local variables: mode:c Index: gcc/params.h =================================================================== --- gcc/params.h (revision 172832) +++ gcc/params.h (working copy) @@ -206,4 +206,8 @@ extern void init_param_values (int *para PARAM_VALUE (PARAM_MIN_NONDEBUG_INSN_UID) #define MAX_STORES_TO_SINK \ PARAM_VALUE (PARAM_MAX_STORES_TO_SINK) +#define CASE_VALUES_THRESHOLD_CASESI \ + PARAM_VALUE (PARAM_CASE_VALUES_THRESHOLD_CASESI) +#define CASE_VALUES_THRESHOLD_TABLEJUMP \ + PARAM_VALUE (PARAM_CASE_VALUES_THRESHOLD_TABLEJUMP) #endif /* ! GCC_PARAMS_H */ Index: gcc/targhooks.c =================================================================== --- gcc/targhooks.c (revision 172832) +++ gcc/targhooks.c (working copy) @@ -71,7 +71,7 @@ along with GCC; see the file COPYING3. #include "opts.h" #include "tree-flow.h" #include "tree-ssa-alias.h" - +#include "params.h" bool default_legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED, @@ -1209,7 +1209,9 @@ default_target_can_inline_p (tree caller unsigned int default_case_values_threshold (void) { - return (HAVE_casesi ? 4 : 5); + return (HAVE_casesi + ? CASE_VALUES_THRESHOLD_CASESI + : CASE_VALUES_THRESHOLD_TABLEJUMP); } bool Index: gcc/Makefile.in =================================================================== --- gcc/Makefile.in (revision 172832) +++ gcc/Makefile.in (working copy) @@ -2807,7 +2807,7 @@ opts-common.o : opts-common.c $(OPTS_H) targhooks.o : targhooks.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TREE_H) \ $(EXPR_H) $(TM_H) $(RTL_H) $(TM_P_H) $(FUNCTION_H) output.h $(DIAGNOSTIC_CORE_H) \ $(MACHMODE_H) $(TARGET_DEF_H) $(TARGET_H) $(GGC_H) gt-targhooks.h \ - $(OPTABS_H) $(RECOG_H) reload.h hard-reg-set.h intl.h $(OPTS_H) \ + $(OPTABS_H) $(RECOG_H) reload.h hard-reg-set.h intl.h $(OPTS_H) $(PARAMS_H) \ tree-ssa-alias.h $(TREE_FLOW_H) bversion.h: s-bversion; @true Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi (revision 172832) +++ gcc/doc/invoke.texi (working copy) @@ -8889,6 +8889,16 @@ The maximum number of conditional stores if either vectorization (@option{-ftree-vectorize}) or if-conversion (@option{-ftree-loop-if-convert}) is disabled. The default is 2. +@item case-values-threshold-casesi +The minimum number of case elements to use a jump table instead of if +statements if the machine supports a @code{casesi} instruction. The +default is 4. + +@item case-values-threshold-tablejump +The minimum number of case elements to use a jump table instead of if +statements if the machine does not support a @code{casesi} +instruction. The default is 5. + @end table @end table Index: gcc/testsuite/gcc.target/powerpc/case-threshold1.c =================================================================== --- gcc/testsuite/gcc.target/powerpc/case-threshold1.c (revision 0) +++ gcc/testsuite/gcc.target/powerpc/case-threshold1.c (revision 0) @@ -0,0 +1,26 @@ +/* Insure case-values-threshold is obeyed. This test should generate if + statements and not a table jump. */ +/* { dg-do compile } */ +/* { dg-options "-O2 --param case-values-threshold-tablejump=11" } */ + +/* { dg-final { scan-assembler-not "mtctr" } } */ +/* { dg-final { scan-assembler-not "bctr" } } */ + +int +switch_10 (int a, int b) +{ + switch (a) + { + case 0: return b + 1; + case 1: return b - 2; + case 2: return b * 3; + case 3: return b / 4; + case 4: return b % 5; + case 5: return b << 6; + case 6: return b >> 7; + case 7: return b & 0x8; + case 8: return b | 0x9; + case 9: return b ^ 0xa; + default: return b; + } +} Index: gcc/testsuite/gcc.target/powerpc/case-threshold2.c =================================================================== --- gcc/testsuite/gcc.target/powerpc/case-threshold2.c (revision 0) +++ gcc/testsuite/gcc.target/powerpc/case-threshold2.c (revision 0) @@ -0,0 +1,26 @@ +/* Insure case-values-threshold is obeyed. This test should generate a table + jump and not if statements. */ +/* { dg-do compile } */ +/* { dg-options "-O2 --param case-values-threshold-tablejump=10" } */ + +/* { dg-final { scan-assembler "mtctr" } } */ +/* { dg-final { scan-assembler "bctr" } } */ + +int +switch_10 (int a, int b) +{ + switch (a) + { + case 0: return b + 1; + case 1: return b - 2; + case 2: return b * 3; + case 3: return b / 4; + case 4: return b % 5; + case 5: return b << 6; + case 6: return b >> 7; + case 7: return b & 0x8; + case 8: return b | 0x9; + case 9: return b ^ 0xa; + default: return b; + } +}