[llvm] [SCEV] Apply loop guards to End in computeMaxBECountForLT (PR #116187)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 19 03:48:55 PST 2024


lukel97 wrote:

I went through and updated the failed tests, this actually ends up reducing the max trip count in a lot more places than expected. 

> If we did something similar in `getSmallConstantTripCount` perhaps that might keep the compile time down? Not sure if applying the loop guards this late still gives us the benefits though.

I gave this a try but it doesn't seem to work, it looks we need to apply the guards before we call `get{Signed,Unigned}RangeMax` in order for `ConstantMaxBECount` to actually be reduced.

I've also noticed that a good few of the other calls to `get{Signed,Unigned}RangeMax` tend to wrap the SCEV with `applyLoopGuards`, e.g. in `howFarToZero`, so maybe this is kind of a pattern.

I'll continue poking around to see if there's anywhere else we can make this more efficient. My gut feeling is that hoisting the loop guard collection to `howManyLessThans` won't help given that the only other uses of `applyLoopGuards` there are mutually exclusive to `computeMaxBECountForLT`. 


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


More information about the llvm-commits mailing list