lower-bitint: Fix up handling of unsigned INTEGER_CSTs operands with lots of 1s in...
commitc75579169eba269a7c339d80b5ac0239f36a58b3
authorJakub Jelinek <jakub@redhat.com>
Fri, 12 Jan 2024 10:23:27 +0000 (12 11:23 +0100)
committerJakub Jelinek <jakub@redhat.com>
Fri, 12 Jan 2024 10:23:27 +0000 (12 11:23 +0100)
treed9661d364df2bb9103812c5904a52a723470a7f9
parent4c08f0dde4c2a48931a61b84a00d5c16f4b0e291
lower-bitint: Fix up handling of unsigned INTEGER_CSTs operands with lots of 1s in the upper bits [PR113334]

For INTEGER_CST operands, the code decides if it should emit the whole
INTEGER_CST into memory, or if there are enough upper bits either all 0s
or all 1s to warrant an optimization, where we use memory for lower limbs
or even just an INTEGER_CST for least significant limb and fill in the
rest of limbs with 0s or 1s.  Unfortunately when not using
bitint_min_cst_precision, the code was using tree_int_cst_sgn (op) < 0
to determine whether to fill in the upper bits with 1s or 0s.  That is
incorrect for TYPE_UNSIGNED INTEGER_CSTs which have higher limbs full of
ones, we really want to check here whether the most significant bit is
set or clear.

Fixed thusly.

2024-01-12  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/113334
* gimple-lower-bitint.cc (bitint_large_huge::handle_operand): Use
wi::neg_p (wi::to_wide (op)) instead of tree_int_cst_sgn (op) < 0
to determine if number should be extended by all ones rather than zero
extended.

* gcc.dg/torture/bitint-46.c: New test.
gcc/gimple-lower-bitint.cc
gcc/testsuite/gcc.dg/torture/bitint-46.c [new file with mode: 0644]