Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

[DebugInfo] DBG_VALUE for spill is emitted before the spill is performed #37872

Closed Quuxplusone closed 4 years ago

Quuxplusone commented 6 years ago
Bugzilla Link PR38899
Status RESOLVED FIXED
Importance P normal
Reported by David Stenberg (david.stenberg@ericsson.com)
Reported on 2018-09-10 23:25:19 -0700
Last modified on 2019-11-01 13:15:48 -0700
Version trunk
Hardware PC Linux
CC aprantl@apple.com, bjorn.a.pettersson@ericsson.com, dblaikie@gmail.com, jdevlieghere@apple.com, jeremy.morse.llvm@gmail.com, llvm-bugs@lists.llvm.org, paul_robinson@playstation.sony.com
Fixed by commit(s) rG56c22931bdfafe8257e61
Attachments foo.c (402 bytes, text/plain)
foo.ll (3352 bytes, text/plain)
Blocks
Blocked by
See also
Created attachment 20865
C reproducer.

Reproduced on trunk (r341822).

When compiling the attached C file using:

        clang -O3 -g foo.c -S --target=ppc64 -S -emit-llvm -o foo.ll
        llc -O3 foo.ll -o foo.mir -print-before-all -print-after-all -debug -stop-after=virtregrewriter &> foo.log

we get a spurious DBG_VALUE emitted for the variable c after register
allocation.

Before Debug Variable Analysis:

        # *** IR Dump Before Debug Variable Analysis ***:
        # Machine code for function test: NoPHIs, TracksLiveness
        Function Live Ins: $x3 in %0, $x4 in %1

        0B  bb.0.entry:
              liveins: $x3, $x4
              DBG_VALUE debug-use $x3, debug-use $noreg, !"a", !DIExpression(), debug-location !16; foo.c:8:14 line no:8
              DBG_VALUE debug-use $x4, debug-use $noreg, !"b", !DIExpression(), debug-location !17; foo.c:8:21 line no:8
        16B   %1:g8rc = COPY $x4
              DBG_VALUE debug-use %1:g8rc, debug-use $noreg, !"b", !DIExpression(), debug-location !17; foo.c:8:21 line no:8
        32B   %0:g8rc = COPY $x3
              DBG_VALUE debug-use %0:g8rc, debug-use $noreg, !"a", !DIExpression(), debug-location !16; foo.c:8:14 line no:8
              DBG_VALUE debug-use %0.sub_32:g8rc, debug-use $noreg, !"a", !DIExpression(), debug-location !16; foo.c:8:14 line no:8
              DBG_VALUE debug-use %1.sub_32:g8rc, debug-use $noreg, !"b", !DIExpression(), debug-location !17; foo.c:8:21 line no:8
        80B   %4:gprc = MULLW %1.sub_32:g8rc, %0.sub_32:g8rc, debug-location !18; foo.c:9:13
              DBG_VALUE debug-use %4:gprc, debug-use $noreg, !"c", !DIExpression(), debug-location !19; foo.c:9:7 line no:9
        96B   INLINEASM &"" [sideeffect] [attdialect], $0:[clobber], {{{ implicit-def early-clobber of $r0-$r1 omitted }}}, !25, debug-location !20; foo.c:2:3 @[ foo.c:10:3 ]
        112B      %5:g8rc = EXTSW_32_64 %4:gprc, debug-location !26; foo.c:11:3
        128B      $x3 = COPY %5:g8rc, debug-location !26; foo.c:11:3
        144B      BLR8 implicit $lr8, implicit $rm, implicit $x3, debug-location !26; foo.c:11:3

        # End machine code for function test.

        ********** COMPUTING LIVE DEBUG VARIABLES: test **********
        ********** DEBUG VARIABLES **********
        !"a,8"   [0B;0e):0 [80B;80r):2 Loc0=debug-use $x3 Loc1=debug-use %0 Loc2=debug-use %0.sub_32
        !"b,8"   [0B;0e):0 [16r;32r):1 [80B;80r):2 Loc0=debug-use $x4 Loc1=debug-use %1 Loc2=debug-use %1.sub_32
        !"c,9"   [80r;112r):0 Loc0=debug-use %4

and after Virtual Register Rewriter:

        ********** EMITTING LIVE DEBUG VARIABLES **********
        !"a,8"   [0B;0e):0 [80B;80r):2 Loc0=debug-use $x3 Loc1=debug-use %0 Loc2=debug-use %0.sub_32
            [0B;0e):0 %bb.0-160B
            [64B;80r):1 %bb.0-160B
        !"b,8"   [0B;0e):0 [16r;32r):1 [80B;80r):2 Loc0=debug-use $x4 Loc1=debug-use %1 Loc2=debug-use %1.sub_32
            [0B;0e):0 %bb.0-160B
            [16r;32r):0 %bb.0-160B
            [64B;80r):1 %bb.0-160B
        !"c,9"   [80r;112r):0 Loc0=debug-use %4
            [80r;112r):0 %bb.0-160B
        # *** IR Dump After Virtual Register Rewriter ***:
        # Machine code for function test: NoPHIs, TracksLiveness, NoVRegs
        Frame Objects:
          fi#0: size=4, align=4, at location [SP]
        Function Live Ins: $x3, $x4

        bb.0.entry:
          liveins: $x3, $x4
          DBG_VALUE debug-use $x3, debug-use $noreg, !"a", !DIExpression(), debug-location !16; foo.c:8:14 line no:8
          DBG_VALUE debug-use $r3, debug-use $noreg, !"a", !DIExpression(), debug-location !16; foo.c:8:14 line no:8
          DBG_VALUE debug-use $x4, debug-use $noreg, !"b", !DIExpression(), debug-location !17; foo.c:8:21 line no:8
          DBG_VALUE debug-use $x4, debug-use $noreg, !"b", !DIExpression(), debug-location !17; foo.c:8:21 line no:8
          DBG_VALUE debug-use $r4, debug-use $noreg, !"b", !DIExpression(), debug-location !17; foo.c:8:21 line no:8
          renamable $r3 = MULLW renamable $r4, renamable $r3, implicit killed $x3, implicit killed $x4, debug-location !18; foo.c:9:13
          DBG_VALUE %stack.0, 0, !"c", !DIExpression(), debug-location !19; foo.c:9:7 line no:9
          STW killed renamable $r3, 0, %stack.0 :: (store 4 into %stack.0)
          INLINEASM &"" [sideeffect] [attdialect], $0:[clobber], {{{ implicit-def early-clobber of $r0-$r1 omitted }}}, !25, debug-location !20; foo.c:2:3 @[ foo.c:10:3 ]
          renamable $r3 = LWZ 0, %stack.0, debug-location !26 :: (load 4 from %stack.0); foo.c:11:3
          renamable $x3 = EXTSW_32_64 killed renamable $r3, debug-location !26; foo.c:11:3
          BLR8 implicit $lr8, implicit $rm, implicit $x3, debug-location !26; foo.c:11:3

As seen, a DBG_VALUE referring to the spill stack slot is emitted before the
spill is performed.

I guess that the ideal output would be a DBG_VALUE referring to $r3 after the
MULLW, and one after the spill, i.e.:

          renamable $r3 = MULLW renamable $r4, renamable $r3, implicit killed $x3, implicit killed $x4, debug-location !18; foo.c:9:13
          DBG_VALUE debug-use $r3, debug-use $noreg, !"c", !DIExpression(), debug-location !19; foo.c:9:7 line no:9
          STW killed renamable $r3, 0, %stack.0 :: (store 4 into %stack.0)
          DBG_VALUE %stack.0, 0, !"c", !DIExpression(), debug-location !19; foo.c:9:7 line no:9
Quuxplusone commented 6 years ago

Attached foo.c (402 bytes, text/plain): C reproducer.

Quuxplusone commented 6 years ago

Attached foo.ll (3352 bytes, text/plain): IR reproducer.

Quuxplusone commented 4 years ago

Proposed patch: https://reviews.llvm.org/D69584

Quuxplusone commented 4 years ago

Resolved by https://github.com/llvm/llvm-project/commit/56c22931bdfafe8257e610cb9f29b9d64478f812