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

[MachineCopyPropagagation] Incorrect dead flag survives

Open JonPsson opened this issue 9 years ago • 4 comments

Bugzilla Link 33037
Version trunk
OS Linux
Blocks llvm/llvm-project#31494
Attachments reduced testcase
CC @RKSimon,@MatzeB,@JonPsson,@uweigand

Extended Description

In this MBB:

BB#0: derived from LLVM BB %BB %V0 = VGBM 0 %V1<def,dead> = COPY %V0 %V1 = COPY %V0 %V1<def,tied1> = VLEIH %V1<kill,tied0>, 0, 1 %V0 = VCEQH %V1, %V0 %R1D = LARL <cp#0> %V1 = VL %R1D, 0, %noreg; mem:LD16ConstantPool %V0<def,dead> = VPERM %V0, %V0, %V1

, the first COPY of %V0 to %V1 has a dead flag, while the second one doesn't.

The optimization seems to think the second COPY is redundant, and calls eraseIfRedundant(). Afterwards, this results in:

    %V1<def,dead> = COPY %V0
    %V1<def,tied1> = VLEIH %V1<kill,tied0>, 0, 1

*** Bad machine code: Using an undefined physical register ***

  • function: autogen_SD11756
  • basic block: BB#0 BB (0x3c90be8)
  • instruction: %V1<def,tied1> = VLEIH
  • operand 1: %V1<kill,tied0>

Somehow, the dead flag should have been removed.

Run line: llc -O3 -mtriple=s390x-linux-gnu -mcpu=z13 -verify-machineinstrs -disable-cgp -pre-RA-sched=source -disable-machine-dce -join-liveintervals=false -o /dev/null ./tc_mcp_undefphysreg.ll

JonPsson avatar May 15 '17 09:05 JonPsson

Found another test case for this bug, which this time showed up after if conversion. I think this is because the live in list of BB#3 is hiding the error.

Related then: I am currently cleaning up aarch64 for the following stricter machine verifier: https://reviews.llvm.org/D33650 That should at least un-hide the error.

MatzeB avatar May 29 '17 14:05 MatzeB

I keep seeing this bug in testing regularly...

JonPsson avatar May 29 '17 11:05 JonPsson

reduced testcase (fails after ifconvert) Found another test case for this bug, which this time showed up after if conversion. I think this is because the live in list of BB#3 is hiding the error.

Run with: llc -mtriple=s390x-linux-gnu -mcpu=z13 -O3 -verify-machineinstrs -disable-cgp -disable-machine-dce -join-liveintervals=false -disable-branch-fold tc_ifconvert.ll

BB#2: derived from LLVM BB %CF290 Live Ins: %R2D Predecessors according to CFG: BB#1 %R0L = LBMux %R2D, 0, %noreg; mem:LD1[%0] %V0 = VGBM 13107 VST %V0, %R1D, 0, %noreg; mem:ST16undef %R1L<def,dead> = COPY %R0L %R1L = COPY %R0L Successors according to CFG: BB#3(?%)

BB#3: derived from LLVM BB %CF260 Live Ins: %R2D %R0L %R1L Predecessors according to CFG: BB#2 STCMux %R1L, %R2D, 0, %noreg; mem:ST1[%0] Successors according to CFG: BB#4(?%)

*** IR Dump After Machine Copy Propagation Pass ***:

BB#2: derived from LLVM BB %CF290 Live Ins: %R2D Predecessors according to CFG: BB#1 %R0L = LBMux %R2D, 0, %noreg; mem:LD1[%0] %V0 = VGBM 13107 VST %V0, %R1D, 0, %noreg; mem:ST16undef %R1L<def,dead> = COPY %R0L Successors according to CFG: BB#3(?%)

BB#3: derived from LLVM BB %CF260 Live Ins: %R2D %R0L %R1L Predecessors according to CFG: BB#2 STCMux %R1L, %R2D, 0, %noreg; mem:ST1[%0]

->

After If Converter

BB#2: derived from LLVM BB %CF290 Live Ins: %R2D Predecessors according to CFG: BB#1 %R0L = LB %R2D, 0, %noreg; mem:LD1[%0] %V0 = VGBM 13107 VST %V0, %R1D, 0, %noreg; mem:ST16undef %R1L<def,dead> = KILL %R0L STC %R1L, %R2D, 0, %noreg; mem:ST1[%0] %V0 = VGBM 0 %V0<def,dead,tied1> = VLVGB %V0<kill,tied0>, %R0L, %noreg, 2 %R0L = LHI 0

*** Bad machine code: Using an undefined physical register ***

  • function: autogen_SD3330
  • basic block: BB#2 CF290 (0x4f6b9a8)
  • instruction: STC
  • operand 0: %R1L

JonPsson avatar May 18 '17 16:05 JonPsson

As this is a bug in MachineCopyPropagation pass, it really isn't a bug in the SystemZ backend, right?

JonPsson avatar May 17 '17 07:05 JonPsson