-verify-regalloc discovers "Instruction ending live segment on dead slot has no dead flag"
| Bugzilla Link | 33024 |
| Version | trunk |
| OS | Linux |
| Attachments | reduced testcase |
| CC | @MatzeB,@JonPsson,@uweigand |
Extended Description
With this reduced llvm-stress test case, run with
llc -mtriple=s390x-linux-gnu -mcpu=z13 -verify-regalloc -disable-lsr -disable-machine-licm -disable-machine-dce -join-liveintervals=false -o /dev/null ./tc_deadslot.ll
It seems that loadRegFromStackSlot() is called, and then verifier complains that the created instruction is missing a dead-flag. I am not sure where this should be fixed...
Output:
0B BB#0: derived from LLVM BB %BB
Live Ins: %R2L
16B %vreg5
64B BB#1: derived from LLVM BB %CF253
Predecessors according to CFG: BB#0 BB#1
72B %vreg11
320B BB#2: derived from LLVM BB %CF258 Predecessors according to CFG: BB#1 BB#2 336B J <BB#2> Successors according to CFG: BB#2(?%)
End machine code for function autogen_SD9889.
*** Bad machine code: Instruction ending live segment on dead slot has no dead flag ***
- function: autogen_SD9889
- basic block: BB#1 CF253 (0x4f45158) [64B;320B)
- instruction: 224B %vreg2
= VL - liverange: [224r,224d:0) 0@224r
- v. register: %vreg2
- segment: [224r,224d:0) LLVM ERROR: Found 1 machine code errors.
mentioned in issue llvm/llvm-bugzilla-archive#39154
reduced testcase that works on trunk Old test case seem to not trigger the bug anymore.
Run new test case with:
bin/llc -mtriple=s390x-linux-gnu -mcpu=z13 -disable-machine-dce -join-liveintervals=false -verify-machineinstrs -o /dev/null ./tc_deadslot_2.ll
=>
*** Bad machine code: Instruction ending live segment on dead slot has no dead flag ***
ping! I see this assertion not that unfrequently with csmith programs.
It seems that this was actually a dead COPY to begin with:
*** IR Dump After Live Register Matrix ***:
224B %vreg2<def,dead> = COPY %vreg0; VR128Bit:%vreg2,%vreg0
After spilling
224B %vreg2
*** Bad machine code: Instruction ending live segment on dead slot has no dead fl
It looks like %vreg0 was spilled, but it is only reloaded once into a dead register. Eventually, loadRegFromStackSlot() is called which fails to preserve the dead flag.
Perhaps the dead COPY should just be removed somewhere before that point?
To answer this question we would need more information on how this happens. You would expect code that calls loadRegFromStackSlot() has at least 1 one user at the moment it is called. If that is not the case then the bug is there.
If the user is later removed for some reason then we have to set the dead flag at that point and the bug would be there.