[all-commits] [llvm/llvm-project] 85334b: [NFCI][SCEV] Avoid recursion in SCEVExpander::isHi...

Roman Lebedev via All-commits all-commits at lists.llvm.org
Wed Mar 18 07:14:13 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 85334b030a6e601bd755a3c0e06ac4bdb9d36c85
      https://github.com/llvm/llvm-project/commit/85334b030a6e601bd755a3c0e06ac4bdb9d36c85
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-03-18 (Wed, 18 Mar 2020)

  Changed paths:
    M llvm/include/llvm/Analysis/ScalarEvolutionExpander.h
    M llvm/lib/Analysis/ScalarEvolutionExpander.cpp

  Log Message:
  -----------
  [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




More information about the All-commits mailing list