Stream: t-compiler/wg-mir-opt

Topic: mir inline cost


andjo403 (Mar 09 2020 at 20:34, on Zulip):

what is the cost that is calculated for mir inlining? While looking in to why the instance_def_size_estimate function is estimate do not match the number of llvm-ir instructions there was alot of code that only is generated in llvm so I guess my question is if that shall be handled in the mir inline cost?
e.g. mir calls/drops that have a cleanup generate one extra BB (landingpad) that contains 10 llvm-ir instructions and also mir resume results in 9 llvm-ir instructions

Wesley Wiser (Mar 09 2020 at 20:40, on Zulip):

The cost calculation is here https://github.com/rust-lang/rust/blob/3dbade652ed8ebac70f903e01f51cd92c4e4302c/src/librustc_mir/transform/inline.rs#L215

Wesley Wiser (Mar 09 2020 at 20:41, on Zulip):

It's done at the MIR statement level so there's definitely a disconnect between that and what LLVM sees.

andjo403 (Mar 09 2020 at 20:43, on Zulip):

my thinking is that maybe at eg line https://github.com/rust-lang/rust/blob/3dbade652ed8ebac70f903e01f51cd92c4e4302c/src/librustc_mir/transform/inline.rs#L331 to increase the cost with 10 due to the landingpad BB

Wesley Wiser (Mar 09 2020 at 20:44, on Zulip):

You mean add another 10 for calls that can unwind?

andjo403 (Mar 09 2020 at 20:48, on Zulip):

yes so eg. for mir _2 = const std::vec::Vec::<T>::as_mut_ptr(move _3) -> [return: bb2, unwind: bb15];
the extra bb cleanup bb is before bb15 in llvm ir
cleanup: ; preds = %bb12, %bb11, %bb10, %bb8, %bb4, %bb5, %bb2, %start %27 = landingpad { i8*, i32 } cleanup %28 = bitcast { i8*, i32 }* %2 to i8* call void @llvm.lifetime.start.p0i8(i64 16, i8* %28) %29 = extractvalue { i8*, i32 } %27, 0 %30 = extractvalue { i8*, i32 } %27, 1 %31 = getelementptr inbounds { i8*, i32 }, { i8*, i32 }* %2, i32 0, i32 0 store i8* %29, i8** %31, align 8 %32 = getelementptr inbounds { i8*, i32 }, { i8*, i32 }* %2, i32 0, i32 1 store i32 %30, i32* %32, align 8 br label %bb15

Wesley Wiser (Mar 09 2020 at 20:59, on Zulip):

That's a good idea!

andjo403 (Mar 09 2020 at 21:14, on Zulip):

call and assert also have a cleanup variable that also generate a landingpad

eddyb (Mar 12 2020 at 12:27, on Zulip):

I think inline costs at the MIR level are more pseudo than science

eddyb (Mar 12 2020 at 12:56, on Zulip):

but I don't have the time to relitigate that so let's pretend I didn't say anything :P

Last update: Apr 03 2020 at 18:20UTC