[llvm-dev] Fwd: Is the fast register allocator O(n^2) in the size of the function?
Dwight Guth via llvm-dev
llvm-dev at lists.llvm.org
Wed Feb 10 10:47:58 PST 2021
Hi,
I am the maintainer of an open source compiler that makes use of the
LLVM toolchain to perform code generation. A user of our compiler, who
is working on a proprietary project, recently shared with me an
example where our toolchain was invoking `llc -O0` on a file with a
rather large function in it, and the register allocation pass was
taking upwards of 5 minutes. This seemed unusual to me, so I
downloaded the debug symbols for LLVM (this was with LLVM 11.0.0), and
I found that slightly over 50% of the runtime of LLC was spent within
a very small loop within llvm::MachineRegisterInfo::hasOneNonDBGUse. I
believe this loop to correspond to the while loop in
llvm::MachineRegisterInfo::defusechain_iterator::advance.
It looks like this function is just scanning through all the defs and
uses of a register in the function until it finds one that it
considers satisfactory? That seems like it would be introducing
behavior that is quadratic in the size of the function to me. Am I
missing something? Is there some other, more sensible reason why the
profile seems so dependent on this one loop of code? Did I
misunderstand something?
My end goal here would be to submit a patch that might optimize this
case, since it seems to me something that might be able to be computed
more efficiently. But I don't understand the code or the algorithm
hugely well, so I was hoping someone could give me some pointers on
where to get started with something like this.
Does anyone have any suggestions on what I could do to make register
allocation run faster on quite large functions?
Thanks,
--
Dwight Guth
Chief Information Officer
Runtime Verification, Inc.
Email: dwight.guth at runtimeverification.com
More information about the llvm-dev
mailing list