Take into account range info to optimize range tests into bit tests
authorEric Botcazou <ebotcazou@gcc.gnu.org>
Fri, 26 Jun 2020 13:23:05 +0000 (15:23 +0200)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Fri, 26 Jun 2020 13:26:48 +0000 (15:26 +0200)
commitb3d77404c060c0d65d8d4c97254995737d0fc032
treeea830543f92f5c3fc7054078e9352a15d9f1093e
parent2ca78835619f0f24c1fe5d74828d8dc95900fe96
Take into account range info to optimize range tests into bit tests

The patch is aimed at addressing the following two issues:

  1. In order to protect the shift operation from undefinedness, the
new bit test is guarded with a new test, but this new test uses the
range of the bit test values, not that of the shift operation so,
if the input is in the range of the shift operation but not of the
bit test values, then the subsequent VRP pass cannot eliminate the
new test.  Moreover changing the new test to use the range of the
shift operation, instead of that of the bit test values, in the
general case would pessimize the cases which are in between.

  2. If the new test can be eliminated, then it becomes profitable
to do the optimization into a bit test for one fewer comparison in
the source code.

Therefore the patch changes optimize_range_tests_to_bit_test to use
the range info of the input in order to eliminate the new test.

gcc/ChangeLog:
* tree-ssa-reassoc.c (dump_range_entry): New function.
(debug_range_entry): New debug function.
(update_range_test): Invoke dump_range_entry for dumping.
(optimize_range_tests_to_bit_test): Merge the entry test in the
bit test when possible and lower the profitability threshold.

gcc/ada/ChangeLog:
* exp_ch4.adb (Expand_Set_Membership): Expand the membership test
using left associativity instead of right associativity.

gcc/testsuite/ChangeLog:
* gnat.dg/opt86_pkg.ads: New helper.
* gnat.dg/opt86a.adb: New test.
* gnat.dg/opt86b.adb: Likewise.
* gnat.dg/opt86c.adb: Likewise.
gcc/ada/exp_ch4.adb
gcc/testsuite/gnat.dg/opt86_pkg.ads [new file with mode: 0644]
gcc/testsuite/gnat.dg/opt86a.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/opt86b.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/opt86c.adb [new file with mode: 0644]
gcc/tree-ssa-reassoc.c