[PATCH] D132076: [KnownBits] Limited recursion through phi operands

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 17 15:12:38 PDT 2022


reames created this revision.
reames added reviewers: RKSimon, nikic.
Herald added subscribers: foad, zzheng, bollu, hiraditya, mcrosier.
Herald added a project: All.
reames requested review of this revision.
Herald added a project: LLVM.

This change adjusts the phi handling in known-bits to allow recursing into phi operands, but adjusts the depth parameter to avoid potential exponential compile time growth.  Specifically, the remaining depth limit is even divided across the number of operands with the depth per operand adjusted upwards so that the total number of recursion steps is limited to the same value we'd perform on a tree of e.g. binary instructions.

This looks on the surface like it might allow a large degree of fan out, but it doesn't.  Some examples follow to help explain.

Term the difference between current depth and max depth as "budget".  Max depth currently defaults to 6.

Consider:

- A one operand phi increases depth by one.  This behaves just like any non-phi instruction.
- A two operand phi increases depth by half of budget.
- A three operand phi increases depth by two thirds of the remaining budget.
- Etc..

Put this together, and we can only recurse through at most two (non-single operand) phis.  The first phi splits the budget, and the second one splits it again.  For 2 operands, that means we'd divided budget by 4.  Since max budget is 6, that means we're down to per operand budget of 1 (required to preserve prior behavior), and won't recurse further.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132076

Files:
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/test/Analysis/ScalarEvolution/outer_phi.ll
  llvm/test/Transforms/InstCombine/known-phi-recurse.ll
  llvm/test/Transforms/LoopUnroll/runtime-unroll-remainder.ll
  llvm/test/Transforms/PhaseOrdering/X86/pr38280.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132076.453426.patch
Type: text/x-patch
Size: 6798 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220817/86f85d96/attachment.bin>


More information about the llvm-commits mailing list