Stream: t-compiler/wg-mir-opt

Topic: peephole opts in mir


Xavier Denis (Aug 07 2020 at 12:40, on Zulip):

is there any plan to grow MIR a proper peephole optimization mechanism?

I recently wrote one for LLVM and their API would make something like: https://github.com/rust-lang/rust/issues/75144 trivial to implement.

oli (Aug 07 2020 at 13:26, on Zulip):

I wouldn't know how that would look, can you give an example why that would be trivial with a peephole optimization mechanism?

lqd (Aug 07 2020 at 13:31, on Zulip):

a lot of them are modeled as pattern matching + code transformations

lqd (Aug 07 2020 at 13:31, on Zulip):

like say, https://github.com/gcc-mirror/gcc/blob/master/gcc/match.pd#L5266-L5269

lqd (Aug 07 2020 at 13:32, on Zulip):

or fitzgen's peepmatic for cranelift https://github.com/fitzgen/peepmatic#example

Xavier Denis (Aug 09 2020 at 22:28, on Zulip):

yea, in rustc it would probably be implemented as a mir traversal which also remembers the shape of previous visited locations

Xavier Denis (Aug 09 2020 at 22:29, on Zulip):

https://github.com/llvm/llvm-project/blob/master/llvm/lib/Analysis/InstructionSimplify.cpp#L2827

for example here's the opt i added to llvm to fix an issue with split_at

Last update: Sep 28 2020 at 16:15UTC