[llvm] [RemoveDIs] Fix spliceDebugInfo splice-to-end edge case (PR #105671)
Orlando Cazalet-Hyams via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 22 08:33:32 PDT 2024
OCHyams wrote:
> Thanks for looking into this @OCHyams
>
> Could you please clarify couple of things here.
>
> 1. In the splice function of test
> `NewBB->splice(NewBB->end(), &BB, B, BB.end());`
> The B here refers to first instruction
> `%b = add i16 %a, 0`
> Is that what we are testing? Shouldn't we split at the return instruction ?
A few lines before the splice we delete the return instruction. That forces the debug records attached to it (which come "before" the instruction) to become "trailing" - meaning they come before `end()` (we can't attached the records to `end()` though, so they're associated with the basic block instead). The splice from `B` to `end()` includes exactly `B` and the one trailing debug marker.
> 2. Consider a scenario in a pass we want to split from return instruction. And the debug record just above belongs to that return instruction. When we try to splice here, can we expect the DebugInfo to tag along with the return instruction
> (or)
> Is it responsibility of pass owners using splice to set HeadBit of the instruction(in case if it has DebugRecords). So that the debug record will be tagged along with return instruction.
Hmm good question. If you're splitting before the ret then I believe the debug records attached to (positioned before) the ret will be separated from it into the new split block, unless HeadBit is set on ret's iterator before the split (as that would then indicate the split point comes "before" the debug intrinsics). HeadBit will be set automatically you've obtained the iterator to ret by calling `BasicBlock::begin()` or `BasicBlock::getFirstNonPHIIt()` (e.g., you call `begin` and the ret is the only instruction), otherwise I believe you're right that you'd need to set it yourself if you're sure you want those records to move.
In most cases that heuristic (set HeadBit from those functions) has worked out, but there are a couple of places in LLVM that explicitly set HeadBit - I can see one such example is actually a block split in [CodeGenPrepare](https://github.com/llvm/llvm-project/blob/fe5d1f901a709bc6a2180b7a77b9d5948c6c3482/llvm/lib/CodeGen/CodeGenPrepare.cpp#L7337).
https://github.com/llvm/llvm-project/pull/105671
More information about the llvm-commits
mailing list