From d95ab70a3cab2998b4671d842e1ad769e75f19a3 Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Wed, 2 Dec 2015 09:08:49 +0000 Subject: PR 68432: Add a target hook to control size/speed optab choices The problem in the PR is that some i386 optabs FAIL when optimising for size rather than speed. The gimple level generally needs access to this information before calling the generator, so this patch adds a new hook to say whether an optab should be used when optimising for size or speed. It also has a "both" option for cases where we want code that is optimised for both size and speed. I've passed the optab to the target hook because I think in most cases that's more useful than the instruction code. We could pass both if there's a use for it though. At the moment the match-and-simplify code doesn't have direct access to the target block, so for now I've used "both" there. Tested on x86_64-linux-gnu and powerpc64-linux-gnu. gcc/ PR tree-optimization/68432 * coretypes.h (optimization_type): New enum. * doc/tm.texi.in (TARGET_OPTAB_SUPPORTED_P): New hook. * doc/tm.texi: Regenerate. * target.def (optab_supported_p): New hook. * targhooks.h (default_optab_supported_p): Declare. * targhooks.c (default_optab_supported_p): New function. * predict.h (function_optimization_type): Declare. (bb_optimization_type): Likewise. * predict.c (function_optimization_type): New function. (bb_optimization_type): Likewise. * optabs-query.h (convert_optab_handler): Define an overload that takes an optimization type. (direct_optab_handler): Likewise. * optabs-query.c (convert_optab_handler): Likewise. (direct_optab_handler): Likewise. * internal-fn.h (direct_internal_fn_supported_p): Take an optimization_type argument. * internal-fn.c (direct_optab_supported_p): Likewise. (multi_vector_optab_supported_p): Likewise. (direct_internal_fn_supported_p): Likewise. * builtins.c (replacement_internal_fn): Update call to direct_internal_fn_supported_p. * gimple-match-head.c (build_call_internal): Likewise. * tree-vect-patterns.c (vect_recog_pow_pattern): Likewise. * tree-vect-stmts.c (vectorizable_internal_function): Likewise. * tree.c (maybe_build_call_expr_loc): Likewise. * config/i386/i386.c (ix86_optab_supported_p): New function. (TARGET_OPTAB_SUPPORTED_P): Define. * config/i386/i386.md (asinxf2): Remove optimize_insn_for_size_p check. (asin2, acosxf2, acos2, log1pxf2, log1p2) (expNcorexf3, expxf2, exp2, exp10xf2, exp102, exp2xf2) (exp22, expm1xf2, expm12, ldexpxf3, ldexp3) (scalbxf3, scalb3, rint2, round2) (xf2, 2): Likewise. gcc/testsuite/ * gcc.target/i386/pr68432-1.c: New test. * gcc.target/i386/pr68432-2.c: Likewise. * gcc.target/i386/pr68432-3.c: Likewise. From-SVN: r231161 --- gcc/predict.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'gcc/predict.c') diff --git a/gcc/predict.c b/gcc/predict.c index 7e0f848..d5c40de 100644 --- a/gcc/predict.c +++ b/gcc/predict.c @@ -269,6 +269,16 @@ optimize_function_for_speed_p (struct function *fun) return !optimize_function_for_size_p (fun); } +/* Return the optimization type that should be used for the function FUN. */ + +optimization_type +function_optimization_type (struct function *fun) +{ + return (optimize_function_for_speed_p (fun) + ? OPTIMIZE_FOR_SPEED + : OPTIMIZE_FOR_SIZE); +} + /* Return TRUE when BB should be optimized for size. */ bool @@ -286,6 +296,16 @@ optimize_bb_for_speed_p (const_basic_block bb) return !optimize_bb_for_size_p (bb); } +/* Return the optimization type that should be used for block BB. */ + +optimization_type +bb_optimization_type (const_basic_block bb) +{ + return (optimize_bb_for_speed_p (bb) + ? OPTIMIZE_FOR_SPEED + : OPTIMIZE_FOR_SIZE); +} + /* Return TRUE when BB should be optimized for size. */ bool -- cgit v1.1