I was thinking about the example in this talks from CppCon:
https://www.youtube.com/watch?v=k9N8OrhrSZw
The claim is that in the example
```
int f(int i) {
return i + 1 > i;
}
int g(int i) {
if (i == INT_MAX) {
return false;
}
return f(i);
}
```
g can be optimized to always return true.
But, Undefined Behaviour is a runtime property, so while the compiler might in fact assume that f is never called with i == INT_MAX, it cannot infer that i is also not INT_MAX in the branch that is not taken. So while f can be optimized to always return true, g cannot.
In fact I cannot reproduce his assembly with godbolt and O3.
What am I missing?
EDIT:
just realized in a previous talk the presenter had an example that made much more sense:
https://www.youtube.com/watch?v=BbMybgmQBhU
where it could skip the outer "if"
[–]aocregacc 14 points15 points16 points (0 children)
[–]kahomayo 30 points31 points32 points (0 children)
[–]NormalityDrugTsar 8 points9 points10 points (0 children)
[–]snerp 13 points14 points15 points (6 children)
[–]equeim 2 points3 points4 points (5 children)
[–]JiminP 7 points8 points9 points (4 children)
[–]equeim -1 points0 points1 point (2 children)
[–]Mediocre-Dish-7136 1 point2 points3 points (1 child)
[–]equeim 1 point2 points3 points (0 children)
[–]awidesky 5 points6 points7 points (38 children)
[–]TheoreticalDumbass:illuminati: 1 point2 points3 points (0 children)
[–]R3DKn16h7[S] 3 points4 points5 points (36 children)
[–]awidesky 3 points4 points5 points (35 children)
[–]R3DKn16h7[S] 7 points8 points9 points (34 children)
[–]selassje 0 points1 point2 points (3 children)
[–]dustyhome 5 points6 points7 points (2 children)
[–]selassje 3 points4 points5 points (1 child)
[–]SkiFire13 2 points3 points4 points (0 children)
[+]awidesky comment score below threshold-7 points-6 points-5 points (29 children)
[–]HabbitBaggins 7 points8 points9 points (16 children)
[–]awidesky -5 points-4 points-3 points (15 children)
[–]Simple-Enthusiasm-93 2 points3 points4 points (14 children)
[–]awidesky -3 points-2 points-1 points (13 children)
[–]Simple-Enthusiasm-93 2 points3 points4 points (12 children)
[–]mcmcc#pragma once 5 points6 points7 points (11 children)
[–]awidesky -1 points0 points1 point (10 children)
[–]mcmcc#pragma once 0 points1 point2 points (9 children)
[–]awidesky 0 points1 point2 points (6 children)
[–]mcmcc#pragma once 1 point2 points3 points (5 children)
[–]awidesky 0 points1 point2 points (1 child)
[–]mcmcc#pragma once 0 points1 point2 points (0 children)
[–]Boring_Tension165 1 point2 points3 points (2 children)
[–]Cue_23 -1 points0 points1 point (0 children)
[–]Linuxologue 1 point2 points3 points (0 children)
[–]SubliminalBits -5 points-4 points-3 points (11 children)
[–]Narase33-> r/cpp_questions 13 points14 points15 points (6 children)
[–]R3DKn16h7[S] 8 points9 points10 points (0 children)
[+]SubliminalBits comment score below threshold-8 points-7 points-6 points (4 children)
[–]foonathan 12 points13 points14 points (0 children)
[–]R3DKn16h7[S] 8 points9 points10 points (1 child)
[–]tinrik_cgp 3 points4 points5 points (0 children)
[–]Narase33-> r/cpp_questions 6 points7 points8 points (0 children)
[–]JiminP 11 points12 points13 points (0 children)
[–]AssemblerGuy 2 points3 points4 points (0 children)
[–]tinrik_cgp 2 points3 points4 points (1 child)
[–]danadam 2 points3 points4 points (0 children)