[llvm] 337c8b1 - [SCEV] Add additional computeConstantDifference() tests (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 5 07:49:17 PDT 2024
Author: Nikita Popov
Date: 2024-08-05T16:49:09+02:00
New Revision: 337c8b1a4f88bdb58ba17712e05307cc2532dc00
URL: https://github.com/llvm/llvm-project/commit/337c8b1a4f88bdb58ba17712e05307cc2532dc00
DIFF: https://github.com/llvm/llvm-project/commit/337c8b1a4f88bdb58ba17712e05307cc2532dc00.diff
LOG: [SCEV] Add additional computeConstantDifference() tests (NFC)
And some tweaks to make this test easier to update. Use raw
string literals and print parse and verifier errors.
Added:
Modified:
llvm/unittests/Analysis/ScalarEvolutionTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
index 5e20e43478011..64a7503d30eed 100644
--- a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
+++ b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
@@ -1117,28 +1117,40 @@ TEST_F(ScalarEvolutionsTest, SCEVComputeConstantDifference) {
LLVMContext C;
SMDiagnostic Err;
std::unique_ptr<Module> M = parseAssemblyString(
- "define void @foo(i32 %sz, i32 %pp, i32 %x) { "
- "entry: "
- " %v0 = add i32 %pp, 0 "
- " %v3 = add i32 %pp, 3 "
- " %vx = add i32 %pp, %x "
- " %vx3 = add i32 %vx, 3 "
- " br label %loop.body "
- "loop.body: "
- " %iv = phi i32 [ %iv.next, %loop.body ], [ 0, %entry ] "
- " %xa = add nsw i32 %iv, %v0 "
- " %yy = add nsw i32 %iv, %v3 "
- " %xb = sub nsw i32 %yy, 3 "
- " %iv.next = add nsw i32 %iv, 1 "
- " %cmp = icmp sle i32 %iv.next, %sz "
- " br i1 %cmp, label %loop.body, label %exit "
- "exit: "
- " ret void "
- "} ",
+ R"(define void @foo(ptr %ptr, i32 %sz, i32 %pp, i32 %x) {
+ entry:
+ %v0 = add i32 %pp, 0
+ %v3 = add i32 %pp, 3
+ %vx = add i32 %pp, %x
+ %vx3 = add i32 %vx, 3
+ br label %loop.body
+ loop.body:
+ %iv = phi i32 [ %iv.next, %loop.body ], [ 0, %entry ]
+ %xa = add nsw i32 %iv, %v0
+ %yy = add nsw i32 %iv, %v3
+ %xb = sub nsw i32 %yy, 3
+ %iv.next = add nsw i32 %iv, 1
+ %cmp = icmp sle i32 %iv.next, %sz
+ br i1 %cmp, label %loop.body, label %loop2.body
+ loop2.body:
+ %iv2 = phi i32 [ %iv2.next, %loop2.body ], [ %iv, %loop.body ]
+ %iv2.next = add nsw i32 %iv2, 1
+ %iv2p3 = add i32 %iv2, 3
+ %var = load i32, ptr %ptr
+ %iv2pvar = add i32 %iv2, %var
+ %iv2pvarp3 = add i32 %iv2pvar, 3
+ %cmp2 = icmp sle i32 %iv2.next, %sz
+ br i1 %cmp2, label %loop2.body, label %exit
+ exit:
+ ret void
+ })",
Err, C);
- ASSERT_TRUE(M && "Could not parse module?");
- ASSERT_TRUE(!verifyModule(*M) && "Must have been well formed!");
+ if (!M) {
+ Err.print("ScalarEvolutionTest", errs());
+ ASSERT_TRUE(M && "Could not parse module?");
+ }
+ ASSERT_TRUE(!verifyModule(*M, &errs()) && "Must have been well formed!");
runWithSE(*M, "foo", [](Function &F, LoopInfo &LI, ScalarEvolution &SE) {
const SCEV *ScevV0 = SE.getSCEV(getInstructionByName(F, "v0")); // %pp
@@ -1154,6 +1166,15 @@ TEST_F(ScalarEvolutionsTest, SCEVComputeConstantDifference) {
const SCEV *ScevXB = SE.getSCEV(getInstructionByName(F, "xb")); // {%pp,+,1}
const SCEV *ScevIVNext =
SE.getSCEV(getInstructionByName(F, "iv.next")); // {1,+,1}
+ // {{0,+,1},+,1}
+ const SCEV *ScevIV2 = SE.getSCEV(getInstructionByName(F, "iv2"));
+ // {{3,+,1},+,1}
+ const SCEV *ScevIV2P3 = SE.getSCEV(getInstructionByName(F, "iv2p3"));
+ // %var + {{0,+,1},+,1}
+ const SCEV *ScevIV2PVar = SE.getSCEV(getInstructionByName(F, "iv2pvar"));
+ // %var + {{3,+,1},+,1}
+ const SCEV *ScevIV2PVarP3 =
+ SE.getSCEV(getInstructionByName(F, "iv2pvarp3"));
auto
diff = [&SE](const SCEV *LHS, const SCEV *RHS) -> std::optional<int> {
auto ConstantDiffOrNone = computeConstantDifference(SE, LHS, RHS);
@@ -1178,6 +1199,8 @@ TEST_F(ScalarEvolutionsTest, SCEVComputeConstantDifference) {
EXPECT_EQ(
diff (ScevIV, ScevIVNext), -1);
EXPECT_EQ(
diff (ScevIVNext, ScevIV), 1);
EXPECT_EQ(
diff (ScevIVNext, ScevIVNext), 0);
+ EXPECT_EQ(
diff (ScevIV2P3, ScevIV2), std::nullopt); // TODO
+ EXPECT_EQ(
diff (ScevIV2PVar, ScevIV2PVarP3), std::nullopt); // TODO
EXPECT_EQ(
diff (ScevV0, ScevIV), std::nullopt);
EXPECT_EQ(
diff (ScevIVNext, ScevV3), std::nullopt);
EXPECT_EQ(
diff (ScevYY, ScevV3), std::nullopt);
More information about the llvm-commits
mailing list