5 ms·
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
- tlb 3y agoIt's a loop that has no effects, so a sufficiently smart compiler would be able to remove it completely.
- wmf 3y agoIt's not a real term.
- ftxbro 3y agoI wonder is it a regional or dialect or cultural thing? The ones listed in the compiler paper and on the AMD driver had names that were not anglo american names. I'm not saying it's bad I'm just wondering maybe it's why I didn't hear 'dead loop' before, because I'm too blinkered not cosmopolitan enough in my understanding of tech jargon.
- detaro 3y agoEither a loop that doesn't do anything (thats the compiler example) or sometimes (IMHO wrongly, but I've seen it a few times) also used as a name for an endless loop.
- ftxbro 3y agoThank you this is very confusing but I suspect this is probably the best answer. Like maybe the compiler example was the first one and the driver example was the second one.
- Someone 3y ago> or sometimes (IMHO wrongly, but I've seen it a few times) also used as a name for an endless loop. I 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 https://isocpp.org/files/papers/P2809R0.html, they do not fully agree on when they are allowed to do that)
- al2o3cr 3y agoThe example from the slide is a range-for: https://en.cppreference.com/w/cpp/language/range-for 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: int fun_with_dead_loop() { for(int i=0; i < 10; i++) { } return 0; } In the case of the patch, I believe the author of the text accidentally combined two similar English idioms "deadlock" and "infinite loop".
- deleted 3y ago[deleted]
- richardjam73 3y agoFor the LLVM document they are talking about dead code. https://en.wikipedia.org/wiki/Dead-code_elimination https://en.wikipedia.org/wiki/Dead-code_elimination