]> git.ipfire.org Git - thirdparty/gcc.git/commit
ifcombine field merge: handle bitfield zero tests in range tests
authorAlexandre Oliva <oliva@adacore.com>
Thu, 19 Dec 2024 01:17:18 +0000 (22:17 -0300)
committerAlexandre Oliva <oliva@gnu.org>
Thu, 19 Dec 2024 01:19:35 +0000 (22:19 -0300)
commit6d5df5133c5dd8f9ec8f213d0e51b77958a54d28
tree339ebca6b741dfd2eb288f96c7e668def69c864b
parent34e6c77da699de4cd172523310123af8e0a36a36
ifcombine field merge: handle bitfield zero tests in range tests

Some bitfield compares with zero are optimized to range tests, so
instead of X & ~(Bit - 1) != 0 what reaches ifcombine is X > (Bit - 1),
where Bit is a power of two and X is unsigned.

This patch recognizes this optimized form of masked compares, and
attempts to merge them like masked compares, which enables some more
field merging that a folder version of fold_truth_andor used to handle
without additional effort.

I haven't seen X & ~(Bit - 1) == 0 become X <= (Bit - 1), or X < Bit
for that matter, but it was easy enough to handle the former
symmetrically to the above.

The latter was also easy enough, and so was its symmetric, X >= Bit,
that is handled like X & ~(Bit - 1) != 0.

for  gcc/ChangeLog

* gimple-fold.cc (decode_field_reference): Accept incoming
mask.
(fold_truth_andor_for_ifcombine): Handle some compares with
powers of two, minus 1 or 0, like masked compares with zero.

for  gcc/testsuite/ChangeLog

* gcc.dg/field-merge-15.c: New.
gcc/gimple-fold.cc
gcc/testsuite/gcc.dg/field-merge-15.c [new file with mode: 0644]