aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Analysis/ValueTrackingTest.cpp
diff options
context:
space:
mode:
authorJuneyoung Lee <aqjune@gmail.com>2021-04-01 02:01:17 +0900
committerJuneyoung Lee <aqjune@gmail.com>2021-04-01 02:41:38 +0900
commitdf0b97dab08abb8605533974f6b977c183f6be37 (patch)
treedab7c8df854d92efbf38427cf922258a668e4b8c /llvm/unittests/Analysis/ValueTrackingTest.cpp
parentae7b1e8823a51068cfa64875fc5222e5b1d16760 (diff)
downloadllvm-df0b97dab08abb8605533974f6b977c183f6be37.zip
llvm-df0b97dab08abb8605533974f6b977c183f6be37.tar.gz
llvm-df0b97dab08abb8605533974f6b977c183f6be37.tar.bz2
[ValueTracking] Add with.overflow intrinsics to poison analysis functions
This is a patch teaching ValueTracking that `s/u*.with.overflow` intrinsics do not create undef/poison and they propagate poison. I couldn't write a nice example like the one with ctpop; ValueTrackingTest.cpp were simply updated to check these instead. This patch helps reducing regression while fixing https://llvm.org/pr49688 . Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D99671
Diffstat (limited to 'llvm/unittests/Analysis/ValueTrackingTest.cpp')
-rw-r--r--llvm/unittests/Analysis/ValueTrackingTest.cpp41
1 files changed, 36 insertions, 5 deletions
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 18fb154..93bb263 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -805,9 +805,16 @@ TEST_F(ValueTrackingTest, ComputeNumSignBits_Shuffle_Pointers) {
}
TEST(ValueTracking, propagatesPoison) {
- std::string AsmHead = "declare i32 @g(i32)\n"
- "define void @f(i32 %x, i32 %y, float %fx, float %fy, "
- "i1 %cond, i8* %p) {\n";
+ std::string AsmHead =
+ "declare i32 @g(i32)\n"
+ "declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)\n"
+ "declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)\n"
+ "declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)\n"
+ "declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)\n"
+ "declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)\n"
+ "declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)\n"
+ "define void @f(i32 %x, i32 %y, float %fx, float %fy, "
+ "i1 %cond, i8* %p) {\n";
std::string AsmTail = " ret void\n}";
// (propagates poison?, IR instruction)
SmallVector<std::pair<bool, std::string>, 32> Data = {
@@ -826,7 +833,13 @@ TEST(ValueTracking, propagatesPoison) {
{true, "urem i32 %x, %y"},
{true, "sdiv exact i32 %x, %y"},
{true, "srem i32 %x, %y"},
- {false, "call i32 @g(i32 %x)"}};
+ {false, "call i32 @g(i32 %x)"},
+ {true, "call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %x, i32 %y)"},
+ {true, "call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %x, i32 %y)"},
+ {true, "call {i32, i1} @llvm.smul.with.overflow.i32(i32 %x, i32 %y)"},
+ {true, "call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %x, i32 %y)"},
+ {true, "call {i32, i1} @llvm.usub.with.overflow.i32(i32 %x, i32 %y)"},
+ {true, "call {i32, i1} @llvm.umul.with.overflow.i32(i32 %x, i32 %y)"}};
std::string AssemblyStr = AsmHead;
for (auto &Itm : Data)
@@ -992,6 +1005,12 @@ TEST(ValueTracking, canCreatePoisonOrUndef) {
std::string AsmHead =
"@s = external dso_local global i32, align 1\n"
"declare i32 @g(i32)\n"
+ "declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)\n"
+ "declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)\n"
+ "declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)\n"
+ "declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)\n"
+ "declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)\n"
+ "declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)\n"
"define void @f(i32 %x, i32 %y, float %fx, float %fy, i1 %cond, "
"<4 x i32> %vx, <4 x i32> %vx2, <vscale x 4 x i32> %svx, i8* %p) {\n";
std::string AsmTail = " ret void\n}";
@@ -1053,7 +1072,19 @@ TEST(ValueTracking, canCreatePoisonOrUndef) {
{{true, false},
"ashr <4 x i32> %vx, select (i1 icmp sgt (i32 ptrtoint (i32* @s to "
"i32), i32 1), <4 x i32> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 "
- "2, i32 3>)"}};
+ "2, i32 3>)"},
+ {{false, false},
+ "call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %x, i32 %y)"},
+ {{false, false},
+ "call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %x, i32 %y)"},
+ {{false, false},
+ "call {i32, i1} @llvm.smul.with.overflow.i32(i32 %x, i32 %y)"},
+ {{false, false},
+ "call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %x, i32 %y)"},
+ {{false, false},
+ "call {i32, i1} @llvm.usub.with.overflow.i32(i32 %x, i32 %y)"},
+ {{false, false},
+ "call {i32, i1} @llvm.umul.with.overflow.i32(i32 %x, i32 %y)"}};
std::string AssemblyStr = AsmHead;
for (auto &Itm : Data)