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
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. Is there some reason I am missing that would cause this function to complete in constant time? And if so, why then is it dominating the profile to such a degree. Is that normal?
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 this test case?