[llvm] [MachineLoopInfo] Fix getLoopID to handle multi latches. (PR #106195)
Marc Auberer via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 27 04:29:31 PDT 2024
================
@@ -211,8 +211,6 @@ MDNode *MachineLoop::getLoopID() const {
break;
}
}
----------------
marcauberer wrote:
I think this won't work for a case like this:
```
bb1: ; head
br %bb3
bb2: ; latch
br %bb1 !loop !1
bb3:
br %bb2
```
As far as I understand, the BasicBlocks are visited in no particular order that ensures, that latch blocks are visited last.
This means that if we visit `bb2`, we set `LoopID` to a non-null value. After that, we visit `bb3`, which has no metadata attached / is no latch => MD is nullptr. Thus the check in line 218 succeeds and we return from the function, which is not what we want.
I think this should work better:
```suggestion
}
if (!MD)
continue;
```
Maybe you can also add a test case for this scenario?
https://github.com/llvm/llvm-project/pull/106195
More information about the llvm-commits
mailing list