Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7678,6 +7678,7 @@ static bool isGuaranteedNotToBeUndefOrPoison(
return true;
}

Value *Splat;
if (!::canCreateUndefOrPoison(Opr, Kind,
/*ConsiderFlagsAndMetadata=*/true)) {
if (const auto *PN = dyn_cast<PHINode>(V)) {
Expand All @@ -7695,6 +7696,10 @@ static bool isGuaranteedNotToBeUndefOrPoison(
}
if (IsWellDefined)
return true;
} else if (isa<ShuffleVectorInst>(Opr) && (Splat = getSplatValue(Opr))) {
// For splats we only need to check the value being splatted.
if (OpCheck(Splat))
return true;
} else if (all_of(Opr->operands(), OpCheck))
return true;
}
Expand Down
10 changes: 10 additions & 0 deletions llvm/unittests/Analysis/ValueTrackingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,16 @@ TEST_F(ValueTrackingTest, isGuaranteedNotToBeUndefOrPoison) {
}
}

TEST_F(ValueTrackingTest, isGuaranteedNotToBeUndefOrPoison_splat) {
parseAssembly(
"define <4 x i32> @test(i32 noundef %x) {\n"
" %ins = insertelement <4 x i32> poison, i32 %x, i32 0\n"
" %A = shufflevector <4 x i32> %ins, <4 x i32> poison, <4 x i32> zeroinitializer\n"
" ret <4 x i32> %A\n"
"}");
EXPECT_TRUE(isGuaranteedNotToBeUndefOrPoison(A));
}

TEST_F(ValueTrackingTest, isGuaranteedNotToBeUndefOrPoison_assume) {
parseAssembly("declare i1 @f_i1()\n"
"declare i32 @f_i32()\n"
Expand Down
Loading