The problem can occur in presence of subregs. If we are swapping two
instructions defining different subregs of the same register we will
get a new liveout from a block. We need to preserve value number for
block's liveout for successor block's livein to match.
To illustrate the problem exposed by that test: before scheduling we had:
%vreg12 [48r,96r:0)[96r,112r:1)[112r,400r:2)[464B,560r:2) 0@48r 1@96r 2@112r L00000001 [48r,208r:0) 0@48r L00000002 [48r,208r:0) 0@48r L00000004 [112r,384r:0)[464B,544r:0) 0@112r L000000 0B BB#0: derived from LLVM BB %entry Live Ins: %SGPR0_SGPR1 16B %vreg1<def> = COPY %SGPR0_SGPR1; SGPR_64:%vreg1 32B %vreg20:sub0_sub1<def,read-undef> = S_LOAD_DWORDX2_IMM %vreg1, 9, 0; mem:LD8[undef(addrspace=2)](nontemporal)(dereferenceable)(invariant) SReg_128:%vreg20 SGPR_64:%vreg1 48B %vreg12:sub0_sub1<def,read-undef> = S_LOAD_DWORDX2_IMM %vreg1, 11, 0; mem:LD8[undef(addrspace=2)](nontemporal)(dereferenceable)(invariant) SReg_128:%vreg12 SGPR_64:%vreg1 96B %vreg12:sub3<def> = S_MOV_B32 61440; SReg_128:%vreg12 112B %vreg12:sub2<def> = S_MOV_B32 -1; SReg_128:%vreg12 … 464B BB#2: derived from LLVM BB %two Predecessors according to CFG: BB#0 544B %vreg20:sub2<def> = COPY %vreg12:sub2; SReg_128:%vreg20,%vreg12 560B %vreg20:sub3<def> = COPY %vreg12:sub3; SReg_128:%vreg20,%vreg12
%vreg12 is liveout from BB#0, segment with value #2: 112r,400r:2. Livein into #BB2 has value #2: [464B,560r:2)
After the scheduling:
%vreg12 [24r,28r:1)[28r,48r:2)[48r,400r:0)[464B,584r:2) 0@48r 1@24r 2@28r L00000001 [48r,208r:0) 0@48r L00000002 [48r,208r:0) 0@48r L00000004 [28r,384r:0)[464B,580r:0) 0@28r L00000008 [24r,400r:0)[464B,584r:0) 0@24r 0B BB#0: derived from LLVM BB %entry Live Ins: %SGPR0_SGPR1 16B %vreg1<def> = COPY %SGPR0_SGPR1; SGPR_64:%vreg1 24B %vreg12:sub3<def,read-undef> = S_MOV_B32 61440; SReg_128:%vreg12 28B %vreg12:sub2<def> = S_MOV_B32 -1; SReg_128:%vreg12 48B %vreg12:sub0_sub1<def> = S_LOAD_DWORDX2_IMM %vreg1, 11, 0; mem:LD8[undef(addrspace=2)](nontemporal)(dereferenceable)(invariant) SReg_128:%vreg12 SGPR_64:%vreg1 … 464B BB#2: derived from LLVM BB %two Predecessors according to CFG: BB#0 576B %vreg21<def> = V_CVT_F16_F32_e32 %vreg0, %EXEC<imp-use>; VGPR_32:%vreg21,%vreg0 580B %vreg20:sub2<def> = COPY %vreg12:sub2; SReg_128:%vreg20,%vreg12 584B %vreg20:sub3<def> = COPY %vreg12:sub3; SReg_128:%vreg20,%vreg12
We have switched %vreg12 subreg definitions, so the new liveout from BB#0 is [48r,400r:0), value number 0. BB#2's livein is not updated: [464B,584r:2).
At this point liveout != livein and LIS is broken. Verifier will report the error.