[llvm] [SCEV] Skip invalidation with empty ValueExprMap (NFC). (PR #226845)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 27 15:24:48 PDT 2026


https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/226845

forgetLoop, forgetValue and forgetValues walk the def-use chains from the forgotten instructions and erase each visited value's SCEV. This can be expensive.

If ValueExprMap is empty, there's nothing to forget and skipping the walk reduces compile-time a bit:
stage1-O3: -0.05%
stage1-ReleaseThinLTO: -0.05%
stage1-ReleaseLTO-g: -0.03%
stage1-aarch64-O3: -0.04%
stage2-O3: -0.05%
stage2-clang: -0.01%

https://llvm-compile-time-tracker.com/compare.php?from=899d817c7950c997402cd229935cd822acf45b08&to=c43f92b9840b62f75ab8a45b7379188d78d81135&stat=instructions:u

>From d1c1ebe5c4b15d193462bad37ba777db15cecf37 Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Sat, 26 Sep 2026 07:15:46 +0100
Subject: [PATCH] [SCEV] Skip invalidation with empty ValueExprMap (NFC).

forgetLoop, forgetValue and forgetValues walk the def-use chains from the
forgotten instructions and erase each visited value's SCEV. This can be
expensive.

If ValueExprMap is empty, there's nothing to forget and skipping the
walk reduces compile-time a bit:
stage1-O3: -0.05%
stage1-ReleaseThinLTO: -0.05%
stage1-ReleaseLTO-g: -0.03%
stage1-aarch64-O3: -0.04%
stage2-O3: -0.05%
stage2-clang: -0.01%

https://llvm-compile-time-tracker.com/compare.php?from=899d817c7950c997402cd229935cd822acf45b08&to=c43f92b9840b62f75ab8a45b7379188d78d81135&stat=instructions:u
---
 llvm/lib/Analysis/ScalarEvolution.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index c5e1af4bf060f..ed505389a18dc 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -8655,6 +8655,11 @@ void ScalarEvolution::visitAndClearUsers(
     SmallVectorImpl<Instruction *> &Worklist,
     SmallPtrSetImpl<Instruction *> &Visited,
     SmallVectorImpl<SCEVUse> &ToForget) {
+  // Nothing can be invalidated if no value has a SCEV yet.
+  if (ValueExprMap.empty()) {
+    Worklist.clear();
+    return;
+  }
   while (!Worklist.empty()) {
     Instruction *I = Worklist.pop_back_val();
     if (!isSCEVable(I->getType()) && !isa<WithOverflowInst>(I))



More information about the llvm-commits mailing list