Add -fbit-tests option.
authorMartin Liska <mliska@suse.cz>
Fri, 2 Oct 2020 12:12:06 +0000 (14:12 +0200)
committerMartin Liska <mliska@suse.cz>
Fri, 6 Nov 2020 15:54:26 +0000 (16:54 +0100)
gcc/ChangeLog:

* common.opt: Add new -fbit-tests option.
* doc/invoke.texi: Document the option.
* tree-switch-conversion.c (bit_test_cluster::find_bit_tests):
Use the option.
* tree-switch-conversion.h (is_enabled): New function.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/switch-4.c: New test.

gcc/common.opt
gcc/doc/invoke.texi
gcc/testsuite/gcc.dg/tree-ssa/switch-4.c [new file with mode: 0644]
gcc/tree-switch-conversion.c
gcc/tree-switch-conversion.h

index d4cbb2f..7d0e0d9 100644 (file)
@@ -1940,6 +1940,10 @@ fjump-tables
 Common Var(flag_jump_tables) Init(1) Optimization
 Use jump tables for sufficiently large switch statements.
 
+fbit-tests
+Common Var(flag_bit_tests) Init(1) Optimization
+Use bit tests for sufficiently large switch statements.
+
 fkeep-inline-functions
 Common Report Var(flag_keep_inline_functions)
 Generate code for functions even if they are fully inlined.
index 32f90ef..271373c 100644 (file)
@@ -638,7 +638,7 @@ Objective-C and Objective-C++ Dialects}.
 -fno-gnu-unique @gol
 -finhibit-size-directive  -fcommon  -fno-ident @gol
 -fpcc-struct-return  -fpic  -fPIC  -fpie  -fPIE  -fno-plt @gol
--fno-jump-tables @gol
+-fno-jump-tables -fno-bit-tests @gol
 -frecord-gcc-switches @gol
 -freg-struct-return  -fshort-enums  -fshort-wchar @gol
 -fverbose-asm  -fpack-struct[=@var{n}]  @gol
@@ -15989,6 +15989,12 @@ building code that forms part of a dynamic linker and cannot
 reference the address of a jump table.  On some targets, jump tables
 do not require a GOT and this option is not needed.
 
+@item -fno-bit-tests
+@opindex fno-bit-tests
+@opindex fbit-tests
+Do not use bit tests for switch statements even where it would be
+more efficient than other code generation strategies.
+
 @item -ffixed-@var{reg}
 @opindex ffixed
 Treat the register named @var{reg} as a fixed register; generated code
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/switch-4.c b/gcc/testsuite/gcc.dg/tree-ssa/switch-4.c
new file mode 100644 (file)
index 0000000..5953ef3
--- /dev/null
@@ -0,0 +1,25 @@
+/* { dg-do compile { target { { x86_64-*-* aarch64-*-* ia64-*-* powerpc64-*-* } && lp64 } } } */
+/* { dg-options "-O2 -fno-bit-tests -fdump-tree-switchlower1" } */
+
+int global;
+
+int foo (int x)
+{
+  switch (x) {
+    case 0:
+    case 10:
+      return 1;
+    case 20:
+    case 30:
+    case 62:
+      return 2;
+    case 1000:
+    case 1010:
+    case 1025 ... 1030:
+      return 1;
+    default:
+      return 0;
+  }
+}
+
+/* { dg-final { scan-tree-dump-not "BT:" "switchlower1" } } */
index 03a1fe6..426462e 100644 (file)
@@ -1310,6 +1310,9 @@ jump_table_cluster::is_beneficial (const vec<cluster *> &,
 vec<cluster *>
 bit_test_cluster::find_bit_tests (vec<cluster *> &clusters)
 {
+  if (!is_enabled ())
+    return clusters.copy ();
+
   unsigned l = clusters.length ();
   auto_vec<min_cluster_item> min;
   min.reserve (l + 1);
index dbfd9ee..7515e95 100644 (file)
@@ -411,6 +411,12 @@ public:
                                                    basic_block case_bb,
                                                    profile_probability prob);
 
+  /* Return whether bit test expansion is allowed.  */
+  static inline bool is_enabled (void)
+  {
+    return flag_bit_tests;
+  }
+
   /* True when the jump table handles an entire switch statement.  */
   bool m_handles_entire_switch;