[llvm] [DFAJumpThreading] Add an early exit heuristic for unpredictable values (PR #85015)

via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 16 08:07:11 PDT 2024


XChy wrote:

> > I believe there is much space for reducing the compile-time in `AllSwitchPaths::paths`, which enumerates the paths from switch and limit the max path length to 20. If there are all conditional jumps from switch, the run time of this function can be O(n ^ 20). I will investigate into it in my free time. Hope I can improve it.
> 
> Hm, this sounds very concerning. The commonality of this patch and #85360 and #85505 is that they all just add early exits -- this is fine to reduce average impact, but it doesn't really do anything to handle degenerate cases. There will be inputs that pass them, and for them the pass will unacceptably slow (complexity n^20 is the same as an infinite loop, really). So this pass really needs more that just early exits, it needs either a different approach, or tight limits (complexity n^20 does not matter if you require n^20 < 100...)

It my blame that I don't explain it well, this function is just an unconditional DFS from switch(and every BB can be visited at most twice).
The `n` is the number of successors of every branch. If the CFG is a complete binary tree and the height is greater than 20. That could be a search for 2^20 times. But actually, that's theoretical, it's impossible for a real-world CFG to be so big.
What concerns me is that this function may look into unnecessary BBs and collect unnecessary paths (it also make threadable path big). I think restricting the path searching to a relatively small scale (like in only a loop) is good.

https://github.com/llvm/llvm-project/pull/85015


More information about the llvm-commits mailing list