From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D20DA3852200; Thu, 17 Nov 2022 20:46:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D20DA3852200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668717978; bh=ARR5+8D1gUUt9RuvupI8PsidGRi7zit1YTfwAqwsQC0=; h=From:To:Subject:Date:From; b=fkDoIaebQDEeH+1sA0GGrEnhatMlGQqso9Luwt/9PbCNHd5s6vzY+dZ3FhGQAhvcI Db/uDLKfcBs52VdakXbf1ULVmVvo9PA1gg69Rfe4/2730kbCmHmJXOmChSDINRnwjU 7K6lCdyzZHlHLZE0uBIArgDzeK63NFweIZQQuT40= From: "ppalka at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ppalka at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107740 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 compili= ng with g++ vs gcc: $ cat is_whitespace.c int is_whitespace (char c) { return (c =3D=3D ' ' || c =3D=3D '\n' || c =3D=3D '\r' || c =3D=3D '\t'); } $ gcc -fdump-tree-{original,iftoswitch}=3D/dev/stdout -O2 is_whitespace.C ;; Function is_whitespace (null) ;; enabled by -tree-original { return (c =3D=3D 32 || c =3D=3D 10) || (c =3D=3D 13 || c =3D=3D 9); } ;; Function is_whitespace (is_whitespace, funcdef_no=3D0, decl_uid=3D2735, cgraph_uid=3D1, symbol_order=3D0) ;; Canonical GIMPLE case clusters: 9-10 13 32=20 ;; BT can be built: BT:9-32=20 Removing basic block 3 Expanded into a new gimple STMT: switch (c_8(D)) [INV], case= 9: [INV], case 10: [INV], case 13: [INV], case 32: [INV]> int is_whitespace (char c) { _Bool _1; _Bool _2; _Bool _3; int iftmp.0_7; : _1 =3D c_8(D) =3D=3D 32; _2 =3D c_8(D) =3D=3D 10; _3 =3D _1 | _2; switch (c_8(D)) [INV], case 9: [INV], case 10: [INV], case 13: [INV], case 32: [INV]> : : : # iftmp.0_7 =3D PHI <1(3), 0(2)> : return iftmp.0_7; } $ g++ -fdump-tree-{original,iftoswitch}=3D/dev/stdout -O2 is_whitespace.C ;; Function int is_whitespace(char) (null) ;; enabled by -tree-original return =3D (int) ((c =3D=3D 32 || c =3D=3D 10) || (c =3D=3D 13 || = c =3D=3D 9)); ;; Function is_whitespace (_Z13is_whitespacec, funcdef_no=3D0, decl_uid=3D2= 757, cgraph_uid=3D1, symbol_order=3D0) int is_whitespace (char c) { bool _1; bool _2; bool _3; bool _4; bool _5; bool _6; bool iftmp.0_7; int _11; : _1 =3D c_8(D) =3D=3D 32; _2 =3D c_8(D) =3D=3D 10; _3 =3D _1 | _2; if (_3 !=3D 0) goto ; [INV] else goto ; [INV] : _4 =3D c_8(D) =3D=3D 13; _5 =3D c_8(D) =3D=3D 9; _6 =3D _4 | _5; : # iftmp.0_7 =3D PHI <1(2), _6(3)> _11 =3D (int) iftmp.0_7; return _11; }=