[llvm] Branch folding: Avoid infinite loop with indirect target blocks (PR #96956)

Andy Kaylor via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 14 17:40:01 PDT 2024


andykaylor wrote:

@v01dXYZ It's been a very long time since I wrote that comment, but I think what I meant was that the check for EHPad is definitely necessary, and even if, at some time in the future, it looked as if the infinite loop wasn't happening if the check was removed, the check still shouldn't be removed. My description in the original code review (https://reviews.llvm.org/D27582) says that the fix had been reverted because it caused compile time issues and the original case wasn't failing anymore. Then I found another case where the infinite loop occurred, so when I recommitted the fix I added a note warning against reverting the fix again. I guess I never completely understood the conditions that triggered the infinite loop, but I was certain that the potential will always be there.

So, maybe it's worth rewording the comment, but I think it would be good to keep it in some form. How about this:

"Changes to the branch folding algorithm may allow the regression tests to pass without these checks, but the checks should still not be removed because the possibility for an infinite loop remains as long as there can be multiple blocks that meet the criteria for being moved to the end."

Maybe we should consider some more general solution where we keep track of which blocks we've moved to the end and skip those in subsequent loop iterations. I haven't looked at this code in a very long time, so I don't know how hard that would be to implement.

https://github.com/llvm/llvm-project/pull/96956


More information about the llvm-commits mailing list