[llvm] [SCEV] Avoid redundant stack push/pop in createSCEVIter (PR #199352)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 11 09:18:22 PDT 2026
https://github.com/daemonpilot updated https://github.com/llvm/llvm-project/pull/199352
>From f87c3daa0e3f38c612675d898ebc3449cdf14146 Mon Sep 17 00:00:00 2001
From: daemonpilot <daemonpilot at hotmail.com>
Date: Sat, 23 May 2026 22:09:43 +0800
Subject: [PATCH] [SCEV] Avoid redundant stack push/pop in createSCEVIter
---
llvm/lib/Analysis/ScalarEvolution.cpp | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index c93838ffdc50d..29f34392358bc 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -7729,14 +7729,15 @@ const SCEV *ScalarEvolution::createSCEVIter(Value *V) {
using PointerTy = PointerIntPair<Value *, 1, bool>;
SmallVector<PointerTy> Stack;
- Stack.emplace_back(V, true);
Stack.emplace_back(V, false);
while (!Stack.empty()) {
- auto E = Stack.pop_back_val();
+ auto E = Stack.back();
Value *CurV = E.getPointer();
- if (getExistingSCEV(CurV))
+ if (getExistingSCEV(CurV)) {
+ Stack.pop_back();
continue;
+ }
SmallVector<Value *> Ops;
const SCEV *CreatedSCEV = nullptr;
@@ -7752,10 +7753,10 @@ const SCEV *ScalarEvolution::createSCEVIter(Value *V) {
if (CreatedSCEV) {
insertValueToMap(CurV, CreatedSCEV);
+ Stack.pop_back();
} else {
- // Queue CurV for SCEV creation, followed by its's operands which need to
- // be constructed first.
- Stack.emplace_back(CurV, true);
+ Stack.back().setInt(true);
+ // Queue its operands which need to be constructed.
for (Value *Op : Ops)
Stack.emplace_back(Op, false);
}
More information about the llvm-commits
mailing list