Function rustc_codegen_ssa::base::build_shift_expr_rhs

source ·
pub fn build_shift_expr_rhs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
    bx: &mut Bx,
    lhs: Bx::Value,
    rhs: Bx::Value,
    is_unchecked: bool
) -> Bx::Value
Expand description

Returns rhs sufficiently masked, truncated, and/or extended so that it can be used to shift lhs.

Shifts in MIR are all allowed to have mismatched LHS & RHS types. The shift methods in BuilderMethods, however, are fully homogeneous (both parameters and the return type are all the same type).

If is_unchecked is false, this masks the RHS to ensure it stays in-bounds, as the BuilderMethods shifts are UB for out-of-bounds shift amounts. For 32- and 64-bit types, this matches the semantics of Java. (See related discussion on #1877 and #10183.)

If is_unchecked is true, this does no masking, and adds sufficient assume calls or operation flags to preserve as much freedom to optimize as possible.