Skip to content

Commit a4ade9e

Browse files
committed
[MachineVerifier] Handle the PHI node for verifyLiveVariables()
Summary: 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. This patch is to fix above bug. Reviewed By: bjope Differential Revision: https://reviews.llvm.org/D80274
1 parent d42c7b2 commit a4ade9e

File tree

3 files changed

+105
-26
lines changed

3 files changed

+105
-26
lines changed

llvm/lib/CodeGen/MachineVerifier.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ namespace {
132132
bool reachable = false;
133133

134134
// Vregs that must be live in because they are used without being
135-
// defined. Map value is the user.
135+
// defined. Map value is the user. vregsLiveIn doesn't include regs
136+
// that only are used by PHI nodes.
136137
RegMap vregsLiveIn;
137138

138139
// Regs killed in MBB. They may be defined again, and will then be in both
@@ -2302,6 +2303,23 @@ void MachineVerifier::calcRegsRequired() {
23022303
if (PInfo.addRequired(MInfo.vregsLiveIn))
23032304
todo.insert(Pred);
23042305
}
2306+
2307+
// Handle the PHI node.
2308+
for (const MachineInstr &MI : MBB.phis()) {
2309+
for (unsigned i = 1, e = MI.getNumOperands(); i != e; i += 2) {
2310+
// Skip those Operands which are undef regs or not regs.
2311+
if (!MI.getOperand(i).isReg() || !MI.getOperand(i).readsReg())
2312+
continue;
2313+
2314+
// Get register and predecessor for one PHI edge.
2315+
Register Reg = MI.getOperand(i).getReg();
2316+
const MachineBasicBlock *Pred = MI.getOperand(i + 1).getMBB();
2317+
2318+
BBInfo &PInfo = MBBInfoMap[Pred];
2319+
if (PInfo.addRequired(Reg))
2320+
todo.insert(Pred);
2321+
}
2322+
}
23052323
}
23062324

23072325
// Iteratively push vregsRequired to predecessors. This will converge to the

llvm/test/CodeGen/PowerPC/livevars-crash1.mir

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# RUN: not --crash llc -mtriple powerpc64le-unknown-linux-gnu %s -o - 2>&1 \
2-
# RUN: -run-pass=livevars,phi-node-elimination -verify-machineinstrs \
3-
# RUN: | FileCheck %s
1+
# RUN: llc -mtriple powerpc64le-unknown-linux-gnu %s -o - 2>&1 \
2+
# RUN: -run-pass=livevars,phi-node-elimination -verify-machineinstrs | \
3+
# RUN: FileCheck %s
44

55
--- |
66
; Function Attrs: noreturn nounwind
@@ -82,9 +82,46 @@ body: |
8282
STD %3, 0, %4 :: (store 8 into %ir.p)
8383
B %bb.1
8484
85+
; CHECK-LABEL: name: zext_free
86+
; CHECK: bb.0.entry:
87+
; CHECK: successors: %bb.1(0x80000000)
88+
; CHECK: liveins: $x3
89+
90+
; CHECK: %4:g8rc_and_g8rc_nox0 = COPY killed $x3
91+
; CHECK: %0:g8rc = LD 0, %4 :: (dereferenceable load 8 from %ir.p)
92+
; CHECK: %12:g8rc_and_g8rc_nox0 = COPY killed %0
93+
94+
; CHECK: bb.1.loop:
95+
; CHECK: successors: %bb.1(0x20000000), %bb.2(0x60000000)
96+
97+
; CHECK: %1:g8rc_and_g8rc_nox0 = COPY killed %12
98+
; CHECK: %5:gprc = LBZ 0, %1 :: (load 1 from %ir.0)
99+
; CHECK: %6:crrc = CMPWI killed %5, 0
100+
; CHEXK: %7:crbitrc = COPY killed %6.sub_eq
101+
; CHECK: %2:g8rc = nuw ADDI8 %1, 1
102+
; CHECK: STD %2, 0, %4 :: (store 8 into %ir.p)
103+
; CHECK: %8:gprc = LBZ 1, %1 :: (load 1 from %ir.incdec.ptr)
104+
; CHECK: %12:g8rc_and_g8rc_nox0 = COPY %2
105+
; CHECK: BCn killed %7, %bb.1
106+
; CHECK: B %bb.2
107+
108+
; CHECK: bb.2.loop:
109+
; CHECK: successors: %bb.3(0x55555555), %bb.1(0x2aaaaaab)
110+
111+
; CHECK: %9:crrc = CMPWI killed %8, 0
112+
; CHECK: %10:crbitrc = COPY killed %9.sub_eq
113+
; CHECK: %12:g8rc_and_g8rc_nox0 = COPY killed %2
114+
; CHECK: BC killed %10, %bb.1
115+
; CHECK: B %bb.3
116+
117+
; CHECK: bb.3.if.then3:
118+
; CHECK: successors: %bb.1(0x80000000)
119+
120+
; CHECK: %3:g8rc = nuw ADDI8 killed %1, 2
121+
; CHECK: STD %3, 0, %4 :: (store 8 into %ir.p)
122+
; CHECK: %12:g8rc_and_g8rc_nox0 = COPY killed %3
123+
; CHECK: B %bb.1
124+
125+
85126
...
86-
# CHECK-LABEL: Bad machine code: LiveVariables: Block should not be in AliveBlocks
87-
# CHECK-NEXT: - function: zext_free
88-
# CHECK-NEXT: - basic block: %bb.2 loop
89-
# CHECK-NEXT: Virtual register %2 is not needed live through the block.
90-
# CHECK-NEXT: LLVM ERROR: Found 1 machine code errors.
127+

llvm/test/CodeGen/PowerPC/livevars-crash2.mir

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# RUN: not --crash llc -mtriple powerpc64le-unknown-linux-gnu %s -o - 2>&1 \
2-
# RUN: -run-pass=livevars,phi-node-elimination -verify-machineinstrs \
3-
# RUN: | FileCheck %s
1+
# RUN: llc -mtriple powerpc64le-unknown-linux-gnu %s -o - 2>&1 \
2+
# RUN: -run-pass=livevars,phi-node-elimination -verify-machineinstrs | \
3+
# RUN: FileCheck %s
44

55
--- |
66
define float @testfloatslt(float %c1, float %c2, float %c3, float %c4, float %a1, float %a2) {
@@ -176,20 +176,44 @@ body: |
176176
STD %3, 0, %4 :: (store 8 into %ir.p)
177177
B %bb.1
178178
179-
...
179+
; CHECK-LABEL: name: testfloatslt
180+
; CHECK: bb.0.entry:
181+
; CHECK: successors: %bb.1(0x80000000)
182+
; CHECK: liveins: $x3
183+
184+
; CHECK: %4:g8rc_and_g8rc_nox0 = COPY killed $x3
185+
; CHECK: %0:g8rc = LD 0, %4 :: (dereferenceable load 8 from %ir.p)
186+
; CHECK: %12:g8rc_and_g8rc_nox0 = COPY killed %0
187+
188+
; CHECK: bb.1.loop:
189+
; CHECK: successors: %bb.1(0x20000000), %bb.2(0x60000000)
190+
191+
; CHECK: %1:g8rc_and_g8rc_nox0 = COPY killed %12
192+
; CHECK: %5:gprc = LBZ 0, %1 :: (load 1 from %ir.0)
193+
; CHECK: %6:crrc = CMPWI killed %5, 0
194+
; CEHCK: %7:crbitrc = COPY killed %6.sub_eq
195+
; CHECK: %2:g8rc = nuw ADDI8 %1, 1
196+
; CHECK: STD %2, 0, %4 :: (store 8 into %ir.p)
197+
; CHECK: %8:gprc = LBZ 1, %1 :: (load 1 from %ir.incdec.ptr)
198+
; CHECK: %12:g8rc_and_g8rc_nox0 = COPY %2
199+
; CHECK: BCn killed %7, %bb.1
200+
; CHECK: B %bb.2
180201
181-
# CHECK-LABEL: Bad machine code: LiveVariables: Block should not be in AliveBlocks
182-
# CHECK-NEXT: - function: testfloatslt
183-
# CHECK-NEXT: - basic block: %bb.1 entry
184-
# CHECK-NEXT: Virtual register %4 is not needed live through the block.
202+
; CHECK: bb.2.loop:
203+
; CHECK: successors: %bb.3(0x55555555), %bb.1(0x2aaaaaab)
185204
186-
# CHECK-LABEL: Bad machine code: LiveVariables: Block should not be in AliveBlocks
187-
# CHECK-NEXT: - function: testfloatslt
188-
# CHECK-NEXT: - basic block: %bb.1 entry
189-
# CHECK-NEXT: Virtual register %5 is not needed live through the block.
205+
; CHECK: %9:crrc = CMPWI killed %8, 0
206+
; CHECK: %10:crbitrc = COPY killed %9.sub_eq
207+
; CHECK: %12:g8rc_and_g8rc_nox0 = COPY killed %2
208+
; CHECK: BC killed %10, %bb.1
209+
; CHECK: B %bb.3
190210
191-
# CHECK-LABEL: Bad machine code: LiveVariables: Block should not be in AliveBlocks
192-
# CHECK-NEXT: - function: testfloatslt
193-
# CHECK-NEXT: - basic block: %bb.2 entry
194-
# CHECK-NEXT: Virtual register %5 is not needed live through the block.
195-
# CHECK-NEXT: LLVM ERROR: Found 3 machine code errors.
211+
; CHECK: bb.3.if.then3:
212+
; CHECK: successors: %bb.1(0x80000000)
213+
214+
; CHECK: %3:g8rc = nuw ADDI8 killed %1, 2
215+
; CHECK: STD %3, 0, %4 :: (store 8 into %ir.p)
216+
; CHECK: %12:g8rc_and_g8rc_nox0 = COPY killed %3
217+
; CHECK: B %bb.1
218+
219+
...

0 commit comments

Comments
 (0)