[llvm] [GlobalISel] Make IRTranslator able to handle PHIs with empty types. (PR #73235)

Dávid Ferenc Szabó via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 12 00:23:35 PST 2024


https://github.com/dfszabo updated https://github.com/llvm/llvm-project/pull/73235

>From 9ffc669d348b445280365dd6145ad454b68dfa23 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?D=C3=A1vid=20Ferenc=20Szab=C3=B3?=
 <szabodavidferenc at gmail.com>
Date: Fri, 12 Jan 2024 09:22:49 +0100
Subject: [PATCH] [GlobalISel] Make IRTranslator able to handle PHIs with empty
 types.

SelectionDAG already handle this since e53b7d1a11d180ed7b33190a837d8898ab2a0b71.
---
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp  |  2 ++
 .../AArch64/GlobalISel/phi-with-empty-type.ll | 32 +++++++++++++++++++
 2 files changed, 34 insertions(+)
 create mode 100644 llvm/test/CodeGen/AArch64/GlobalISel/phi-with-empty-type.ll

diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 8a6bfdc5ee669c..662de0f3fe0e5e 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -3223,6 +3223,8 @@ void IRTranslator::finishPendingPhis() {
 #endif // ifndef NDEBUG
   for (auto &Phi : PendingPHIs) {
     const PHINode *PI = Phi.first;
+    if (PI->getType()->isEmptyTy())
+      continue;
     ArrayRef<MachineInstr *> ComponentPHIs = Phi.second;
     MachineBasicBlock *PhiMBB = ComponentPHIs[0]->getParent();
     EntryBuilder->setDebugLoc(PI->getDebugLoc());
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/phi-with-empty-type.ll b/llvm/test/CodeGen/AArch64/GlobalISel/phi-with-empty-type.ll
new file mode 100644
index 00000000000000..4aaa58e8dab2e0
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/phi-with-empty-type.ll
@@ -0,0 +1,32 @@
+; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
+; RUN: llc < %s -O0 -global-isel -mtriple=aarch64 -stop-after=irtranslator | FileCheck %s
+
+
+%zero = type [0 x i8]
+
+define %zero @test(%zero %x, %zero %y) {
+  ; CHECK-LABEL: name: test
+  ; CHECK: bb.1.b1:
+  ; CHECK-NEXT:   successors: %bb.3(0x40000000), %bb.2(0x40000000)
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT:   [[DEF:%[0-9]+]]:_(s1) = G_IMPLICIT_DEF
+  ; CHECK-NEXT:   G_BRCOND [[DEF]](s1), %bb.3
+  ; CHECK-NEXT:   G_BR %bb.2
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT: bb.2.b2:
+  ; CHECK-NEXT:   successors: %bb.3(0x80000000)
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT:   G_BR %bb.3
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT: bb.3.end:
+  ; CHECK-NEXT:   RET_ReallyLR
+b1:
+  br i1 undef, label %end, label %b2
+
+b2:
+  br label %end
+
+end:
+  %z = phi %zero [ %y, %b1 ], [ %x, %b2 ]
+  ret %zero %z
+}



More information about the llvm-commits mailing list