[llvm] [LAA] Rewrite findForkedPointer (NFCI) (PR #140298)

Graham Hunter via llvm-commits llvm-commits at lists.llvm.org
Tue May 20 06:38:57 PDT 2025


================
@@ -1088,29 +1092,49 @@ static void findForkedSCEVs(
   }
 }
 
-static SmallVector<PointerIntPair<const SCEV *, 1, bool>>
-findForkedPointer(PredicatedScalarEvolution &PSE,
-                  const DenseMap<Value *, const SCEV *> &StridesMap, Value *Ptr,
-                  const Loop *L) {
-  ScalarEvolution *SE = PSE.getSE();
-  assert(SE->isSCEVable(Ptr->getType()) && "Value is not SCEVable!");
-  SmallVector<PointerIntPair<const SCEV *, 1, bool>> Scevs;
-  findForkedSCEVs(SE, L, Ptr, Scevs, MaxForkedSCEVDepth);
-
-  // For now, we will only accept a forked pointer with two possible SCEVs
-  // that are either SCEVAddRecExprs or loop invariant.
-  if (Scevs.size() == 2 &&
----------------
huntergr-arm wrote:

Looking through the tests, there's at least 3 which could generate more than 2 SCEV values (`@forked_ptrs_with_different_base3`, `@forked_ptrs_two_forks_gep`, and `@forked_ptrs_two_select`). However, the checks in `findForkedSCEVs` reject all 3 and just return a single CouldNotCompute SCEV.

I think this was just a final sanity check to restrict to 2 SCEVs rather than code we could properly test, in case someone extended `findForkedSCEVs` to cover new instructions without upholding the restriction.

There's no hard requirement to limit to 2 SCEVs of course, I was just focused on the cases I had at the time.

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


More information about the llvm-commits mailing list