[llvm] [AsmParser] Convert empty arrays to `poison` (PR #119754)

Pedro Lobo via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 12 12:09:00 PST 2024


https://github.com/pedroclobo created https://github.com/llvm/llvm-project/pull/119754

Empty arrays can be converted to `poison` instead of `undef`.

>From a1b52d5d5c6cf3855a04a695888b1100204137e4 Mon Sep 17 00:00:00 2001
From: Pedro Lobo <pedro.lobo at tecnico.ulisboa.pt>
Date: Thu, 12 Dec 2024 20:01:35 +0000
Subject: [PATCH] [AsmParser] Convert empty arrays to `poison`

Empty arrays can be converted to `poison` instead of `undef`.
---
 llvm/lib/AsmParser/LLParser.cpp                   | 2 +-
 llvm/test/Assembler/aggregate-constant-values.ll  | 2 +-
 llvm/test/CodeGen/AMDGPU/amdgpu.private-memory.ll | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 34311499367b41..558ab3af632117 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -6185,7 +6185,7 @@ bool LLParser::convertValIDToValue(Type *Ty, ValID &ID, Value *&V,
   case ValID::t_EmptyArray:
     if (!Ty->isArrayTy() || cast<ArrayType>(Ty)->getNumElements() != 0)
       return error(ID.Loc, "invalid empty array initializer");
-    V = UndefValue::get(Ty);
+    V = PoisonValue::get(Ty);
     return false;
   case ValID::t_Zero:
     // FIXME: LabelTy should not be a first-class type.
diff --git a/llvm/test/Assembler/aggregate-constant-values.ll b/llvm/test/Assembler/aggregate-constant-values.ll
index 3ae356b55dff5c..b208b582a4657a 100644
--- a/llvm/test/Assembler/aggregate-constant-values.ll
+++ b/llvm/test/Assembler/aggregate-constant-values.ll
@@ -26,7 +26,7 @@ define void @bar(ptr %x) nounwind {
 }
 
 ; CHECK: @bar_empty
-; CHECK: store [0 x i32] undef, ptr %x
+; CHECK: store [0 x i32] poison, ptr %x
 ; CHECK: ret
 define void @bar_empty(ptr %x) nounwind {
   store [0 x i32][], ptr %x
diff --git a/llvm/test/CodeGen/AMDGPU/amdgpu.private-memory.ll b/llvm/test/CodeGen/AMDGPU/amdgpu.private-memory.ll
index c1a957dec3e867..82832277b1aba4 100644
--- a/llvm/test/CodeGen/AMDGPU/amdgpu.private-memory.ll
+++ b/llvm/test/CodeGen/AMDGPU/amdgpu.private-memory.ll
@@ -504,7 +504,7 @@ define amdgpu_kernel void @v2float_stack(ptr addrspace(1) %out, i32 %a) {
 }
 
 ; OPT-LABEL: @direct_alloca_read_0xi32(
-; OPT: store [0 x i32] undef, ptr addrspace(3)
+; OPT: store [0 x i32] poison, ptr addrspace(3)
 ; OPT: load [0 x i32], ptr addrspace(3)
 define amdgpu_kernel void @direct_alloca_read_0xi32(ptr addrspace(1) %out, i32 %index) {
 entry:



More information about the llvm-commits mailing list