llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[DAGCombiner] Compile time blow up after enqueuing additional TokenFactor-s

Open last5bits opened this issue 4 years ago • 1 comments

Commit in question:

commit d6351340bb9bf7703fb79629efdba5886d434694
Date:   Wed Mar 13 17:07:09 2019 +0000

    [DAGCombiner] If a TokenFactor would be merged into its user, consider the user later.


SDValue DAGCombiner::visitTokenFactor(SDNode *N) {
  ...
  // If the sole user is a token factor, we should make sure we have a
  // chance to merge them together. This prevents TF chains from inhibiting
  // optimizations.
  if (N->hasOneUse() && N->use_begin()->getOpcode() == ISD::TokenFactor)
    AddToWorklist(*(N->use_begin()));

Enqueuing these additional TokenFactor-s leads to compile time blow up in some cases:

before after
time .7s 103s
# of nodes combined 8,029 1,365,331
# times a TokenFactor was visited 8,824 1,447,721

Test case attached. Command line to run:

llc -O2 dagcombine-compile-time-blow-up.ll

dagcombine-compile-time-blow-up.zip

last5bits avatar Dec 23 '21 20:12 last5bits

Pinging this, as this is an issue that seems to keep coming back with various code patterns.

Another reproducer of compile time blow up: llc -O2 on: https://reviews.llvm.org/P8277

A change that resolved the reproducer I linked is this one: https://reviews.llvm.org/D118877. But it's too big of a hammer and severely affects codegen.

alinas avatar Mar 14 '22 20:03 alinas