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; }