Mirror the `getLoopID()` implementation of `LoopInfo` in `MachineLoopInfo`. `getLoopID` used `findLoopControlBlock` to detect the special case where there is a single latch. However, `findLoopControlBlock` returns the exiting block if the latch is not an exiting block. The middle end places the `LoopID` metadata on the latch regardless of if it's an exiting block or not. I raised this issue in the PR that introduced the `getLoopID()` helper (https://github.com/llvm/llvm-project/pull/71026#discussion_r2000595214) and @FreddyLeaf confirmed this is a bug and asked me to help implement a refinement. I've mirrored the implementation of `LoopInfo` instead of simply changing `findLoopControlBlock()` to `findLoopControlBlock()` to keep the two implementations consistent. The only difference between the two is that `MachineLoopInfo::getLoopID` initially starts out with a `MachineBacisBlock` and attempts to retrieve the `BasicBlock` (if it wasn't for this difference, I would have moved it to `genericLoopInfo`). I've also updated the test associated with https://github.com/llvm/llvm-project/pull/71026 (`test5`) that check the alignment for a loop with a single latch that's not the exit. This test will fail for the current implementation. I'm not sure if we want to include this test upstream (it might look out of place after we remove the 'single-latch-specialization' from `getLoopID()`). Let me know if you have any comments, @FreddyLeaf !
9.5 KiB
9.5 KiB