[all-commits] [llvm/llvm-project] afe355: [SCEV] Cache ZExt SCEV expressions.

Florian Hahn via All-commits all-commits at lists.llvm.org
Fri Dec 9 14:14:31 PST 2022

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: afe3558a0b963f7401b044ed64187b5319288112
  Author: Florian Hahn <flo at fhahn.com>
  Date:   2022-12-09 (Fri, 09 Dec 2022)

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

  Log Message:
  [SCEV] Cache ZExt SCEV expressions.

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

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: -0.03%
* ReleaseThinLTO: -0.03%
* ReleaseLTO-g: 0.00%


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.

Reviewed By: mkazantsev

Differential Revision: https://reviews.llvm.org/D137505

More information about the All-commits mailing list