]> git.ipfire.org Git - thirdparty/gcc.git/commit
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)
committerGiuliano Belinassi <giuliano.belinassi@usp.br>
Mon, 17 Aug 2020 16:15:05 +0000 (13:15 -0300)
commitc295d6ff2c6287377c87f749bcff6cb1775da206
tree7d06f412b609803e8252f2d97dffdd420a512744
parentf1ec0db18177387c69c71834bfff2504d92195a2
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