When checking if instructions clobber any locations, we do so by looking at each entry in VariableMap and call MI.modifiesRegister() on that variable. If the size of VariableMap is large, this can be very slow, because modifiesRegister isn't very fast.
Instead, we track just the specified registers, and only call MI.modifiesRegister() for each entry in that much smaller set. If there are no matches, we avoid needing to iterate over VariableMap entirely. If there are any matches, we can then iterate over VariableMap and do the much cheaper equality comparison for registers to decide if remove it.
This brings compilation of a seemingly-simle file from 5 minutes to 10 seconds. The stats added in this patch show the relative sizes of data sets:
$ llc -run-pass=removeredundantdebugvalues /tmp/repro.O3.mir -o /dev/null -stats ===-------------------------------------------------------------------------=== ... Statistics Collected ... ===-------------------------------------------------------------------------=== 6 removeredundantdebugvalues - Maximum size of RegisterSet (forward scan) 183077 removeredundantdebugvalues - Maximum size of VariableMap (forward scan)
This patch is purely a compile time improvement. It is not intended to have any visible effect on the output IR.