diff options
author | Johannes Reifferscheid <jreiffers@google.com> | 2024-07-30 14:27:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-30 14:27:37 +0200 |
commit | 65697b1c7cc9824d51f22f109c6a32428a7dd557 (patch) | |
tree | 1e50280af0e3c39fb0270a0d20596f778506ba91 /llvm/unittests/Analysis/ScalarEvolutionTest.cpp | |
parent | 41c0f89f5532ec110b927c3a67ceac83448c5d98 (diff) | |
download | llvm-65697b1c7cc9824d51f22f109c6a32428a7dd557.zip llvm-65697b1c7cc9824d51f22f109c6a32428a7dd557.tar.gz llvm-65697b1c7cc9824d51f22f109c6a32428a7dd557.tar.bz2 |
Remove value cache in SCEV comparator. (#100721)
The cache triggers almost never, and seems unlikely to help with
performance. However, when it does, it is likely to cause the comparator
to become inconsistent due to a bad interaction of the depth limit and
cache hits. This leads to crashes in debug builds. See the new unit test
for a reproducer.
Diffstat (limited to 'llvm/unittests/Analysis/ScalarEvolutionTest.cpp')
-rw-r--r-- | llvm/unittests/Analysis/ScalarEvolutionTest.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp index a6a5ffd..76e6095 100644 --- a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp +++ b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp @@ -1625,4 +1625,40 @@ TEST_F(ScalarEvolutionsTest, ForgetValueWithOverflowInst) { }); } +TEST_F(ScalarEvolutionsTest, ComplexityComparatorIsStrictWeakOrdering) { + // Regression test for a case where caching of equivalent values caused the + // comparator to get inconsistent. + LLVMContext C; + SMDiagnostic Err; + std::unique_ptr<Module> M = parseAssemblyString(R"( + define i32 @foo(i32 %arg0) { + %1 = add i32 %arg0, 1 + %2 = add i32 %arg0, 1 + %3 = xor i32 %2, %1 + %4 = add i32 %3, %2 + %5 = add i32 %arg0, 1 + %6 = xor i32 %5, %arg0 + %7 = add i32 %arg0, %6 + %8 = add i32 %5, %7 + %9 = xor i32 %8, %7 + %10 = add i32 %9, %8 + %11 = xor i32 %10, %9 + %12 = add i32 %11, %10 + %13 = xor i32 %12, %11 + %14 = add i32 %12, %13 + %15 = add i32 %14, %4 + ret i32 %15 + })", + Err, C); + + ASSERT_TRUE(M && "Could not parse module?"); + ASSERT_TRUE(!verifyModule(*M) && "Must have been well formed!"); + + runWithSE(*M, "foo", [](Function &F, LoopInfo &LI, ScalarEvolution &SE) { + // When _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG, this will + // crash if the comparator has the specific caching bug. + SE.getSCEV(F.getEntryBlock().getTerminator()->getOperand(0)); + }); +} + } // end namespace llvm |