optimizer: Do not run if we know the function is ConstABI eligible (#51143)
If we can determine that a function is sufficiently pure and returns a
constant, we have special ABI that lets us throw away the code for it
and just return the constant. However, we were still going through all
the steps of actually computing the code, including running the
optimizer on it, compressing it in preparation for caching, etc. We can
just stop doing that and bypass the optimizer entirely.
The actual change to do this is pretty tiny, but there's some unexpected
fallout which this needs to cleanup:
1. Various tests expect code_* queries of things inferred to ConstABI to
still return reasonable code. Fix this by manually emitting a ReturnNode
at the end of inference if the caller is a reflection function.
2. This kinda wreaks havoc on the EscapeAnalysis tests, which work by
using a side-effect of the optimizer, but a lot of the functions are
ConstABI eligible, so the optimizer doesn't run any more. Fortunately,
I'm in the middle of looking at overhauling EscapeAnalysis, so I'll have
some chance to figure out how to change the test system to actually do
this properly, rather than exfiltrating side effects. That said, since
EscapeAnalysis is not in the default pipeline, I don't think we should
hold the perf improvement until that is done.
Benchmarked to be about 10% faster locally, but we'll see what
nanosoldier thinks.
---------
Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>