rustc_codegen_ssa::base

Function build_shift_expr_rhs

source
pub(crate) 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: it has the same size as lhs, and the value, when interpreted unsigned (no matter its type), will not exceed the size of lhs.

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

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.