[PATCH] D83392: Strlen loop idiom recognition

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 27 12:44:17 PDT 2020


efriedma added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp:1657
+  // Find the 'sub' instruction that computes the strlen. First we need
+  // the base pointer to check the operands of the 'sub'.
+  auto *BasePtrSCEV = dyn_cast<SCEVUnknown>(SE->getPointerBase(LoadEv));
----------------
musman wrote:
> efriedma wrote:
> > I don't understand what you're doing here.
> > 
> > Probably the simplest thing to do here would be to directly expand LCSSAPHI based on the result of strlen, instead of trying to dig into the exit block and find a subtraction operation.
> I was thinking the subtraction operation was needed in order to do replaceAllUsesWith on it, is there a way to do that without needing the subtract?
> Also, to expand the LCSSAPHI would you take the incoming value and check if it's an AddRec, then expand that?
> Thanks again.
The actual output of the loop reflects the true count; you shouldn't need to dig through instructions outside it.  (We can simplify the subtraction, if there is one, as a separate transform.  I assume instcombine already handles this.)

To expand the LCSSAPHI, yes, you'd check if it's an appropriate addrec, then replace it with the sum of the addrec's base and the result of the strlen call.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83392/new/

https://reviews.llvm.org/D83392



More information about the llvm-commits mailing list