public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ppalka at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/107740] New: if-to-switch conversion happens for simple predicate function when compiled with gcc but not with g++
Date: Thu, 17 Nov 2022 20:46:18 +0000	[thread overview]
Message-ID: <bug-107740-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 107740
           Summary: if-to-switch conversion happens for simple predicate
                    function when compiled with gcc but not with g++
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ppalka at gcc dot gnu.org
  Target Milestone: ---

For the following testcase, the ||'s are converted into a switch statement when
compiling with gcc but not with g++ (despite only minor differences in their
GENERIC trees) and ultimately leads to seemingly worse codegen when compiling
with g++ vs gcc:

$ cat is_whitespace.c
int
is_whitespace (char c)
{
  return (c == ' '
          || c == '\n'
          || c == '\r'
          || c == '\t');
}


$ gcc -fdump-tree-{original,iftoswitch}=/dev/stdout -O2 is_whitespace.C

;; Function is_whitespace (null)
;; enabled by -tree-original


{
  return (c == 32 || c == 10) || (c == 13 || c == 9);
}


;; Function is_whitespace (is_whitespace, funcdef_no=0, decl_uid=2735,
cgraph_uid=1, symbol_order=0)

;; Canonical GIMPLE case clusters: 9-10 13 32 
;; BT can be built: BT:9-32 
Removing basic block 3
Expanded into a new gimple STMT: switch (c_8(D)) <default: <L6> [INV], case 9:
<L5> [INV], case 10: <L5> [INV], case 13: <L5> [INV], case 32: <L5> [INV]>

int is_whitespace (char c)
{
  _Bool _1;
  _Bool _2;
  _Bool _3;
  int iftmp.0_7;

  <bb 2> :
  _1 = c_8(D) == 32;
  _2 = c_8(D) == 10;
  _3 = _1 | _2;
  switch (c_8(D)) <default: <L6> [INV], case 9: <L5> [INV], case 10: <L5>
[INV], case 13: <L5> [INV], case 32: <L5> [INV]>

  <bb 3> :
<L5>:

  <bb 4> :
  # iftmp.0_7 = PHI <1(3), 0(2)>
<L6>:
  return iftmp.0_7;

}


$ g++ -fdump-tree-{original,iftoswitch}=/dev/stdout -O2 is_whitespace.C

;; Function int is_whitespace(char) (null)
;; enabled by -tree-original


return <retval> = (int) ((c == 32 || c == 10) || (c == 13 || c == 9));


;; Function is_whitespace (_Z13is_whitespacec, funcdef_no=0, decl_uid=2757,
cgraph_uid=1, symbol_order=0)

int is_whitespace (char c)
{
  bool _1;
  bool _2;
  bool _3;
  bool _4;
  bool _5;
  bool _6;
  bool iftmp.0_7;
  int _11;

  <bb 2> :
  _1 = c_8(D) == 32;
  _2 = c_8(D) == 10;
  _3 = _1 | _2;
  if (_3 != 0)
    goto <bb 4>; [INV]
  else
    goto <bb 3>; [INV]

  <bb 3> :
  _4 = c_8(D) == 13;
  _5 = c_8(D) == 9;
  _6 = _4 | _5;

  <bb 4> :
  # iftmp.0_7 = PHI <1(2), _6(3)>
  _11 = (int) iftmp.0_7;
  return _11;

}

             reply	other threads:[~2022-11-17 20:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-17 20:46 ppalka at gcc dot gnu.org [this message]
2022-11-17 20:48 ` [Bug tree-optimization/107740] " pinskia at gcc dot gnu.org
2022-11-17 20:59 ` [Bug tree-optimization/107740] [12/13 Regression] " pinskia at gcc dot gnu.org
2022-11-17 21:00 ` pinskia at gcc dot gnu.org
2023-01-13 12:44 ` rguenth at gcc dot gnu.org
2023-05-08 12:26 ` [Bug tree-optimization/107740] [12/13/14 " rguenth 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-107740-4@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).