public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/107740] New: if-to-switch conversion happens for simple predicate function when compiled with gcc but not with g++
@ 2022-11-17 20:46 ppalka at gcc dot gnu.org
  2022-11-17 20:48 ` [Bug tree-optimization/107740] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-11-17 20:46 UTC (permalink / raw)
  To: gcc-bugs

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;

}

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-05-08 12:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-17 20:46 [Bug tree-optimization/107740] New: if-to-switch conversion happens for simple predicate function when compiled with gcc but not with g++ ppalka at gcc dot gnu.org
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

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).