public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "gjl at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/109907] Missed optimization for bit extraction (uses shift instead of single bit-test)
Date: Fri, 26 May 2023 16:08:42 +0000	[thread overview]
Message-ID: <bug-109907-4-m2wM8n1qAc@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-109907-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #23 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
Thank you so much for looking into this.

For the test case from comment #21 though, the problem is somewhere in tree
optimizations.

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

The -fdump-tree-optimized dump reads:

;; Function lfsr32_mpp_ge0 (lfsr32_mpp_ge0, funcdef_no=0, decl_uid=1880,
cgraph_uid=1, symbol_order=0)

unsigned char lfsr32_mpp_ge0 (long unsigned int number)
{
  unsigned char b;
  long unsigned int _1;
  long unsigned int _2;
  _Bool _3;
  unsigned char _8;
  _Bool _9;
  unsigned char _10;
  unsigned char _11;

  <bb 2> [local count: 1073741824]:
  _1 = number_5(D) & 536870912;
  _2 = number_5(D) & 8192;
  if (_2 != 0)
    goto <bb 4>; [50.00%]
  else
    goto <bb 3>; [50.00%]

  <bb 3> [local count: 536870912]:
  _9 = _1 == 0;
  _10 = (unsigned char) _9;
  _11 = -_10;
  goto <bb 5>; [100.00%]

  <bb 4> [local count: 536870913]:
  _3 = _1 != 0;
  _8 = (unsigned char) _3;

  <bb 5> [local count: 1073741824]:
  # b_4 = PHI <_11(3), _8(4)>
  return b_4;
}

The ANDs are expanded by expand_binop() and later passes have to deal with the
32-bit arithmnetic.  combine finds one combination of andsi3 into
"*sbrx_and_branch<mode>_split" with mode=si, but apart from that the mess still
lives in asm.

  parent reply	other threads:[~2023-05-26 16:08 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-19 10:10 [Bug middle-end/109907] New: [avr] " gjl at gcc dot gnu.org
2023-05-19 14:14 ` [Bug middle-end/109907] " pinskia at gcc dot gnu.org
2023-05-19 15:42 ` [Bug middle-end/109907] " pinskia at gcc dot gnu.org
2023-05-19 15:45 ` pinskia at gcc dot gnu.org
2023-05-19 20:03 ` pinskia at gcc dot gnu.org
2023-05-19 20:12 ` pinskia at gcc dot gnu.org
2023-05-19 20:41 ` gjl at gcc dot gnu.org
2023-05-19 20:55 ` pinskia at gcc dot gnu.org
2023-05-19 20:59 ` gjl at gcc dot gnu.org
2023-05-20  0:46 ` pinskia at gcc dot gnu.org
2023-05-20  5:09 ` pinskia at gcc dot gnu.org
2023-05-20  7:36 ` gjl at gcc dot gnu.org
2023-05-20  7:50 ` gjl at gcc dot gnu.org
2023-05-20 22:23 ` pinskia at gcc dot gnu.org
2023-05-20 22:40 ` pinskia at gcc dot gnu.org
2023-05-21  5:15 ` pinskia at gcc dot gnu.org
2023-05-21  5:36 ` pinskia at gcc dot gnu.org
2023-05-21  9:09 ` gjl at gcc dot gnu.org
2023-05-21  9:55 ` gjl at gcc dot gnu.org
2023-05-23  9:58 ` gjl at gcc dot gnu.org
2023-05-26  8:49 ` gjl at gcc dot gnu.org
2023-05-26 11:14 ` gjl at gcc dot gnu.org
2023-05-26 15:21 ` pinskia at gcc dot gnu.org
2023-05-26 16:08 ` gjl at gcc dot gnu.org [this message]
2023-05-26 23:11 ` pinskia at gcc dot gnu.org
2023-05-26 23:34 ` pinskia at gcc dot gnu.org
2023-05-26 23:49 ` pinskia at gcc dot gnu.org
2023-05-27  0:36 ` pinskia at gcc dot gnu.org
2023-05-27  4:02 ` pinskia at gcc dot gnu.org
2023-05-27 20:09 ` pinskia at gcc dot gnu.org
2023-06-11  9:22 ` cvs-commit at gcc dot gnu.org
2023-06-11  9:26 ` gjl at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-109907-4-m2wM8n1qAc@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).