On 4/10/23 01:10, Jakub Jelinek wrote:
On Sat, Apr 08, 2023 at 06:25:32PM -0600, Jeff Law wrote:
On 4/6/23 08:21, Eric Botcazou wrote:
So, perhaps just in the return op0; case add further code for
WORD_REGISTER_OPERATIONS and sub-word modes which will call nonzero_bits
again for the word mode and decide if it is still safe.
Does it work to just replace mode by word_mode in the calls to nonzero_bits?
It helps marginally -- basically we defer mucking up the code a bit. We
then hit this in simplify_and_const_int_1:
/* See what bits may be nonzero in VAROP. Unlike the general case of
a call to nonzero_bits, here we don't care about bits outside
MODE. */
nonzero = nonzero_bits (varop, mode) & GET_MODE_MASK (mode);
That just seems wrong for WORD_REGISTER_OPERATIONS targets.
Hacking both locations in a similar manner fixes the test.
If so, can you post that in patch form and can we go with that version
plus the testcase (e.g. from the first patch I've posted where I've changed
dse)?
So as I mentioned in IRC, I haven't really looked closely at
simplify_and_const_int_1. I don't have a high degree of confidence this
patch is complete, even though it does fix the test for 108947 and 109040.
I did bootstrap on riscv, but not a regression test, that's spinning
right now.
Jeff
diff --git a/gcc/combine.cc b/gcc/combine.cc
index 22bf8e1ec89..c41d8a09b3b 100644
--- a/gcc/combine.cc
+++ b/gcc/combine.cc
@@ -10055,9 +10055,10 @@ simplify_and_const_int_1 (scalar_int_mode mode, rtx
varop,
/* See what bits may be nonzero in VAROP. Unlike the general case of
a call to nonzero_bits, here we don't care about bits outside
- MODE. */
+ MODE unless WORD_REGISTER_OPERATIONS is true. */
- nonzero = nonzero_bits (varop, mode) & GET_MODE_MASK (mode);
+ enum machine_mode tmode = WORD_REGISTER_OPERATIONS ? word_mode : mode;
+ nonzero = nonzero_bits (varop, tmode) & GET_MODE_MASK (tmode);
/* Turn off all bits in the constant that are known to already be zero.
Thus, if the AND isn't needed at all, we will have CONSTOP == NONZERO_BITS
diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
index 3b33afa2461..5f6f70491d8 100644
--- a/gcc/simplify-rtx.cc
+++ b/gcc/simplify-rtx.cc
@@ -3752,7 +3752,10 @@ simplify_context::simplify_binary_operation_1 (rtx_code
code,
return op0;
if (HWI_COMPUTABLE_MODE_P (mode))
{
- HOST_WIDE_INT nzop0 = nonzero_bits (trueop0, mode);
+ /* When WORD_REGISTER_OPERATIONS is true, we need to know the
+ nonzero bits in WORD_MODE rather than MODE. */
+ HOST_WIDE_INT nzop0
+ = nonzero_bits (trueop0, WORD_REGISTER_OPERATIONS ? word_mode :
mode);
HOST_WIDE_INT nzop1;
if (CONST_INT_P (trueop1))
{