[llvm] 94adb39 - unittests: Use opaque pointers in a test
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 12 03:49:09 PDT 2023
Author: Matt Arsenault
Date: 2023-04-12T06:48:58-04:00
New Revision: 94adb39b85e069728ebdb6f31c76f98f4355f66b
URL: https://github.com/llvm/llvm-project/commit/94adb39b85e069728ebdb6f31c76f98f4355f66b
DIFF: https://github.com/llvm/llvm-project/commit/94adb39b85e069728ebdb6f31c76f98f4355f66b.diff
LOG: unittests: Use opaque pointers in a test
Added:
Modified:
llvm/unittests/Analysis/ValueTrackingTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 9e501bbc251f..55834a70fe6c 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -626,28 +626,28 @@ TEST_F(MatchSelectPatternTest, NotNotNe) {
TEST(ValueTracking, GuaranteedToTransferExecutionToSuccessor) {
StringRef Assembly =
- "declare void @nounwind_readonly(i32*) nounwind readonly "
- "declare void @nounwind_argmemonly(i32*) nounwind argmemonly "
- "declare void @nounwind_willreturn(i32*) nounwind willreturn "
- "declare void @throws_but_readonly(i32*) readonly "
- "declare void @throws_but_argmemonly(i32*) argmemonly "
- "declare void @throws_but_willreturn(i32*) willreturn "
+ "declare void @nounwind_readonly(ptr) nounwind readonly "
+ "declare void @nounwind_argmemonly(ptr) nounwind argmemonly "
+ "declare void @nounwind_willreturn(ptr) nounwind willreturn "
+ "declare void @throws_but_readonly(ptr) readonly "
+ "declare void @throws_but_argmemonly(ptr) argmemonly "
+ "declare void @throws_but_willreturn(ptr) willreturn "
" "
- "declare void @unknown(i32*) "
+ "declare void @unknown(ptr) "
" "
- "define void @f(i32* %p) { "
- " call void @nounwind_readonly(i32* %p) "
- " call void @nounwind_argmemonly(i32* %p) "
- " call void @nounwind_willreturn(i32* %p)"
- " call void @throws_but_readonly(i32* %p) "
- " call void @throws_but_argmemonly(i32* %p) "
- " call void @throws_but_willreturn(i32* %p) "
- " call void @unknown(i32* %p) nounwind readonly "
- " call void @unknown(i32* %p) nounwind argmemonly "
- " call void @unknown(i32* %p) nounwind willreturn "
- " call void @unknown(i32* %p) readonly "
- " call void @unknown(i32* %p) argmemonly "
- " call void @unknown(i32* %p) willreturn "
+ "define void @f(ptr %p) { "
+ " call void @nounwind_readonly(ptr %p) "
+ " call void @nounwind_argmemonly(ptr %p) "
+ " call void @nounwind_willreturn(ptr %p)"
+ " call void @throws_but_readonly(ptr %p) "
+ " call void @throws_but_argmemonly(ptr %p) "
+ " call void @throws_but_willreturn(ptr %p) "
+ " call void @unknown(ptr %p) nounwind readonly "
+ " call void @unknown(ptr %p) nounwind argmemonly "
+ " call void @unknown(ptr %p) nounwind willreturn "
+ " call void @unknown(ptr %p) readonly "
+ " call void @unknown(ptr %p) argmemonly "
+ " call void @unknown(ptr %p) willreturn "
" ret void "
"} ";
@@ -661,18 +661,18 @@ TEST(ValueTracking, GuaranteedToTransferExecutionToSuccessor) {
auto &BB = F->getEntryBlock();
bool ExpectedAnswers[] = {
- false, // call void @nounwind_readonly(i32* %p)
- false, // call void @nounwind_argmemonly(i32* %p)
- true, // call void @nounwind_willreturn(i32* %p)
- false, // call void @throws_but_readonly(i32* %p)
- false, // call void @throws_but_argmemonly(i32* %p)
- false, // call void @throws_but_willreturn(i32* %p)
- false, // call void @unknown(i32* %p) nounwind readonly
- false, // call void @unknown(i32* %p) nounwind argmemonly
- true, // call void @unknown(i32* %p) nounwind willreturn
- false, // call void @unknown(i32* %p) readonly
- false, // call void @unknown(i32* %p) argmemonly
- false, // call void @unknown(i32* %p) willreturn
+ false, // call void @nounwind_readonly(ptr %p)
+ false, // call void @nounwind_argmemonly(ptr %p)
+ true, // call void @nounwind_willreturn(ptr %p)
+ false, // call void @throws_but_readonly(ptr %p)
+ false, // call void @throws_but_argmemonly(ptr %p)
+ false, // call void @throws_but_willreturn(ptr %p)
+ false, // call void @unknown(ptr %p) nounwind readonly
+ false, // call void @unknown(ptr %p) nounwind argmemonly
+ true, // call void @unknown(ptr %p) nounwind willreturn
+ false, // call void @unknown(ptr %p) readonly
+ false, // call void @unknown(ptr %p) argmemonly
+ false, // call void @unknown(ptr %p) willreturn
false, // ret void
};
@@ -811,9 +811,9 @@ TEST_F(ValueTrackingTest, impliesPoisonTest_MaskCmp) {
TEST_F(ValueTrackingTest, ComputeNumSignBits_Shuffle_Pointers) {
parseAssembly(
- "define <2 x i32*> @test(<2 x i32*> %x) {\n"
- " %A = shufflevector <2 x i32*> zeroinitializer, <2 x i32*> undef, <2 x i32> zeroinitializer\n"
- " ret <2 x i32*> %A\n"
+ "define <2 x ptr> @test(<2 x ptr> %x) {\n"
+ " %A = shufflevector <2 x ptr> zeroinitializer, <2 x ptr> undef, <2 x i32> zeroinitializer\n"
+ " ret <2 x ptr> %A\n"
"}\n");
EXPECT_EQ(ComputeNumSignBits(A, M->getDataLayout()), 64u);
}
@@ -857,7 +857,7 @@ TEST(ValueTracking, propagatesPoison) {
"declare i64 @llvm.llrint.f32(float)\n"
"declare float @llvm.fmuladd.f32(float, float, float)\n"
"define void @f(i32 %x, i32 %y, float %fx, float %fy, "
- "i1 %cond, i8* %p) {\n";
+ "i1 %cond, ptr %p) {\n";
std::string AsmTail = " ret void\n}";
// (propagates poison?, IR instruction)
SmallVector<std::tuple<bool, std::string, unsigned>, 32> Data = {
@@ -884,10 +884,10 @@ TEST(ValueTracking, propagatesPoison) {
{true, "fcmp oeq float %fx, %fy", 1},
{true, "icmp eq i32 %x, %y", 0},
{true, "icmp eq i32 %x, %y", 1},
- {true, "getelementptr i8, i8* %p, i32 %x", 0},
- {true, "getelementptr i8, i8* %p, i32 %x", 1},
- {true, "getelementptr inbounds i8, i8* %p, i32 %x", 0},
- {true, "getelementptr inbounds i8, i8* %p, i32 %x", 1},
+ {true, "getelementptr i8, ptr %p, i32 %x", 0},
+ {true, "getelementptr i8, ptr %p, i32 %x", 1},
+ {true, "getelementptr inbounds i8, ptr %p, i32 %x", 0},
+ {true, "getelementptr inbounds i8, ptr %p, i32 %x", 1},
{true, "bitcast float %fx to i32", 0},
{true, "select i1 %cond, i32 %x, i32 %y", 0},
{false, "select i1 %cond, i32 %x, i32 %y", 1},
@@ -1113,7 +1113,7 @@ TEST(ValueTracking, canCreatePoisonOrUndef) {
"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";
+ "<4 x i32> %vx, <4 x i32> %vx2, <vscale x 4 x i32> %svx, ptr %p) {\n";
std::string AsmTail = " ret void\n}";
// (can create poison?, can create undef?, IR instruction)
SmallVector<std::pair<std::pair<bool, bool>, std::string>, 32> Data = {
@@ -1138,8 +1138,8 @@ TEST(ValueTracking, canCreatePoisonOrUndef) {
{{true, false}, "lshr exact i32 %x, 31"},
{{false, false}, "udiv i32 %x, %y"},
{{true, false}, "udiv exact i32 %x, %y"},
- {{false, false}, "getelementptr i8, i8* %p, i32 %x"},
- {{true, false}, "getelementptr inbounds i8, i8* %p, i32 %x"},
+ {{false, false}, "getelementptr i8, ptr %p, i32 %x"},
+ {{true, false}, "getelementptr inbounds i8, ptr %p, i32 %x"},
{{true, false}, "fneg nnan float %fx"},
{{false, false}, "fneg float %fx"},
{{false, false}, "fadd float %fx, %fy"},
@@ -1170,7 +1170,7 @@ TEST(ValueTracking, canCreatePoisonOrUndef) {
{{false, false}, "call noundef i32 @g(i32 %x)"},
{{true, false}, "fcmp nnan oeq float %fx, %fy"},
{{false, false}, "fcmp oeq float %fx, %fy"},
- {{true, false}, "ashr i32 %x, ptrtoint (i32* @s to i32)"},
+ {{true, false}, "ashr i32 %x, ptrtoint (ptr @s to i32)"},
{{false, false},
"call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %x, i32 %y)"},
{{false, false},
@@ -1217,17 +1217,17 @@ TEST(ValueTracking, canCreatePoisonOrUndef) {
TEST_F(ValueTrackingTest, computePtrAlignment) {
parseAssembly("declare i1 @f_i1()\n"
- "declare i8* @f_i8p()\n"
+ "declare ptr @f_i8p()\n"
"declare void @llvm.assume(i1)\n"
"define void @test() {\n"
- " %A = call i8* @f_i8p()\n"
+ " %A = call ptr @f_i8p()\n"
" %cond = call i1 @f_i1()\n"
" %CxtI = add i32 0, 0\n"
" br i1 %cond, label %BB1, label %EXIT\n"
"BB1:\n"
" %CxtI2 = add i32 0, 0\n"
" %cond2 = call i1 @f_i1()\n"
- " call void @llvm.assume(i1 true) [ \"align\"(i8* %A, i64 16) ]\n"
+ " call void @llvm.assume(i1 true) [ \"align\"(ptr %A, i64 16) ]\n"
" br i1 %cond2, label %BB2, label %EXIT\n"
"BB2:\n"
" %CxtI3 = add i32 0, 0\n"
@@ -1598,11 +1598,11 @@ TEST_F(ValueTrackingTest, isNonZeroRecurrence) {
TEST_F(ValueTrackingTest, KnownNonZeroFromDomCond) {
parseAssembly(R"(
- declare i8* @f_i8()
+ declare ptr @f_i8()
define void @test(i1 %c) {
- %A = call i8* @f_i8()
- %B = call i8* @f_i8()
- %c1 = icmp ne i8* %A, null
+ %A = call ptr @f_i8()
+ %B = call ptr @f_i8()
+ %c1 = icmp ne ptr %A, null
%cond = and i1 %c1, %c
br i1 %cond, label %T, label %Q
T:
@@ -1622,11 +1622,11 @@ TEST_F(ValueTrackingTest, KnownNonZeroFromDomCond) {
TEST_F(ValueTrackingTest, KnownNonZeroFromDomCond2) {
parseAssembly(R"(
- declare i8* @f_i8()
+ declare ptr @f_i8()
define void @test(i1 %c) {
- %A = call i8* @f_i8()
- %B = call i8* @f_i8()
- %c1 = icmp ne i8* %A, null
+ %A = call ptr @f_i8()
+ %B = call ptr @f_i8()
+ %c1 = icmp ne ptr %A, null
%cond = select i1 %c, i1 %c1, i1 false
br i1 %cond, label %T, label %Q
T:
@@ -1736,8 +1736,8 @@ TEST_F(ComputeKnownBitsTest, KnownNonZeroShift) {
// %q is known nonzero without known bits.
// Because %q is nonzero, %A[0] is known to be zero.
parseAssembly(
- "define i8 @test(i8 %p, i8* %pq) {\n"
- " %q = load i8, i8* %pq, !range !0\n"
+ "define i8 @test(i8 %p, ptr %pq) {\n"
+ " %q = load i8, ptr %pq, !range !0\n"
" %A = shl i8 %p, %q\n"
" ret i8 %A\n"
"}\n"
@@ -1867,9 +1867,9 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownUSubSatZerosPreserved) {
TEST_F(ComputeKnownBitsTest, ComputeKnownBitsPtrToIntTrunc) {
// ptrtoint truncates the pointer type.
parseAssembly(
- "define void @test(i8** %p) {\n"
- " %A = load i8*, i8** %p\n"
- " %i = ptrtoint i8* %A to i32\n"
+ "define void @test(ptr %p) {\n"
+ " %A = load ptr, ptr %p\n"
+ " %i = ptrtoint ptr %A to i32\n"
" %m = and i32 %i, 31\n"
" %c = icmp eq i32 %m, 0\n"
" call void @llvm.assume(i1 %c)\n"
@@ -1886,9 +1886,9 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownBitsPtrToIntTrunc) {
TEST_F(ComputeKnownBitsTest, ComputeKnownBitsPtrToIntZext) {
// ptrtoint zero extends the pointer type.
parseAssembly(
- "define void @test(i8** %p) {\n"
- " %A = load i8*, i8** %p\n"
- " %i = ptrtoint i8* %A to i128\n"
+ "define void @test(ptr %p) {\n"
+ " %A = load ptr, ptr %p\n"
+ " %i = ptrtoint ptr %A to i128\n"
" %m = and i128 %i, 31\n"
" %c = icmp eq i128 %m, 0\n"
" call void @llvm.assume(i1 %c)\n"
@@ -1921,8 +1921,8 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownBitsFreeze) {
}
TEST_F(ComputeKnownBitsTest, ComputeKnownBitsAddWithRange) {
- parseAssembly("define void @test(i64* %p) {\n"
- " %A = load i64, i64* %p, !range !{i64 64, i64 65536}\n"
+ parseAssembly("define void @test(ptr %p) {\n"
+ " %A = load i64, ptr %p, !range !{i64 64, i64 65536}\n"
" %APlus512 = add i64 %A, 512\n"
" %c = icmp ugt i64 %APlus512, 523\n"
" call void @llvm.assume(i1 %c)\n"
@@ -1976,8 +1976,8 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownBitsUnknownVScale) {
// 512 + [32, 64) doesn't produce overlapping bits.
// Make sure we get all the individual bits properly.
TEST_F(ComputeKnownBitsTest, ComputeKnownBitsAddWithRangeNoOverlap) {
- parseAssembly("define void @test(i64* %p) {\n"
- " %A = load i64, i64* %p, !range !{i64 32, i64 64}\n"
+ parseAssembly("define void @test(ptr %p) {\n"
+ " %A = load i64, ptr %p, !range !{i64 32, i64 64}\n"
" %APlus512 = add i64 %A, 512\n"
" %c = icmp ugt i64 %APlus512, 523\n"
" call void @llvm.assume(i1 %c)\n"
@@ -2002,8 +2002,8 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownBitsAddWithRangeNoOverlap) {
TEST_F(ComputeKnownBitsTest, ComputeKnownBitsGEPWithRange) {
parseAssembly(
- "define void @test(i64* %p) {\n"
- " %A = load i64, i64* %p, !range !{i64 64, i64 65536}\n"
+ "define void @test(ptr %p) {\n"
+ " %A = load i64, ptr %p, !range !{i64 64, i64 65536}\n"
" %APtr = inttoptr i64 %A to float*"
" %APtrPlus512 = getelementptr float, float* %APtr, i32 128\n"
" %c = icmp ugt float* %APtrPlus512, inttoptr (i32 523 to float*)\n"
@@ -2035,8 +2035,8 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownBitsGEPWithRange) {
// in the gep. Indeed, gep float, [32,64), 128 is not 128 + [32,64).
TEST_F(ComputeKnownBitsTest, ComputeKnownBitsGEPWithRangeNoOverlap) {
parseAssembly(
- "define void @test(i64* %p) {\n"
- " %A = load i64, i64* %p, !range !{i64 32, i64 64}\n"
+ "define void @test(ptr %p) {\n"
+ " %A = load i64, ptr %p, !range !{i64 32, i64 64}\n"
" %APtr = inttoptr i64 %A to float*"
" %APtrPlus512 = getelementptr float, float* %APtr, i32 128\n"
" %c = icmp ugt float* %APtrPlus512, inttoptr (i32 523 to float*)\n"
@@ -2600,7 +2600,7 @@ const FindAllocaForValueTestParams FindAllocaForValueTests[] = {
{R"(
define void @test() {
%a = alloca i64
- %r = bitcast i64* %a to i32*
+ %r = bitcast ptr %a to ptr
ret void
})",
true, true},
@@ -2608,7 +2608,7 @@ const FindAllocaForValueTestParams FindAllocaForValueTests[] = {
{R"(
define void @test() {
%a = alloca i32
- %r = getelementptr i32, i32* %a, i32 1
+ %r = getelementptr i32, ptr %a, i32 1
ret void
})",
true, false},
@@ -2616,7 +2616,7 @@ const FindAllocaForValueTestParams FindAllocaForValueTests[] = {
{R"(
define void @test() {
%a = alloca i32
- %r = getelementptr i32, i32* %a, i32 0
+ %r = getelementptr i32, ptr %a, i32 0
ret void
})",
true, true},
@@ -2628,7 +2628,7 @@ const FindAllocaForValueTestParams FindAllocaForValueTests[] = {
br label %bb1
bb1:
- %r = phi i32* [ %a, %entry ], [ %r, %bb1 ]
+ %r = phi ptr [ %a, %entry ], [ %r, %bb1 ]
br i1 %cond, label %bb1, label %exit
exit:
@@ -2639,7 +2639,7 @@ const FindAllocaForValueTestParams FindAllocaForValueTests[] = {
{R"(
define void @test(i1 %cond) {
%a = alloca i32
- %r = select i1 %cond, i32* %a, i32* %a
+ %r = select i1 %cond, ptr %a, ptr %a
ret void
})",
true, true},
@@ -2648,7 +2648,7 @@ const FindAllocaForValueTestParams FindAllocaForValueTests[] = {
define void @test(i1 %cond) {
%a = alloca i32
%b = alloca i32
- %r = select i1 %cond, i32* %a, i32* %b
+ %r = select i1 %cond, ptr %a, ptr %b
ret void
})",
false, false},
@@ -2657,12 +2657,12 @@ const FindAllocaForValueTestParams FindAllocaForValueTests[] = {
define void @test(i1 %cond) {
entry:
%a = alloca i64
- %a32 = bitcast i64* %a to i32*
+ %a32 = bitcast ptr %a to ptr
br label %bb1
bb1:
- %x = phi i32* [ %a32, %entry ], [ %x, %bb1 ]
- %r = getelementptr i32, i32* %x, i32 1
+ %x = phi ptr [ %a32, %entry ], [ %x, %bb1 ]
+ %r = getelementptr i32, ptr %x, i32 1
br i1 %cond, label %bb1, label %exit
exit:
@@ -2674,12 +2674,12 @@ const FindAllocaForValueTestParams FindAllocaForValueTests[] = {
define void @test(i1 %cond) {
entry:
%a = alloca i64
- %a32 = bitcast i64* %a to i32*
+ %a32 = bitcast ptr %a to ptr
br label %bb1
bb1:
- %x = phi i32* [ %a32, %entry ], [ %r, %bb1 ]
- %r = getelementptr i32, i32* %x, i32 1
+ %x = phi ptr [ %a32, %entry ], [ %r, %bb1 ]
+ %r = getelementptr i32, ptr %x, i32 1
br i1 %cond, label %bb1, label %exit
exit:
@@ -2688,9 +2688,9 @@ const FindAllocaForValueTestParams FindAllocaForValueTests[] = {
true, false},
{R"(
- define void @test(i1 %cond, i64* %a) {
+ define void @test(i1 %cond, ptr %a) {
entry:
- %r = bitcast i64* %a to i32*
+ %r = bitcast ptr %a to ptr
ret void
})",
false, false},
@@ -2703,7 +2703,7 @@ const FindAllocaForValueTestParams FindAllocaForValueTests[] = {
br label %bb1
bb1:
- %r = phi i32* [ %a, %entry ], [ %b, %bb1 ]
+ %r = phi ptr [ %a, %entry ], [ %b, %bb1 ]
br i1 %cond, label %bb1, label %exit
exit:
@@ -2711,18 +2711,18 @@ const FindAllocaForValueTestParams FindAllocaForValueTests[] = {
})",
false, false},
{R"(
- declare i32* @retptr(i32* returned)
+ declare ptr @retptr(ptr returned)
define void @test(i1 %cond) {
%a = alloca i32
- %r = call i32* @retptr(i32* %a)
+ %r = call ptr @retptr(ptr %a)
ret void
})",
true, true},
{R"(
- declare i32* @fun(i32*)
+ declare ptr @fun(ptr)
define void @test(i1 %cond) {
%a = alloca i32
- %r = call i32* @fun(i32* %a)
+ %r = call ptr @fun(ptr %a)
ret void
})",
false, false},
More information about the llvm-commits
mailing list