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

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 14 03:04:46 PST 2024


david-arm wrote:

> > Possibly using pre-computed guards in howManyLessThans would help, though I'm not sure (the existing guard uses are conditional).
> 
> Or going one level higher, we could pre-compute the guards for all exit count calculation for a given loop, which would be beneficial for multi-exit loops. Possibly this needs to be lazy though for the cases where we don't need the guards at all.

I see that `getSmallConstantTripMultiple` applies the loop guards after calculating the exit count, i.e.

```
unsigned ScalarEvolution::getSmallConstantTripMultiple(const Loop *L,
                                                       const SCEV *ExitCount) {
  if (ExitCount == getCouldNotCompute())
    return 1;

  // Get the trip count
  const SCEV *TCExpr = getTripCountFromExitCount(applyLoopGuards(ExitCount, L));

...
}
```

and perhaps this function is used less in the code base so the additional compile time cost is minimal? 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.

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


More information about the llvm-commits mailing list