https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106126
--- Comment #11 from luoxhu at gcc dot gnu.org --- Sorry for breaking, my bugzilla account is luo...@gcc.gnu.org. The patch seems reasonable to fold 65-90 ('A'-'Z') to switch statement, 4,6c4,6 < ;; Canonical GIMPLE case clusters: 33 60 62 126 < ;; BT can be built: BT(values:3 comparisons:6 range:30 density: 20.00%):33-62 126 < pr106126.c:3:28: optimized: Condition chain with 4 BBs transformed into a switch statement. --- > ;; Canonical GIMPLE case clusters: 33 60 62 65-90 126 > ;; BT can be built: BT(values:3 comparisons:6 range:30 density: 20.00%):33-62 > 65-90 126 > pr106126.c:3:28: optimized: Condition chain with 5 BBs transformed into a > switch statement. ... 96,97c108,109 < <bb 8> : < switch (_13) <default: <L11> [INV], case 33: <L10> [INV], case 60: <L10> [INV], case 62: <L10> [INV], case 126: <L10> [INV]> --- > <bb 7> : > switch (_13) <default: <L13> [INV], case 33: <L10> [INV], case 60: <L10> > [INV], case 62: <L10> [INV], case 65 ... 90: <L14> [INV], case 126: <L10> > [INV]> complete pr106126.bad.c.046t.iftoswitch: ;; Function pool_conda_matchspec (pool_conda_matchspec, funcdef_no=0, decl_uid=1979, cgraph_uid=1, symbol_order=1) ;; Canonical GIMPLE case clusters: 33 60 62 65-90 126 ;; BT can be built: BT(values:3 comparisons:6 range:30 density: 20.00%):33-62 65-90 126 pr106126.c:3:28: optimized: Condition chain with 5 BBs transformed into a switch statement. Removing basic block 9 ;; basic block 9, loop depth 2 ;; pred: if (_13 != 62) goto <bb 10>; [INV] else goto <bb 12>; [INV] ;; succ: 10 ;; 12 Removing basic block 10 ;; basic block 10, loop depth 2 ;; pred: if (_13 != 33) goto <bb 11>; [INV] else goto <bb 12>; [INV] ;; succ: 11 ;; 12 Removing basic block 11 ;; basic block 11, loop depth 2 ;; pred: if (_13 != 126) goto <bb 3>; [INV] else goto <bb 12>; [INV] ;; succ: 3 ;; 12 Removing basic block 3 ;; basic block 3, loop depth 2 ;; pred: _3 = (unsigned char) _13; _4 = _3 + 191; if (_4 <= 25) goto <bb 14>; [INV] else goto <bb 13>; [INV] ;; succ: 14 ;; 13 Expanded into a new gimple STMT: switch (_13) <default: <L12> [INV], case 33: <L10> [INV], case 60: <L10> [INV], case 62: <L10> [INV], case 65 ... 90: <L11> [INV], case 126: <L10> [INV]> Removing basic block 13 ;; basic block 13, loop depth 2 ;; pred: <L12>: goto <bb 6>; [100.00%] ;; succ: 6 Removing basic block 14 ;; basic block 14, loop depth 1 ;; pred: <L11>: ;; succ: 4 fix_loop_structure: fixing up loops for function void pool_conda_matchspec () { unsigned char _8; char _10; char * var_1.3_11; char _13; unsigned char _14; char * var_1.3_15; <bb 2> : goto <bb 4>; [INV] <bb 3> : # _14 = PHI <_3(7)> # var_1.3_15 = PHI <var_1.3_11(7)> <L14>: _8 = _14 + 65; _10 = (char) _8; *var_1.3_15 = _10; <bb 4> : <bb 5> : <L13>: var_1.3_11 = var_1; if (var_1.3_11 != 0B) goto <bb 6>; [INV] else goto <bb 8>; [INV] <bb 6> : _13 = *var_1.3_11; if (_13 != 0) goto <bb 7>; [INV] else goto <bb 8>; [INV] <bb 7> : switch (_13) <default: <L13> [INV], case 33: <L10> [INV], case 60: <L10> [INV], case 62: <L10> [INV], case 65 ... 90: <L14> [INV], case 126: <L10> [INV]> <bb 8> : <L10>: return; _8 = _14 + 65; _10 = (char) _8; *var_1.3_15 = _10; <bb 4> : <bb 5> : <L13>: var_1.3_11 = var_1; if (var_1.3_11 != 0B) goto <bb 6>; [INV] else goto <bb 8>; [INV] <bb 6> : _13 = *var_1.3_11; if (_13 != 0) goto <bb 7>; [INV] else goto <bb 8>; [INV] <bb 7> : switch (_13) <default: <L13> [INV], case 33: <L10> [INV], case 60: <L10> [INV], case 62: <L10> [INV], case 65 ... 90: <L14> [INV], case 126: <L10> [INV]> <bb 8> : <L10>: return; } The problem is _3 is removed in basic block 3, but _14 is still using it.