https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109907

--- Comment #20 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
Here is a testcase similar to the one from PR55181, where the first test is for
the sign bit:

unsigned char lfsr32_mpp_sign (unsigned long number)
{
  unsigned char b = 0;
  if (number & (1UL << 31)) b--;
  if (number & (1UL << 29)) b++;
  if (number & (1UL << 13)) b++;
  return b;
}

unsigned char lfsr32_ppp_sign (unsigned long number)
{
  unsigned char b = 0;
  if (number & (1UL << 31)) b++;
  if (number & (1UL << 29)) b++;
  if (number & (1UL << 13)) b++;
  return b;
}

What then happens is:

expr.cc::do_store_flag()
expmed.cc::emit_store_flag_force()
expmed.cc::emit_store_flag()
expmed.cc::emit_store_flag_1()

the latter then does:

      if (STORE_FLAG_VALUE == 1 || normalizep)
        /* If we are supposed to produce a 0/1 value, we want to do
           a logical shift from the sign bit to the low-order bit; for
           a -1/0 value, we do an arithmetic shift.  */
        op0 = expand_shift (RSHIFT_EXPR, int_mode, op0,
                            GET_MODE_BITSIZE (int_mode) - 1,
                            subtarget, normalizep != -1);

"normalizep" is true because ops->type has a precision of 1, and
STORE_FLAG_VALUE is the default of 1.

Nowhere is there any cost computation or consideration whether extzv could do
the trick.

Reply via email to