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

[Early Machine LICM] Bad machine code: Virtual register killed in block, but needed live out.

Open JonPsson opened this issue 6 years ago • 6 comments

Bugzilla Link 47483
Version trunk
OS Linux
Attachments reduced testcase
CC @topperc,@JonPsson,@vedantk

Extended Description

llc -mcpu=z13 -O3 tc_mver_vregkilled_neededliveout.ll -sink-insts-to-avoid-spills -verify-machineinstrs

*** Bad machine code: Virtual register killed in block, but needed live out. ***

  • function: main
  • basic block: %bb.3 bb5 (0x677c338) Virtual register %5 is used after the block. LLVM ERROR: Found 1 machine code errors.

An LLGCR instruction with a killed vreg %5 is moved into the loop without the kill flag being cleared...

JonPsson avatar Sep 10 '20 12:09 JonPsson

This sinking code appears to be off by default so how can it be quite frequent?

I'm not sure I understand the code. The original commit message talks about sinking copy instructions, but the code seems to check that the users of the instruction being sunk are copies not the instruction itself.

Sorry - I meant that in random testing where this option sometimes is enabled I see this every week...

JonPsson avatar Oct 01 '20 08:10 JonPsson

This sinking code appears to be off by default so how can it be quite frequent?

I'm not sure I understand the code. The original commit message talks about sinking copy instructions, but the code seems to check that the users of the instruction being sunk are copies not the instruction itself.

topperc avatar Oct 01 '20 07:10 topperc

ping!

This is quite frequent with expensive checks enabled...

JonPsson avatar Sep 30 '20 09:09 JonPsson

testcase.tar.gz

llc -mcpu=arch13 -O3 -consthoist-gep -sink-insts-to-avoid-spills -verify-machineinstrs tc_crash0_aftercreduce.ll

This is still here...

A little unhappy with the confusion about kill flags and their "trustworthiness". When working on transformations it would be helpful to have something more documented, rather than "maybe not trust" kill flags "late".

Ideally, either the verifier should not complain if it is actually acceptable (i.e. "kill flags are not guaranteed to be correct"), or the transformation should be fixed to not leave false kill flags.

Having liveness modelled correctly always (all actually killing uses marked as "kill") would be ideal but not practical if it is not really needed and difficult to compute. A first good step then I think would be to at least clear kill flags to conservatively omit them rather than ignoring them and leaving a false kill flag in the IR (which could theoretically be dangerous if that kill flag is "trusted").

JonPsson avatar May 30 '22 15:05 JonPsson

I am not sure why this was assigned to me, was this a bug I created?

Probable solution: https://reviews.llvm.org/D126754

perlfu avatar Jun 01 '22 06:06 perlfu

Thanks for the patch! Your name was the best one I could find and there was no "subscribe" button, so I had to assign it to you. I was assuming you would either try to fix it or assign somebody else...

JonPsson avatar Jun 02 '22 15:06 JonPsson