Skip to content

Commit ed8c894

Browse files
committed
[ValueTracking] Don't convert poison to undef
1 parent 18069a2 commit ed8c894

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6187,14 +6187,14 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) {
61876187

61886188
LLVMContext &Ctx = V->getContext();
61896189

6190-
// Poison don't care.
6191-
auto *PoisonInt8 = PoisonValue::get(Type::getInt8Ty(Ctx));
6190+
// Undef don't care.
6191+
auto *UndefInt8 = UndefValue::get(Type::getInt8Ty(Ctx));
61926192
if (isa<UndefValue>(V))
6193-
return PoisonInt8;
6193+
return UndefInt8;
61946194

61956195
// Return poison for zero-sized type.
61966196
if (DL.getTypeStoreSize(V->getType()).isZero())
6197-
return PoisonInt8;
6197+
return PoisonValue::get(Type::getInt8Ty(Ctx));
61986198

61996199
Constant *C = dyn_cast<Constant>(V);
62006200
if (!C) {
@@ -6252,23 +6252,23 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) {
62526252
return LHS;
62536253
if (!LHS || !RHS)
62546254
return nullptr;
6255-
if (LHS == PoisonInt8)
6255+
if (LHS == UndefInt8)
62566256
return RHS;
6257-
if (RHS == PoisonInt8)
6257+
if (RHS == UndefInt8)
62586258
return LHS;
62596259
return nullptr;
62606260
};
62616261

62626262
if (ConstantDataSequential *CA = dyn_cast<ConstantDataSequential>(C)) {
6263-
Value *Val = PoisonInt8;
6263+
Value *Val = UndefInt8;
62646264
for (unsigned I = 0, E = CA->getNumElements(); I != E; ++I)
62656265
if (!(Val = Merge(Val, isBytewiseValue(CA->getElementAsConstant(I), DL))))
62666266
return nullptr;
62676267
return Val;
62686268
}
62696269

62706270
if (isa<ConstantAggregate>(C)) {
6271-
Value *Val = PoisonInt8;
6271+
Value *Val = UndefInt8;
62726272
for (Value *Op : C->operands())
62736273
if (!(Val = Merge(Val, isBytewiseValue(Op, DL))))
62746274
return nullptr;

llvm/test/Transforms/MemCpyOpt/fca2memcpy.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ define void @addrproducer(ptr %src, ptr %dst) {
8181
; CHECK-LABEL: @addrproducer(
8282
; CHECK-NEXT: [[DST2:%.*]] = getelementptr [[S:%.*]], ptr [[DST]], i64 1
8383
; CHECK-NEXT: call void @llvm.memmove.p0.p0.i64(ptr align 8 [[DST2]], ptr align 8 [[SRC:%.*]], i64 16, i1 false)
84-
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 8 [[DST:%.*]], i8 poison, i64 16, i1 false)
84+
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 8 [[DST:%.*]], i8 undef, i64 16, i1 false)
8585
; CHECK-NEXT: ret void
8686
;
8787
%1 = load %S, ptr %src
@@ -94,7 +94,7 @@ define void @addrproducer(ptr %src, ptr %dst) {
9494
define void @aliasaddrproducer(ptr %src, ptr %dst, ptr %dstidptr) {
9595
; CHECK-LABEL: @aliasaddrproducer(
9696
; CHECK-NEXT: [[TMP1:%.*]] = load [[S:%.*]], ptr [[SRC:%.*]], align 8
97-
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 8 [[DST:%.*]], i8 poison, i64 16, i1 false)
97+
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 8 [[DST:%.*]], i8 undef, i64 16, i1 false)
9898
; CHECK-NEXT: [[DSTINDEX:%.*]] = load i32, ptr [[DSTIDPTR:%.*]], align 4
9999
; CHECK-NEXT: [[DST2:%.*]] = getelementptr [[S]], ptr [[DST]], i32 [[DSTINDEX]]
100100
; CHECK-NEXT: store [[S]] [[TMP1]], ptr [[DST2]], align 8
@@ -114,7 +114,7 @@ define void @noaliasaddrproducer(ptr %src, ptr noalias %dst, ptr noalias %dstidp
114114
; CHECK-NEXT: [[DSTINDEX:%.*]] = or i32 [[TMP2]], 1
115115
; CHECK-NEXT: [[DST2:%.*]] = getelementptr [[S:%.*]], ptr [[DST:%.*]], i32 [[DSTINDEX]]
116116
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[DST2]], ptr align 8 [[SRC]], i64 16, i1 false)
117-
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 8 [[SRC:%.*]], i8 poison, i64 16, i1 false)
117+
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 8 [[SRC:%.*]], i8 undef, i64 16, i1 false)
118118
; CHECK-NEXT: ret void
119119
;
120120
%1 = load %S, ptr %src

llvm/test/Transforms/MemCpyOpt/memcpy-to-memset.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ declare void @llvm.memcpy.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1) nounw
77
define void @test_undef() nounwind {
88
; CHECK-LABEL: @test_undef(
99
; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
10-
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[A]], i8 poison, i64 4, i1 false)
10+
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[A]], i8 undef, i64 4, i1 false)
1111
; CHECK-NEXT: ret void
1212
;
1313
%a = alloca i32, align 4

llvm/unittests/Analysis/ValueTrackingTest.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2769,8 +2769,8 @@ const std::pair<const char *, const char *> IsBytewiseValueTests[] = {
27692769
"ptr null",
27702770
},
27712771
{
2772-
"i8 poison",
2773-
"ptr poison",
2772+
"i8 undef",
2773+
"ptr undef",
27742774
},
27752775
{
27762776
"i8 0",
@@ -2789,8 +2789,8 @@ const std::pair<const char *, const char *> IsBytewiseValueTests[] = {
27892789
"i8 -1",
27902790
},
27912791
{
2792-
"i8 poison",
2793-
"i16 poison",
2792+
"i8 undef",
2793+
"i16 undef",
27942794
},
27952795
{
27962796
"i8 0",
@@ -2873,24 +2873,24 @@ const std::pair<const char *, const char *> IsBytewiseValueTests[] = {
28732873
"[0 x i8] zeroinitializer",
28742874
},
28752875
{
2876-
"i8 poison",
2877-
"[0 x i8] poison",
2876+
"i8 undef",
2877+
"[0 x i8] undef",
28782878
},
28792879
{
28802880
"i8 poison",
28812881
"[5 x [0 x i8]] zeroinitializer",
28822882
},
28832883
{
2884-
"i8 poison",
2885-
"[5 x [0 x i8]] poison",
2884+
"i8 undef",
2885+
"[5 x [0 x i8]] undef",
28862886
},
28872887
{
28882888
"i8 0",
28892889
"[6 x i8] zeroinitializer",
28902890
},
28912891
{
2892-
"i8 poison",
2893-
"[6 x i8] poison",
2892+
"i8 undef",
2893+
"[6 x i8] undef",
28942894
},
28952895
{
28962896
"i8 1",
@@ -2910,15 +2910,15 @@ const std::pair<const char *, const char *> IsBytewiseValueTests[] = {
29102910
},
29112911
{
29122912
"i8 1",
2913-
"[4 x i8] [i8 1, i8 poison, i8 1, i8 1]",
2913+
"[4 x i8] [i8 1, i8 undef, i8 1, i8 1]",
29142914
},
29152915
{
29162916
"i8 0",
29172917
"<6 x i8> zeroinitializer",
29182918
},
29192919
{
2920-
"i8 poison",
2921-
"<6 x i8> poison",
2920+
"i8 undef",
2921+
"<6 x i8> undef",
29222922
},
29232923
{
29242924
"i8 1",
@@ -2938,15 +2938,15 @@ const std::pair<const char *, const char *> IsBytewiseValueTests[] = {
29382938
},
29392939
{
29402940
"i8 5",
2941-
"<2 x i8> < i8 5, i8 poison >",
2941+
"<2 x i8> < i8 5, i8 undef >",
29422942
},
29432943
{
29442944
"i8 0",
29452945
"[2 x [2 x i16]] zeroinitializer",
29462946
},
29472947
{
2948-
"i8 poison",
2949-
"[2 x [2 x i16]] poison",
2948+
"i8 undef",
2949+
"[2 x [2 x i16]] undef",
29502950
},
29512951
{
29522952
"i8 -86",
@@ -2963,24 +2963,24 @@ const std::pair<const char *, const char *> IsBytewiseValueTests[] = {
29632963
"{ } zeroinitializer",
29642964
},
29652965
{
2966-
"i8 poison",
2967-
"{ } poison",
2966+
"i8 undef",
2967+
"{ } undef",
29682968
},
29692969
{
29702970
"i8 poison",
29712971
"{ {}, {} } zeroinitializer",
29722972
},
29732973
{
2974-
"i8 poison",
2975-
"{ {}, {} } poison",
2974+
"i8 undef",
2975+
"{ {}, {} } undef",
29762976
},
29772977
{
29782978
"i8 0",
29792979
"{i8, i64, ptr} zeroinitializer",
29802980
},
29812981
{
2982-
"i8 poison",
2983-
"{i8, i64, ptr} poison",
2982+
"i8 undef",
2983+
"{i8, i64, ptr} undef",
29842984
},
29852985
{
29862986
"i8 -86",

0 commit comments

Comments
 (0)