llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.97k stars 11.54k forks source link

[RegCoalescer] Bad machine code: Live segment doesn't end at a valid instruction #84815

Open JonPsson1 opened 6 months ago

JonPsson1 commented 6 months ago
cat tc_crash3_aftercreduce.ll
define i64 @f(ptr %arg) {
bb:
  %i = load i136, ptr %arg, align 4
  %i1 = lshr i136 %i, 32
  br label %bb2

bb2:
  %i3 = trunc i136 %i1 to i64
  ret i64 %i3
}

llc -mtriple=s390x-linux-gnu -mcpu=zEC12 -O3 -disable-machine-dce -verify-machineinstrs  tc_crash3_aftercreduce.ll

*** Bad machine code: Live segment doesn't end at a valid instruction ***
- function:    f
- basic block: %bb.0  (0x2aa03c3f3b8) [0B;256B)
- liverange:   [176r,224d:0) 0@176r
- v. register: %1
- segment:     [176r,224d:0)

It seems that the coalescer is messing up the dead-flag(s), and the resulting live-range is broken:

 dead %1:gr64bit = INSERT_SUBREG killed %10:gr64bit(tied-def 0), killed %11:grx32bit, %subreg.subreg_l32

=>  # *** IR Dump After Two-Address instruction pass (twoaddressinstruction) ***:

  %1:gr64bit = COPY killed %10:gr64bit
  dead %1.subreg_l32:gr64bit = COPY killed %11:grx32bit

=>  # *** IR Dump After Live Interval Analysis (liveintervals) ***:

208B      %1:gr64bit = COPY %10:gr64bit
224B      dead %1.subreg_l32:gr64bit = COPY %11:grx32bit

=> # *** IR Dump After Register Coalescer (register-coalescer) ***:

176B      %1:gr64bit = SRLG %4:gr64bit, $noreg, 24
240B      dead %0:gr64bit = LGHI 0

*** Bad machine code: Live segment doesn't end at a valid instruction ***
- function:    f
- basic block: %bb.0  (0x2aa03c4e5c8) [0B;256B)
- liverange:   [176r,224d:0) 0@176r
- v. register: %1

@DianQK @aeubanks ..?

Godbolt: https://llvm.godbolt.org/z/e6Eafrbh9

aeubanks commented 6 months ago

(I have very little experience in this part of LLVM)

DianQK commented 6 months ago

I can reproduce it using any version. But I also know very little about it.