What Is a 'Dead Loop'?
Apparently it's a very important concept in compiler or driver design or implementation. I never heard it before. It's written in bright red as a warning on page 5 of https://llvm.org/devmtg/2020-09/slides/CIL_Common_MLIR_Abstraction.pdf and it was the key concept behind the patch that George Hotz didn't understand and thought was bad in https://youtu.be/Mr0rWJhv9jU?t=320 I tried to google it but I suck at googling because it kept wanting to tell me about the forbidden gymnastics trick instead https://en.wikipedia.org/wiki/Korbut_flip
9 comments
[ 4.8 ms ] story [ 32.0 ms ] threadI think that’s because C and C++ compilers often are allowed to assume that a loop will terminate (reading https://isocpp.org/files/papers/P2809R0.html, they do not fully agree on when they are allowed to do that)
https://en.cppreference.com/w/cpp/language/range-for
My interpretation is that the compiler isn't able to recognize that iterating over a "std::map" doesn't have side-effects, so it can't recognize that the loop is "dead code" that does nothing.
For instance, optimizing compilers will remove this loop entirely:
In the case of the patch, I believe the author of the text accidentally combined two similar English idioms "deadlock" and "infinite loop".https://en.wikipedia.org/wiki/Dead-code_elimination