708 icon indicating copy to clipboard operation
708 copied to clipboard

Definite last use for in parameters when passing to another function.

Open happycr opened this issue 4 years ago • 0 comments

If I understand Appendix 1 correctly, a function of the form:

// Where B is a large type.
void f(in B b) {
    use(b);
}

generates the following code for the moment (ignoring bit flags):

void _generated_f(const B* b, bool __b_arg_is_nonconst_rvalue ) {
    if (__b_arg_is_nonconst_rvalue) {
        use(std::move(*b));
    }
    else {
        use(b);
    }
}

Assuming the function use takes b by an in parameter ( what else would it be? ) why doesn't the generated code look like this:

void _generated_f(const B* b, bool __b_arg_is_nonconst_rvalue) {
   use(b, __b_arg_is_nonconst_rvalue);
}

That way we remove one unnecessary branch and the function use can optimize for r values... Is there something I am not understanding correctly?

happycr avatar Jul 01 '21 20:07 happycr