[llvm] [ValueTracking] Return `poison` for zero-sized types (PR #122647)
Pedro Lobo via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 12 11:49:56 PST 2025
https://github.com/pedroclobo created https://github.com/llvm/llvm-project/pull/122647
Return `poison` for zero-sized types in `isBitwiseValue`.
>From 18069a24b6bd9ce23ddac10412a79c1582fe6561 Mon Sep 17 00:00:00 2001
From: Pedro Lobo <pedro.lobo at tecnico.ulisboa.pt>
Date: Sun, 12 Jan 2025 19:40:10 +0000
Subject: [PATCH] [ValueTracking] Return `poison` for zero-sized types
Return `poison` for zero-sized types in `isBitwiseValue`.
---
llvm/lib/Analysis/ValueTracking.cpp | 18 +++----
llvm/test/Transforms/MemCpyOpt/fca2memcpy.ll | 6 +--
.../Transforms/MemCpyOpt/memcpy-to-memset.ll | 2 +-
.../store-to-memset-is-nonzero-type.ll | 4 +-
llvm/unittests/Analysis/ValueTrackingTest.cpp | 52 +++++++++----------
5 files changed, 41 insertions(+), 41 deletions(-)
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 0e50fc60ce7921..89cd1cf944af79 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -6187,14 +6187,14 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) {
LLVMContext &Ctx = V->getContext();
- // Undef don't care.
- auto *UndefInt8 = UndefValue::get(Type::getInt8Ty(Ctx));
+ // Poison don't care.
+ auto *PoisonInt8 = PoisonValue::get(Type::getInt8Ty(Ctx));
if (isa<UndefValue>(V))
- return UndefInt8;
+ return PoisonInt8;
- // Return Undef for zero-sized type.
+ // Return poison for zero-sized type.
if (DL.getTypeStoreSize(V->getType()).isZero())
- return UndefInt8;
+ return PoisonInt8;
Constant *C = dyn_cast<Constant>(V);
if (!C) {
@@ -6252,15 +6252,15 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) {
return LHS;
if (!LHS || !RHS)
return nullptr;
- if (LHS == UndefInt8)
+ if (LHS == PoisonInt8)
return RHS;
- if (RHS == UndefInt8)
+ if (RHS == PoisonInt8)
return LHS;
return nullptr;
};
if (ConstantDataSequential *CA = dyn_cast<ConstantDataSequential>(C)) {
- Value *Val = UndefInt8;
+ Value *Val = PoisonInt8;
for (unsigned I = 0, E = CA->getNumElements(); I != E; ++I)
if (!(Val = Merge(Val, isBytewiseValue(CA->getElementAsConstant(I), DL))))
return nullptr;
@@ -6268,7 +6268,7 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) {
}
if (isa<ConstantAggregate>(C)) {
- Value *Val = UndefInt8;
+ Value *Val = PoisonInt8;
for (Value *Op : C->operands())
if (!(Val = Merge(Val, isBytewiseValue(Op, DL))))
return nullptr;
diff --git a/llvm/test/Transforms/MemCpyOpt/fca2memcpy.ll b/llvm/test/Transforms/MemCpyOpt/fca2memcpy.ll
index 61e349e01ed91d..0170833966ae49 100644
--- a/llvm/test/Transforms/MemCpyOpt/fca2memcpy.ll
+++ b/llvm/test/Transforms/MemCpyOpt/fca2memcpy.ll
@@ -81,7 +81,7 @@ define void @addrproducer(ptr %src, ptr %dst) {
; CHECK-LABEL: @addrproducer(
; CHECK-NEXT: [[DST2:%.*]] = getelementptr [[S:%.*]], ptr [[DST]], i64 1
; CHECK-NEXT: call void @llvm.memmove.p0.p0.i64(ptr align 8 [[DST2]], ptr align 8 [[SRC:%.*]], i64 16, i1 false)
-; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 8 [[DST:%.*]], i8 undef, i64 16, i1 false)
+; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 8 [[DST:%.*]], i8 poison, i64 16, i1 false)
; CHECK-NEXT: ret void
;
%1 = load %S, ptr %src
@@ -94,7 +94,7 @@ define void @addrproducer(ptr %src, ptr %dst) {
define void @aliasaddrproducer(ptr %src, ptr %dst, ptr %dstidptr) {
; CHECK-LABEL: @aliasaddrproducer(
; CHECK-NEXT: [[TMP1:%.*]] = load [[S:%.*]], ptr [[SRC:%.*]], align 8
-; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 8 [[DST:%.*]], i8 undef, i64 16, i1 false)
+; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 8 [[DST:%.*]], i8 poison, i64 16, i1 false)
; CHECK-NEXT: [[DSTINDEX:%.*]] = load i32, ptr [[DSTIDPTR:%.*]], align 4
; CHECK-NEXT: [[DST2:%.*]] = getelementptr [[S]], ptr [[DST]], i32 [[DSTINDEX]]
; CHECK-NEXT: store [[S]] [[TMP1]], ptr [[DST2]], align 8
@@ -114,7 +114,7 @@ define void @noaliasaddrproducer(ptr %src, ptr noalias %dst, ptr noalias %dstidp
; CHECK-NEXT: [[DSTINDEX:%.*]] = or i32 [[TMP2]], 1
; CHECK-NEXT: [[DST2:%.*]] = getelementptr [[S:%.*]], ptr [[DST:%.*]], i32 [[DSTINDEX]]
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[DST2]], ptr align 8 [[SRC]], i64 16, i1 false)
-; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 8 [[SRC:%.*]], i8 undef, i64 16, i1 false)
+; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 8 [[SRC:%.*]], i8 poison, i64 16, i1 false)
; CHECK-NEXT: ret void
;
%1 = load %S, ptr %src
diff --git a/llvm/test/Transforms/MemCpyOpt/memcpy-to-memset.ll b/llvm/test/Transforms/MemCpyOpt/memcpy-to-memset.ll
index 1858f306db9f3c..cbeb51ed2a3fd8 100644
--- a/llvm/test/Transforms/MemCpyOpt/memcpy-to-memset.ll
+++ b/llvm/test/Transforms/MemCpyOpt/memcpy-to-memset.ll
@@ -7,7 +7,7 @@ declare void @llvm.memcpy.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1) nounw
define void @test_undef() nounwind {
; CHECK-LABEL: @test_undef(
; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
-; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[A]], i8 undef, i64 4, i1 false)
+; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[A]], i8 poison, i64 4, i1 false)
; CHECK-NEXT: ret void
;
%a = alloca i32, align 4
diff --git a/llvm/test/Transforms/MemCpyOpt/store-to-memset-is-nonzero-type.ll b/llvm/test/Transforms/MemCpyOpt/store-to-memset-is-nonzero-type.ll
index 0455d65fe7521d..6b53138342ebff 100644
--- a/llvm/test/Transforms/MemCpyOpt/store-to-memset-is-nonzero-type.ll
+++ b/llvm/test/Transforms/MemCpyOpt/store-to-memset-is-nonzero-type.ll
@@ -5,7 +5,7 @@
define void @array_zero(ptr %p) {
; CHECK-LABEL: @array_zero(
-; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[P:%.*]], i8 undef, i64 0, i1 false)
+; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[P:%.*]], i8 poison, i64 0, i1 false)
; CHECK-NEXT: ret void
;
store [0 x i8] zeroinitializer, ptr %p
@@ -25,7 +25,7 @@ define void @array_nonzero(ptr %p) {
define void @struct_zero(ptr %p) {
; CHECK-LABEL: @struct_zero(
-; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[P:%.*]], i8 undef, i64 0, i1 false)
+; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[P:%.*]], i8 poison, i64 0, i1 false)
; CHECK-NEXT: ret void
;
store { } zeroinitializer, ptr %p
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 0145ee70a14c17..c82ab920975a8c 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -2769,8 +2769,8 @@ const std::pair<const char *, const char *> IsBytewiseValueTests[] = {
"ptr null",
},
{
- "i8 undef",
- "ptr undef",
+ "i8 poison",
+ "ptr poison",
},
{
"i8 0",
@@ -2789,8 +2789,8 @@ const std::pair<const char *, const char *> IsBytewiseValueTests[] = {
"i8 -1",
},
{
- "i8 undef",
- "i16 undef",
+ "i8 poison",
+ "i16 poison",
},
{
"i8 0",
@@ -2869,28 +2869,28 @@ const std::pair<const char *, const char *> IsBytewiseValueTests[] = {
"ptr inttoptr (i96 -1 to ptr)",
},
{
- "i8 undef",
+ "i8 poison",
"[0 x i8] zeroinitializer",
},
{
- "i8 undef",
- "[0 x i8] undef",
+ "i8 poison",
+ "[0 x i8] poison",
},
{
- "i8 undef",
+ "i8 poison",
"[5 x [0 x i8]] zeroinitializer",
},
{
- "i8 undef",
- "[5 x [0 x i8]] undef",
+ "i8 poison",
+ "[5 x [0 x i8]] poison",
},
{
"i8 0",
"[6 x i8] zeroinitializer",
},
{
- "i8 undef",
- "[6 x i8] undef",
+ "i8 poison",
+ "[6 x i8] poison",
},
{
"i8 1",
@@ -2910,15 +2910,15 @@ const std::pair<const char *, const char *> IsBytewiseValueTests[] = {
},
{
"i8 1",
- "[4 x i8] [i8 1, i8 undef, i8 1, i8 1]",
+ "[4 x i8] [i8 1, i8 poison, i8 1, i8 1]",
},
{
"i8 0",
"<6 x i8> zeroinitializer",
},
{
- "i8 undef",
- "<6 x i8> undef",
+ "i8 poison",
+ "<6 x i8> poison",
},
{
"i8 1",
@@ -2938,15 +2938,15 @@ const std::pair<const char *, const char *> IsBytewiseValueTests[] = {
},
{
"i8 5",
- "<2 x i8> < i8 5, i8 undef >",
+ "<2 x i8> < i8 5, i8 poison >",
},
{
"i8 0",
"[2 x [2 x i16]] zeroinitializer",
},
{
- "i8 undef",
- "[2 x [2 x i16]] undef",
+ "i8 poison",
+ "[2 x [2 x i16]] poison",
},
{
"i8 -86",
@@ -2959,28 +2959,28 @@ const std::pair<const char *, const char *> IsBytewiseValueTests[] = {
"[2 x i16] [i16 -21836, i16 -21846]]",
},
{
- "i8 undef",
+ "i8 poison",
"{ } zeroinitializer",
},
{
- "i8 undef",
- "{ } undef",
+ "i8 poison",
+ "{ } poison",
},
{
- "i8 undef",
+ "i8 poison",
"{ {}, {} } zeroinitializer",
},
{
- "i8 undef",
- "{ {}, {} } undef",
+ "i8 poison",
+ "{ {}, {} } poison",
},
{
"i8 0",
"{i8, i64, ptr} zeroinitializer",
},
{
- "i8 undef",
- "{i8, i64, ptr} undef",
+ "i8 poison",
+ "{i8, i64, ptr} poison",
},
{
"i8 -86",
More information about the llvm-commits
mailing list