Skip to content

Commit c8cdc8c

Browse files
committed
[ValueTracking] Teach isGuaranteedNotToBeUndefOrPoison about splats
Splats include two poison values, but only the poison-ness of the splatted value actually matters.
1 parent 9b9eefa commit c8cdc8c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7678,6 +7678,7 @@ static bool isGuaranteedNotToBeUndefOrPoison(
76787678
return true;
76797679
}
76807680

7681+
Value *Splat;
76817682
if (!::canCreateUndefOrPoison(Opr, Kind,
76827683
/*ConsiderFlagsAndMetadata=*/true)) {
76837684
if (const auto *PN = dyn_cast<PHINode>(V)) {
@@ -7695,6 +7696,10 @@ static bool isGuaranteedNotToBeUndefOrPoison(
76957696
}
76967697
if (IsWellDefined)
76977698
return true;
7699+
} else if (isa<ShuffleVectorInst>(Opr) && (Splat = getSplatValue(Opr))) {
7700+
// For splats we only need to check the value being splatted.
7701+
if (OpCheck(Splat))
7702+
return true;
76987703
} else if (all_of(Opr->operands(), OpCheck))
76997704
return true;
77007705
}

llvm/unittests/Analysis/ValueTrackingTest.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,16 @@ TEST_F(ValueTrackingTest, isGuaranteedNotToBeUndefOrPoison) {
10911091
}
10921092
}
10931093

1094+
TEST_F(ValueTrackingTest, isGuaranteedNotToBeUndefOrPoison_splat) {
1095+
parseAssembly(
1096+
"define <4 x i32> @test(i32 noundef %x) {\n"
1097+
" %ins = insertelement <4 x i32> poison, i32 %x, i32 0\n"
1098+
" %A = shufflevector <4 x i32> %ins, <4 x i32> poison, <4 x i32> zeroinitializer\n"
1099+
" ret <4 x i32> %A\n"
1100+
"}");
1101+
EXPECT_TRUE(isGuaranteedNotToBeUndefOrPoison(A));
1102+
}
1103+
10941104
TEST_F(ValueTrackingTest, isGuaranteedNotToBeUndefOrPoison_assume) {
10951105
parseAssembly("declare i1 @f_i1()\n"
10961106
"declare i32 @f_i32()\n"

0 commit comments

Comments
 (0)