[PATCH] D100573: [ValueTracking] don't recursively compute known bits using multiple llvm.assumes

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 15 11:16:28 PDT 2021


nikic added a comment.

In D100573#2692136 <https://reviews.llvm.org/D100573#2692136>, @lebedev.ri wrote:

> Note that we canonicalize `assume(x && y)` to `assume(x), assume(y)`, so we really ought to do better than just give up.

Not sure I see what relation that has to this issue. We still process all applicable assumes. We'll just not make use of even more assumes when doing recursive queries while already handling an assume.

Let me try to state the core problem here: ValueTracking walks are depth-limited. This is fine as long as the branching factor is low. At a typical branching factor <= 2, going to a depth of 6 has maximum complexity of 2^64, which is reasonable. However, we need to be careful whenever the branching factor is higher than that. For a factor b=3, complexity is already 3^6 = 729, which is beyond reasonable bounds. I believe there are only two cases where we can run into this issue: One is phi nodes, where the branching factor is the number of phi node arguments. The other are assumes, where the branching factor is the number of applicable assumes for a value.

In such cases, we need to apply *some* kind of limit to avoid pathological compile-time costs. What we do for phi nodes is to perform the recursive known bits queries with a depth of MaxDepth-1, which aggressively limits the number of recursions we can do with high branching factor. This patch uses an alternative approach, which forbids further use a assumes in the recursive queries.

That does also suggest a possible alternative approach here, which is to do the same thing we do for phi nodes and do the recursive queries with MaxDepth-1.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100573/new/

https://reviews.llvm.org/D100573



More information about the llvm-commits mailing list