https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110628
--- Comment #6 from Jan Hubicka <hubicka at ucw dot cz> --- The mismatch happens on: void foo (unsigned int x) { if (x != 0x800 && x != 0x810) abort (); } It is bug in reassoc turning: void foo (unsigned int x) { ;; basic block 2, loop depth 0, count 1073741824 (estimated locally, freq 1.0000), maybe hot ;; prev block 0, next block 3, flags: (NEW, REACHABLE, VISITED) ;; pred: ENTRY [always] count:1073741824 (estimated locally, freq 1.0000) (FALLTHRU,EXECUTABLE) if (x_1(D) != 2048) goto <bb 3>; [66.00%] else goto <bb 5>; [34.00%] ;; succ: 3 [66.0% (guessed)] count:708669600 (estimated locally, freq 0.6600) (TRUE_VALUE,EXECUTABLE) ;; 5 [34.0% (guessed)] count:365072224 (estimated locally, freq 0.3400) (FALSE_VALUE,EXECUTABLE) ;; basic block 3, loop depth 0, count 708669600 (estimated locally, freq 0.6600), maybe hot ;; prev block 2, next block 4, flags: (NEW, REACHABLE, VISITED) ;; pred: 2 [66.0% (guessed)] count:708669600 (estimated locally, freq 0.6600) (TRUE_VALUE,EXECUTABLE) if (x_1(D) != 2064) goto <bb 4>; [0.00%] else goto <bb 5>; [100.00%] ;; succ: 4 [never] count:0 (precise, freq 0.0000) (TRUE_VALUE,EXECUTABLE) ;; 5 [always] count:708669600 (estimated locally, freq 0.6600) (FALSE_VALUE,EXECUTABLE) ;; basic block 4, loop depth 0, count 0 (precise, freq 0.0000), probably never executed ;; prev block 3, next block 5, flags: (NEW, REACHABLE, VISITED) ;; pred: 3 [never] count:0 (precise, freq 0.0000) (TRUE_VALUE,EXECUTABLE) abort (); ;; succ: to: void foo (unsigned int x) { unsigned int _4; _Bool _5; ;; basic block 2, loop depth 0, count 1073741824 (estimated locally, freq 1.0000), maybe hot ;; prev block 0, next block 3, flags: (NEW, REACHABLE, VISITED) ;; pred: ENTRY [always] count:1073741824 (estimated locally, freq 1.0000) (FALLTHRU,EXECUTABLE) _4 = x_1(D) & 4294967279; _5 = _4 != 2048; if (_5 != 0) goto <bb 3>; [66.00%] else goto <bb 4>; [34.00%] ;; succ: 3 [66.0% (guessed)] count:708669600 (estimated locally, freq 0.6600) (TRUE_VALUE,EXECUTABLE) ;; 4 [34.0% (guessed)] count:365072224 (estimated locally, freq 0.3400) (FALSE_VALUE,EXECUTABLE) ;; basic block 3, loop depth 0, count 0 (precise, freq 0.0000), probably never executed ;; Invalid sum of incoming counts 708669600 (estimated locally, freq 0.6600), should be 0 (precise, freq 0.0000) ;; prev block 2, next block 4, flags: (NEW, REACHABLE, VISITED) ;; pred: 2 [66.0% (guessed)] count:708669600 (estimated locally, freq 0.6600) (TRUE_VALUE,EXECUTABLE) abort (); ;; succ: ;; basic block 4, loop depth 0, count 1073741824 (estimated locally, freq 1.0000), maybe hot ;; Invalid sum of incoming counts 365072224 (estimated locally, freq 0.3400), should be 1073741824 (estimated locally, freq 1.0000) ;; prev block 3, next block 1, flags: (NEW, REACHABLE, VISITED) ;; pred: 2 [34.0% (guessed)] count:365072224 (estimated locally, freq 0.3400) (FALSE_VALUE,EXECUTABLE) return; So it combines two conditionals together but does not update the outgoing probabilitis of the conditional. On x86-64 we have already in cfg dump: _1 = x != 2048; _2 = x != 2064; _3 = _1 & _2; if (_3 != 0) goto <bb 3>; [INV] else I wonder why optimization diverges here?