[NFCI][SCEV] Avoid recursion in SCEVExpander::isHighCostExpansion*()
Summary: As noted in [[ https://bugs.llvm.org/show_bug.cgi?id=45201 | PR45201 ]], [[ https://bugs.llvm.org/show_bug.cgi?id=10090 | PR10090 ]] SCEV doesn't always avoid recursive algorithms, and that causes issues with large expression depths and/or smaller stack sizes. In `SCEVExpander::isHighCostExpansion*()` case, the refactoring to avoid recursion is rather idiomatic. We simply need to place the root expr into a vector, and iterate over vector elements accounting for the cost of each one, adding new exprs at the end of the vector, thus achieving recursion-less traversal. The order in which we will visit exprs doesn't matter here, so we will be fine with the most basic approach of using SmallVector and inserting/extracting from the back, which accidentally is the same depth-first traversal that we were doing previously recursively. Reviewers: mkazantsev, reames, wmi, ekatz Reviewed By: mkazantsev Subscribers: hiraditya, javed.absar, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D76273
Loading
Please register or sign in to comment