[llvm] [SCEV] Add option to request use-specific SCEV for a GEP expr, (PR #190677)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 10 08:27:30 PDT 2026


================
@@ -4718,20 +4745,26 @@ void ScalarEvolution::insertValueToMap(Value *V, const SCEV *S) {
 
 /// Return an existing SCEV if it exists, otherwise analyze the expression and
 /// create a new one.
-const SCEV *ScalarEvolution::getSCEV(Value *V) {
+SCEVUse ScalarEvolution::getSCEV(Value *V, bool UseCtx) {
   assert(isSCEVable(V->getType()) && "Value is not SCEVable!");
 
-  if (const SCEV *S = getExistingSCEV(V))
+  if (SCEVUse S = getExistingSCEV(V)) {
+    // When not using context-specific flags, return the canonical SCEV
+    // without any use-specific flags.
+    if (!UseCtx)
----------------
fhahn wrote:

The intention here is to limit the initial scope; I think we would need to audit various users to make sure using a use-specific SCEV is actually correct.

Not sure if there's a nicer way? I updated to PR now to always create use-specific SCEVs (this removes the boolean arg on most functions), but return the canonical SCEV if the flag here is false. 

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


More information about the llvm-commits mailing list