https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70724
Bug ID: 70724 Summary: [6 Regression] Miscompiles python3 with FDO Product: gcc Version: 6.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org Target Milestone: --- Testcase: extern void abort (void); typedef long int _PyTime_t; typedef enum { _PyTime_ROUND_FLOOR = 0, _PyTime_ROUND_CEILING = 1 } _PyTime_round_t; static _PyTime_t _PyTime_Divide(const _PyTime_t t, const _PyTime_t k, const _PyTime_round_t round) { if (round == _PyTime_ROUND_CEILING) { if (t >= 0) return (t + k - 1) / k; else return t / k; } else { if (t >= 0) return t / k; else return (t - (k - 1)) / k; } } _PyTime_t __attribute__((noinline,noclone)) _PyTime_AsMicroseconds(_PyTime_t t, _PyTime_round_t round) { return _PyTime_Divide(t, 1000, round); } int main() { if (_PyTime_AsMicroseconds (10000, _PyTime_ROUND_FLOOR) != 10) abort (); return 0; } is miscompiled at -O2 -fprofile-use (actually with -O2 -ftracer). The issue is tail-merging which merges <bb 5>: # RANGE [-9223372036854775, 0] _6 = t_2(D) / 1000; goto <bb 9>; and <bb 7>: # RANGE [0, 9223372036854775] NONZERO 18014398509481983 _7 = t_2(D) / 1000; goto <bb 9>; not resetting range info. VRP2 then miscompiles the division to always zero.