[SCEV] Iteratively compute ranges for deeply nested expressions.
authorFlorian Hahn <flo@fhahn.com>
Mon, 21 Nov 2022 21:56:14 +0000 (21:56 +0000)
committerFlorian Hahn <flo@fhahn.com>
Mon, 21 Nov 2022 21:56:14 +0000 (21:56 +0000)
commit5dad4c67882a5eac2485f722e8e4109642155058
treea7771c4228907566cf49278b5b7bcdec03b94a53
parente1e1cad6fd756b0af54e638e96f0a7a076d169db
[SCEV] Iteratively compute ranges for deeply nested expressions.

At the moment, getRangeRef may overflow the stack for very deeply nested
expressions.

This patch introduces a new getRangeRefIter function, which first builds
a worklist of N-ary expressions and phi nodes, followed by their
operands iteratively.

getRangeRef has been extended to also take a Depth argument and it
switches to use getRangeRefIter once the depth reaches a certain
threshold.

This ensures compile-time is not impacted in general. Note that
the iterative algorithm may lead to a slightly different evaluation
order, which could result in slightly worse ranges for cyclic phis.

https://llvm-compile-time-tracker.com/compare.php?from=23c3eb7cdf3478c9db86f6cb5115821a8f0f5f40&to=e0e09fa338e77e53242bfc846e1484350ad79773&stat=instructions

Fixes #49579.

Reviewed By: mkazantsev

Differential Revision: https://reviews.llvm.org/D130728
llvm/include/llvm/Analysis/ScalarEvolution.h
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/ranges.ll
llvm/test/Transforms/IndVarSimplify/range-iter-threshold.ll [new file with mode: 0644]