When doing MachineVerifier for LiveVariables, the MachineVerifier pass will calculate the LiveVariables,
and compares the result with the result livevars pass gave. If they are different, verifyLiveVariables()
will give error.
But when we calculate the LiveVariables in MachineVerifier, we don't consider the PHI node, while livevars
considers, so we will get different result and verifyLiveVariables() will be failed.
Now, we don't enable the verificatoin for LiveVariables, so we haven't gotten the failure for verifyLiveVariables().
For below case:
48 body: | 49 bb.0.entry: 50 successors: %bb.1(0x80000000) 51 liveins: $x3 52 53 %4:g8rc_and_g8rc_nox0 = COPY killed $x3 54 %0:g8rc = LD 0, %4 :: (dereferenceable load 8 from %ir.p) 55 56 bb.1.loop: 57 successors: %bb.1(0x20000000), %bb.2(0x60000000) 58 59 %1:g8rc_and_g8rc_nox0 = PHI %0, %bb.0, %2, %bb.1, %3, %bb.3, %2, %bb.2 60 %5:gprc = LBZ 0, %1 :: (load 1 from %ir.0) 61 %6:crrc = CMPWI killed %5, 0 62 %7:crbitrc = COPY killed %6.sub_eq 63 %2:g8rc = nuw ADDI8 %1, 1 64 STD %2, 0, %4 :: (store 8 into %ir.p) 65 %8:gprc = LBZ 1, %1 :: (load 1 from %ir.incdec.ptr) 66 BCn killed %7, %bb.1 67 B %bb.2 68 69 bb.2.loop: 70 successors: %bb.3(0x55555555), %bb.1(0x2aaaaaab) 71 72 %9:crrc = CMPWI killed %8, 0 73 %10:crbitrc = COPY killed %9.sub_eq 74 BC killed %10, %bb.1 75 B %bb.3 76 77 bb.3.if.then3: 78 successors: %bb.1(0x80000000) 79 80 %3:g8rc = nuw ADDI8 killed %1, 2 81 STD %3, 0, %4 :: (store 8 into %ir.p) 82 B %bb.1
We will get below error:
# Bad machine code: LiveVariables: Block should not be in AliveBlocks # - function: zext_free # - basic block: %bb.2 loop # Virtual register %2 is not needed live through the block. # LLVM ERROR: Found 1 machine code errors.
But in fact, %2 is should live through the %bb.2. In the line 59 for PHI, %2 can be
from %bb.1 or %bb.2, and %2 is defined in %bb.1, so %2 is live through %bb2, not live
through %bb1.
Below is the liveVariables info for above case:
Reg: %1 Alive in blocks: 2, Killed by: #0: %3:g8rc = nuw ADDI8 killed %1:g8rc_and_g8rc_nox0, 2 Reg: %2 Alive in blocks: 2, Killed by: No instructions. Reg: %4 Alive in blocks: 1, 2, 3, Killed by: No instructions.
This patch can fix 210 verification error for LiveVariables.
Add a comment here that vregsLiveIn doesn't include regs that only are used by PHI nodes.