]> granicus.if.org Git - llvm/commitdiff
MachineVerifier: undef phi arg doesn't need to be live-out from predecessor
authorMatthias Braun <matze@braunis.de>
Mon, 4 Dec 2017 18:57:48 +0000 (18:57 +0000)
committerMatthias Braun <matze@braunis.de>
Mon, 4 Dec 2017 18:57:48 +0000 (18:57 +0000)
Differential Revision: https://reviews.llvm.org/D40756

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319674 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/MachineVerifier.cpp
test/CodeGen/X86/verifier-phi-fail0.mir [new file with mode: 0644]
test/CodeGen/X86/verifier-phi.mir [new file with mode: 0644]

index fd00a2d750160e44eb763468fb24e01272b1fda0..6834059234eeda7bc131600b9dbcf665c87cb23a 100644 (file)
@@ -1652,7 +1652,8 @@ void MachineVerifier::checkPHIOps(const MachineBasicBlock &MBB) {
       if (MInfo.reachable) {
         seen.insert(&Pre);
         BBInfo &PrInfo = MBBInfoMap[&Pre];
-        if (PrInfo.reachable && !PrInfo.isLiveOut(MO0.getReg()))
+        if (!MO0.isUndef() && PrInfo.reachable &&
+            !PrInfo.isLiveOut(MO0.getReg()))
           report("PHI operand is not live-out from predecessor", &MO0, I);
       }
     }
diff --git a/test/CodeGen/X86/verifier-phi-fail0.mir b/test/CodeGen/X86/verifier-phi-fail0.mir
new file mode 100644 (file)
index 0000000..655cd2a
--- /dev/null
@@ -0,0 +1,30 @@
+# RUN: not llc -o - %s -verify-machineinstrs -run-pass=none 2>&1 | FileCheck %s
+---
+# CHECK: Bad machine code: PHI operand is not live-out from predecessor
+# CHECK: - function:    func0
+# CHECK: - basic block: %bb.3
+# CHECK: - instruction: %0<def> = PHI
+# CHECK: - operand 1:   %1
+#
+# CHECK: Bad machine code: PHI operand is not live-out from predecessor
+# CHECK: - function:    func0
+# CHECK: - basic block: %bb.3
+# CHECK: - instruction: %0<def> = PHI
+# CHECK: - operand 3:   %0
+name: func0
+tracksRegLiveness: true
+body: |
+  bb.0:
+    JE_1 %bb.1, implicit undef %eflags
+    JMP_1 %bb.2
+
+  bb.1:
+    %0:gr32 = IMPLICIT_DEF
+    JMP_1 %bb.3
+
+  bb.2:
+    %1:gr32 = IMPLICIT_DEF
+
+  bb.3:
+    %0:gr32 = PHI %1, %bb.1, %0, %bb.2
+...
diff --git a/test/CodeGen/X86/verifier-phi.mir b/test/CodeGen/X86/verifier-phi.mir
new file mode 100644 (file)
index 0000000..1a2f13c
--- /dev/null
@@ -0,0 +1,34 @@
+# RUN: llc -o - %s -verify-machineinstrs -run-pass=none | FileCheck %s
+# This should cleanly pass the machine verifier
+---
+# CHECK-LABEL: name: func0
+# CHECK: %0:gr32 = PHI undef %1:gr32, %bb.0, undef %1:gr32, %bb.1
+name: func0
+tracksRegLiveness: true
+body: |
+  bb.0:
+    JE_1 %bb.1, implicit undef %eflags
+    JMP_1 %bb.2
+
+  bb.1:
+
+  bb.2:
+    %0 : gr32 = PHI undef %1 : gr32, %bb.0, undef %1 : gr32, %bb.1
+...
+---
+# CHECK-LABEL: name: func1
+# CHECK: %2:gr32 = PHI %0, %bb.0, %1, %bb.1
+name: func1
+tracksRegLiveness: true
+body: |
+  bb.0:
+    %0 : gr32 = IMPLICIT_DEF
+    JE_1 %bb.1, implicit undef %eflags
+    JMP_1 %bb.2
+
+  bb.1:
+    %1 : gr32 = IMPLICIT_DEF
+
+  bb.2:
+    %2 : gr32 = PHI %0, %bb.0, %1, %bb.1
+...