[PATCH] D137505: [SCEV] Cache ZExt SCEV expressions.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 5 16:20:04 PDT 2022


fhahn created this revision.
fhahn added reviewers: efriedma, nikic, reames, mkazantsev.
Herald added subscribers: javed.absar, hiraditya.
Herald added a project: All.
fhahn requested review of this revision.
Herald added a project: LLVM.

When creating SCEV expressions for ZExt, there's quite a bit of
reasoning done and in many places the reasoning in turn will try to
create new SCEVs for other ZExts.

This can have a huge compile-time impact. The attached test from #58402
takes an excessive amount of compile time; without the patch, the test
doesn't complete in 1500+ seconds, but with the patch it completes in 1
second.

To speed up this case, cache created ZExt expressions for given (SCEV, Ty) pairs.
Caching just ZExts is relatively straight-forward, but it might make
sense to extend it to other expressions in the future.

This has a slight positive impact on CTMark:

- O3 <https://reviews.llvm.org/owners/package/3/>: -0.07%
- ReleaseThinLTO: -0.06%
- ReleaseLTO-g: -0.04%

https://llvm-compile-time-tracker.com/compare.php?from=1f034e207885d7edfa34b5408c7c872a966febcd&to=08d9e0f7966745fa300ac4a6c55692666daab68c&stat=instructions:u

The patch also improves compile-time for some internal real-world workloads
where time spent in SCEV goes from ~300 seconds to ~3 seconds.

There are a few cases where computing & caching the result earlier may
return more pessimistic results, but the compile-time savings seem to
outweigh that.

Fixes #58402.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137505

Files:
  llvm/include/llvm/Analysis/ScalarEvolution.h
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/test/Analysis/ScalarEvolution/pr58402-large-number-of-zext-exprs.ll
  llvm/test/Transforms/IndVarSimplify/AArch64/widen-loop-comp.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137505.473470.patch
Type: text/x-patch
Size: 24730 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221105/fc6d7ecf/attachment.bin>


More information about the llvm-commits mailing list