[PATCH] D147117: [SCEV] When computing trip count, only zext if necessary

Joshua Cao via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 1 01:07:21 PDT 2023


caojoshua added inline comments.


================
Comment at: llvm/lib/Analysis/LoopCacheAnalysis.cpp:337
   if (auto ConstantCost = dyn_cast<SCEVConstant>(RefCost))
-    return ConstantCost->getValue()->getSExtValue();
+    return ConstantCost->getValue()->getZExtValue();
 
----------------
nikic wrote:
> caojoshua wrote:
> > nikic wrote:
> > > The changes to LoopCacheAnalysis should be split out into a separate patch. I'm also wondering why this changes some but not all of the AnyExtends...
> > The places where I changed sext->zext are SCEVs that are computed from TripCount. In this case, RefCost is set to TripCount in the else block above.
> > 
> > I thought it made sense to have a single patch for these two changes. It would be harder to motivate the changes if I only submitted a patch for LoopCacheAnalysis. And the whole patch is small overall, so its not hard to read.
> But aren't the two AnyExtends in the `else` block above also on trip counts?
You're right. I think its just lack of test coverage in LoopCacheAnalysis / LoopInterchange, and that we should be using `zext` in those cases.

These cases don't come up very often. It's specifically when `BackedgeTakenCount = false`, or when there is a dead loop. The code we are talking about only applies when there are >=3 subscripts, and there probably just is not a test for it yet.

When I get the chance, I'll see if I can create a breaking test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147117



More information about the llvm-commits mailing list