What Is a 'Dead Loop'?

1 points by ftxbro ↗ HN
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 ] thread
It's a loop that has no effects, so a sufficiently smart compiler would be able to remove it completely.
It's not a real term.
I 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.
Either 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.
Thank 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.
> 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, they do not fully agree on when they are allowed to do that)

The example from the slide is a 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".
(comment deleted)