diff mbox

Remove CASE_USE_BIT_TESTS target macro

Message ID CABu31nNHZKdm98XCwT8ULBgyaE0s7WsPCuqt3ueZpm5AGJaE4w@mail.gmail.com
State New
Headers show

Commit Message

Steven Bosscher June 29, 2012, 2:35 p.m. UTC
Hello,

This patch removes the CASE_USE_BIT_TESTS target macro. The default
value of the macro is defined in stmt.c, where the only user of the
macro is also. No target re-defines the macro.

(I wonder if the test is necessary at all. AFAICT all targets support
shifts in word_mode. The macro was originally written to test for
ashlsi3, which is _not_ supported on all targets -- but word_mode
shifts are. Oh well, another day perhaps...)

Bootstrapped and tested on powerpc64-unknown-linux-gnu. OK for trunk?

Ciao!
Steven


	* stmt.c (CASE_USE_BIT_TESTS): Fold away into its only user ...
	(expand_switch_using_bit_tests_p): ...here.
	* doc/tm.texi.in (CASE_USE_BIT_TESTS): Remove documentation.
	* doc/tm.texi (CASE_USE_BIT_TESTS): Regenerate.

Comments

Richard Biener June 29, 2012, 2:42 p.m. UTC | #1
On Fri, Jun 29, 2012 at 4:35 PM, Steven Bosscher <stevenb.gcc@gmail.com> wrote:
> Hello,
>
> This patch removes the CASE_USE_BIT_TESTS target macro. The default
> value of the macro is defined in stmt.c, where the only user of the
> macro is also. No target re-defines the macro.
>
> (I wonder if the test is necessary at all. AFAICT all targets support
> shifts in word_mode. The macro was originally written to test for
> ashlsi3, which is _not_ supported on all targets -- but word_mode
> shifts are. Oh well, another day perhaps...)
>
> Bootstrapped and tested on powerpc64-unknown-linux-gnu. OK for trunk?

Ok.  (poison CASE_USE_BIT_TESTS?)

Thanks,
Richard.

> Ciao!
> Steven
>
>
>        * stmt.c (CASE_USE_BIT_TESTS): Fold away into its only user ...
>        (expand_switch_using_bit_tests_p): ...here.
>        * doc/tm.texi.in (CASE_USE_BIT_TESTS): Remove documentation.
>        * doc/tm.texi (CASE_USE_BIT_TESTS): Regenerate.
>
> Index: stmt.c
> ===================================================================
> --- stmt.c      (revision 189073)
> +++ stmt.c      (working copy)
> @@ -1722,13 +1722,6 @@ add_case_node (struct case_node *head, tree type,
>  /* Maximum number of case bit tests.  */
>  #define MAX_CASE_BIT_TESTS  3
>
> -/* By default, enable case bit tests on targets with ashlsi3.  */
> -#ifndef CASE_USE_BIT_TESTS
> -#define CASE_USE_BIT_TESTS  (optab_handler (ashl_optab, word_mode) \
> -                            != CODE_FOR_nothing)
> -#endif
> -
> -
>  /* A case_bit_test represents a set of case nodes that may be
>    selected from using a bit-wise comparison.  HI and LO hold
>    the integer to be tested against, LABEL contains the label
> @@ -1888,8 +1881,10 @@ bool
>  expand_switch_using_bit_tests_p (tree index_expr, tree range,
>                                 unsigned int uniq, unsigned int count)
>  {
> -  return (CASE_USE_BIT_TESTS
> -         && ! TREE_CONSTANT (index_expr)
> +  if (optab_handler (ashl_optab, word_mode) == CODE_FOR_nothing)
> +    return false;
> +
> +  return (! TREE_CONSTANT (index_expr)
>          && compare_tree_int (range, GET_MODE_BITSIZE (word_mode)) < 0
>          && compare_tree_int (range, 0) > 0
>          && lshift_cheap_p ()
> Index: doc/tm.texi
> ===================================================================
> --- doc/tm.texi (revision 189074)
> +++ doc/tm.texi (working copy)
> @@ -10306,16 +10306,6 @@ The default is four for machines with a @code{case
>  five otherwise.  This is best for most machines.
>  @end deftypefn
>
> -@defmac CASE_USE_BIT_TESTS
> -Define this macro to be a C expression to indicate whether C switch
> -statements may be implemented by a sequence of bit tests.  This is
> -advantageous on processors that can efficiently implement left shift
> -of 1 by the number of bits held in a register, but inappropriate on
> -targets that would require a loop.  By default, this macro returns
> -@code{true} if the target defines an @code{ashlsi3} pattern, and
> -@code{false} otherwise.
> -@end defmac
> -
>  @defmac WORD_REGISTER_OPERATIONS
>  Define this macro if operations between registers with integral mode
>  smaller than a word are always performed on the entire register.
> Index: doc/tm.texi.in
> ===================================================================
> --- doc/tm.texi.in      (revision 189074)
> +++ doc/tm.texi.in      (working copy)
> @@ -10180,16 +10180,6 @@ The default is four for machines with a @code{case
>  five otherwise.  This is best for most machines.
>  @end deftypefn
>
> -@defmac CASE_USE_BIT_TESTS
> -Define this macro to be a C expression to indicate whether C switch
> -statements may be implemented by a sequence of bit tests.  This is
> -advantageous on processors that can efficiently implement left shift
> -of 1 by the number of bits held in a register, but inappropriate on
> -targets that would require a loop.  By default, this macro returns
> -@code{true} if the target defines an @code{ashlsi3} pattern, and
> -@code{false} otherwise.
> -@end defmac
> -
>  @defmac WORD_REGISTER_OPERATIONS
>  Define this macro if operations between registers with integral mode
>  smaller than a word are always performed on the entire register.
Steven Bosscher June 29, 2012, 2:52 p.m. UTC | #2
On Fri, Jun 29, 2012 at 4:42 PM, Richard Guenther
<richard.guenther@gmail.com> wrote:
> On Fri, Jun 29, 2012 at 4:35 PM, Steven Bosscher <stevenb.gcc@gmail.com> wrote:
>> Hello,
>>
>> This patch removes the CASE_USE_BIT_TESTS target macro.
...
> Ok.  (poison CASE_USE_BIT_TESTS?)

Right, I've done that in the patch I commited.

Ciao!
Steven
Georg-Johann Lay June 30, 2012, 8:58 a.m. UTC | #3
Steven Bosscher schrieb:
> Hello,
> 
> This patch removes the CASE_USE_BIT_TESTS target macro. The default
> value of the macro is defined in stmt.c, where the only user of the
> macro is also. No target re-defines the macro.
> 
> (I wonder if the test is necessary at all. AFAICT all targets support
> shifts in word_mode. The macro was originally written to test for
> ashlsi3, which is _not_ supported on all targets -- but word_mode
> shifts are. Oh well, another day perhaps...)

Even if a target supports ward_mode shifts with variable offsets
it might be the case that it's not appropriate to use it in switch/case
expansion because it is too expensive.

For example, avr supports word_mode shifts but because there is no
barrel shifter, a loop has to be used. Likewise for "odd" shift
offsets with const_int offsets.

Johann

> Bootstrapped and tested on powerpc64-unknown-linux-gnu. OK for trunk?
> 
> Ciao!
> Steven
> 
> 
> 	* stmt.c (CASE_USE_BIT_TESTS): Fold away into its only user ...
> 	(expand_switch_using_bit_tests_p): ...here.
> 	* doc/tm.texi.in (CASE_USE_BIT_TESTS): Remove documentation.
> 	* doc/tm.texi (CASE_USE_BIT_TESTS): Regenerate.
Steven Bosscher June 30, 2012, 10:01 a.m. UTC | #4
On Sat, Jun 30, 2012 at 10:58 AM, Georg-Johann Lay <gjl@gcc.gnu.org> wrote:
> Steven Bosscher schrieb:
>>
>> Hello,
>>
>> This patch removes the CASE_USE_BIT_TESTS target macro. The default
>> value of the macro is defined in stmt.c, where the only user of the
>> macro is also. No target re-defines the macro.
>>
>> (I wonder if the test is necessary at all. AFAICT all targets support
>> shifts in word_mode. The macro was originally written to test for
>> ashlsi3, which is _not_ supported on all targets -- but word_mode
>> shifts are. Oh well, another day perhaps...)
>
>
> Even if a target supports ward_mode shifts with variable offsets
> it might be the case that it's not appropriate to use it in switch/case
> expansion because it is too expensive.
>
> For example, avr supports word_mode shifts but because there is no
> barrel shifter, a loop has to be used. Likewise for "odd" shift
> offsets with const_int offsets.

Cost is an orthogonal issue.

The CASE_USE_BIT_TESTS macro tests whether the operation is supported
at all for a target. There is a cost check after that to see if the
shift is cheap, see lshift_cheap_p().

Ciao!
Steven
diff mbox

Patch

Index: stmt.c
===================================================================
--- stmt.c      (revision 189073)
+++ stmt.c      (working copy)
@@ -1722,13 +1722,6 @@  add_case_node (struct case_node *head, tree type,
 /* Maximum number of case bit tests.  */
 #define MAX_CASE_BIT_TESTS  3

-/* By default, enable case bit tests on targets with ashlsi3.  */
-#ifndef CASE_USE_BIT_TESTS
-#define CASE_USE_BIT_TESTS  (optab_handler (ashl_optab, word_mode) \
-                            != CODE_FOR_nothing)
-#endif
-
-
 /* A case_bit_test represents a set of case nodes that may be
    selected from using a bit-wise comparison.  HI and LO hold
    the integer to be tested against, LABEL contains the label
@@ -1888,8 +1881,10 @@  bool
 expand_switch_using_bit_tests_p (tree index_expr, tree range,
                                 unsigned int uniq, unsigned int count)
 {
-  return (CASE_USE_BIT_TESTS
-         && ! TREE_CONSTANT (index_expr)
+  if (optab_handler (ashl_optab, word_mode) == CODE_FOR_nothing)
+    return false;
+
+  return (! TREE_CONSTANT (index_expr)
          && compare_tree_int (range, GET_MODE_BITSIZE (word_mode)) < 0
          && compare_tree_int (range, 0) > 0
          && lshift_cheap_p ()
Index: doc/tm.texi
===================================================================
--- doc/tm.texi (revision 189074)
+++ doc/tm.texi (working copy)
@@ -10306,16 +10306,6 @@  The default is four for machines with a @code{case
 five otherwise.  This is best for most machines.
 @end deftypefn

-@defmac CASE_USE_BIT_TESTS
-Define this macro to be a C expression to indicate whether C switch
-statements may be implemented by a sequence of bit tests.  This is
-advantageous on processors that can efficiently implement left shift
-of 1 by the number of bits held in a register, but inappropriate on
-targets that would require a loop.  By default, this macro returns
-@code{true} if the target defines an @code{ashlsi3} pattern, and
-@code{false} otherwise.
-@end defmac
-
 @defmac WORD_REGISTER_OPERATIONS
 Define this macro if operations between registers with integral mode
 smaller than a word are always performed on the entire register.
Index: doc/tm.texi.in
===================================================================
--- doc/tm.texi.in      (revision 189074)
+++ doc/tm.texi.in      (working copy)
@@ -10180,16 +10180,6 @@  The default is four for machines with a @code{case
 five otherwise.  This is best for most machines.
 @end deftypefn

-@defmac CASE_USE_BIT_TESTS
-Define this macro to be a C expression to indicate whether C switch
-statements may be implemented by a sequence of bit tests.  This is
-advantageous on processors that can efficiently implement left shift
-of 1 by the number of bits held in a register, but inappropriate on
-targets that would require a loop.  By default, this macro returns
-@code{true} if the target defines an @code{ashlsi3} pattern, and
-@code{false} otherwise.
-@end defmac
-
 @defmac WORD_REGISTER_OPERATIONS
 Define this macro if operations between registers with integral mode
 smaller than a word are always performed on the entire register.