llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

.loc is incorrect for compiler generated spill code in ppc32/64 .

Open ukalappa-mips opened this issue 4 years ago • 8 comments

Hi , The testcase like https://godbolt.org/z/McGWf7YE8 .

.loc should be associated like .loc 0 0 for the compiler generated insn like

 .loc    1 25 4                          # example.c:25:4
        bl callee
        lwz 3, 8(31)                            # 4-byte Folded Reload

It should be like

 .loc    1 25 4                          # example.c:25:4
   bl callee
.loc 1 0 0 
   lwz 3, 8(31)                            # 4-byte Folded Reload

instead of previous stmt .

problem pops up when we nexti from the gdb or any dwarf consumer.

ukalappa-mips avatar Jul 04 '22 07:07 ukalappa-mips

@llvm/issue-subscribers-backend-powerpc

llvmbot avatar Jul 04 '22 13:07 llvmbot

This is curious, because https://reviews.llvm.org/D127488 is attempting to eliminate line-0 locations, on the grounds that they take up space and aren't useful for debugging.

problem pops up when we nexti from the gdb or any dwarf consumer.

What problem is it that you see?

pogo59 avatar Jul 05 '22 20:07 pogo59

What problem is it that you see?

Yeah, same question here. I guess nexti should not rely on debug line section, it just executes the instructions one by one. So inserting a .loc 1 0 0 between the call and the lwz(inserted internally by compiler) will not impact the nexti. And it will also not impact the next as I tested on PPC linux with GDB.

chenzheng1030 avatar Jul 06 '22 03:07 chenzheng1030

What problem is it that you see? the issue we have like

step to callee ,then return from callee like finish ,we expect gdb to go .loc 27 not to stay in .loc 25 .

inserting a .loc 1 0 0 between the call and the lwz(inserted internally by compiler) will not impact the nexti interesting.

that something worked for us ,anyway what could be ideal solution would associate the reload insn to next .loc i.e .loc 27 here not the previous .loc ?

ukalappa-mips avatar Jul 06 '22 04:07 ukalappa-mips

Is there precedent for this in other compilers (GCC)? I'd generally err away from this and suggest that this sort of behavior (unlocated instructions "attaching" to the previous located instruction) is to be expected from most producers. I guess associating them with the next line instead could improve user experience, though might also produce confusion too (eg: get to the call line, nexti and nothing happens/the call doesn't execute because some extra instructions are there (though it wouldn't be super surprising, since many/most calls need some setup instructions to put arguments in the registers, etc)) - and also that'd risk breaking things if you back propagated the location over a basic block boundary, which would mean potentially making a more inconsistent user experience (or a larger line table by using line zero in that special case).

dwblaikie avatar Jul 06 '22 17:07 dwblaikie

that'd risk breaking things if you back propagated the location over a basic block boundary,

We already go to some trouble to avoid doing that (back up over a block boundary), due to user complaints. There's a high chance the previous block is completely unrelated and will only cause more confusion.

Spills and reloads are, in one view, completely artificial and there's an argument that they should therefore get line 0. On the other hand, spills and reloads are there primarily because the calling convention says certain registers are caller-preserved, and arguably the spill/reload exists only because there's a call, suggesting that they really should be attached to the same source location as the call.

pogo59 avatar Jul 06 '22 19:07 pogo59

Yes, I also think back propagated the location may cause other issue. For example, if the loop's last instruction is a artificial instruction (since the location can be back propagated over a block boundary), but it has debug line info from the instruction outside of the loop. While debugging the loop, we may have the feel that we are already out of the loop when executing the last artificial instruction, but we are clearly not.

And another reason for not associating the unlocated instruction with its following instruction's location is the unlocated instruction may bind to the previous instruction. For example, for the case in https://godbolt.org/z/McGWf7YE8, if we compile with fast instruction selection, the call will have a nop following the call, like:

    .loc    0 23 4 is_stmt 1                # 1.c:23:4
    bl callee
    nop
    .loc    0 25 4                          # 1.c:25:4
    bl callee
    nop
    .loc    0 27 8                          # 1.c:27:8
    lwz 3, 112(31)

The unlocated nop following the bl belongs to the call, it does not make sense to change its location to the following instruction's location.

chenzheng1030 avatar Jul 07 '22 01:07 chenzheng1030

@pogo59 and @chenzheng1030 ,agree that spills and reloads are part of call and location of those insn should be associated with call .loc .

Now ,says we step over the call and step over lands you to these insn because your return address update same ,and i see the problem here (from the perspective of gdb ).

ukalappa-mips avatar Jul 08 '22 08:07 ukalappa-mips