[llvm] Limit Number of Values used for SCEV Calculation (PR #140565)

Manish Kausik H via llvm-commits llvm-commits at lists.llvm.org
Tue May 20 08:48:26 PDT 2025


Nirhar wrote:

> So anything that was calculated is permanently "unknown", which is likely to confuse future calculations.

Hmm, I get your point.

Another alternative that I can think of, is to decouple discovery of "Values" needed to calculate SCEV from its actual calculation. Here is pseudocode on how getSCEV can probably be implemented:

```cpp
SCEV * getSCEV(Value *V) {
  queue<Value *> DependentValues;
  // Fill DependentValues with all Values that calculation of SCEV for V depends on, with leaf Values first.
  // fillDependentValues can implement the recursion, and here we can bail out if this involves too many Values.
  bool TooManyValues = fillDependentValues(V, DependentValues)
  if (TooManyValues)
    return getUnknown(V);
  
  for (auto I: DependentValues)
    // Calculate SCEV for I and cache it.

  return SCEVCache[V];
}
```
I think this would be considerable refactor of SCEV. @nikic @efriedma-quic let me know if this sounds like a good idea

https://github.com/llvm/llvm-project/pull/140565


More information about the llvm-commits mailing list