Instead of blindly traversing the use-def chain of constant arguments, compute known constants along the way. Stop as soon as a user cannot be replaced by a constant. Keep it light-weight by handling some basic instruction types.
Stats from the llvm testsuite (CTMark):
-O3 pipeline
Nspecs before | ClamAV : 5 | SPASS : 2 | Bullet : 1 |
Nspecs after | ClamAV : 5 | consumer-typeset : 1 | Bullet : 1 |
InstrCount delta (geomean) : -0.029% | |||
LTO pipeline
Nspecs before | sqlite3 : 1 | consumer-typeset : 1 |
Nspecs after | SPASS : 3 | consumer-typeset : 1 |
InstrCount delta (geomean) : -0.015% |
Let's add a comment for this since its semantics are not clear from the signature.