https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101150
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Target Milestone|--- |11.2 Status|UNCONFIRMED |NEW Keywords| |missed-optimization Component|c++ |tree-optimization Last reconfirmed| |2021-06-22 --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- There seems to be some missing optimizations (jump threading) here. First one: long int _12; _12 = _9 - _15; if (_12 != 0) goto <bb 4>; [33.00%] else goto <bb 3>; [67.00%] // this should just jump to bb 15 because _12 == 0 and there for _9 == _15 <bb 3> [local count: 79134772]: if (_9 != _15) /// This should always be false coming from bb 2 because _12 == 0 there for _9 == _15 goto <bb 11>; [89.00%] else goto <bb 15>; [11.00%] ... <bb 11> [local count: 104641928]: # _143 = PHI <_18(8), _9(3)> # _118 = PHI <_19(8), _15(3)> # v$_M_start_84 = PHI <_104(8), 0B(3)> # prephitmp_123 = PHI <_12(8), _12(3)> _133 = (unsigned long) _143; _110 = (unsigned long) _118; _125 = _133 - _110; .... <bb 15> [local count: 117575200]: return; Second one: ... <bb 4> [local count: 19488414]: _64 = (long unsigned int) _12; if (_64 > 9223372036854775804) goto <bb 5>; [0.04%] else goto <bb 6>; [99.96%] .... <bb 6> [local count: 9740309]: if (_12 != 0) // This should always be true as _12 should always != 0 on coming into this bb because we can only come via the if statement in bb 4 on the true edge of the conditional. goto <bb 7>; [100.00%] else goto <bb 16>; [0.00%] /// NOTE BB 16 is where the null pointer write it located --------- CUT ------- The reason why if you have both foo and bar defined, there is a heuristics of the inlining of vector::_M_default_append which causes the difference, nothing shocking really.