Closed
Description
pub fn bar(v: u8) -> bool {
unsafe { std::mem::transmute(v) }
}
Generates (https://rust.godbolt.org/z/xzYdeffxq, note the redundant and
):
mov eax, edi
and al, 1
ret
This is because we generate a redundant trunc/zext:
rust/compiler/rustc_codegen_ssa/src/mir/block.rs
Lines 1820 to 1824 in 1dda298
define zeroext i1 @_ZN7example3bar17h1b5c1a9c0782d25bE(i8 %v) unnamed_addr #0 {
%0 = alloca i8, align 1
%1 = trunc i8 %v to i1
%2 = zext i1 %1 to i8
store i8 %2, ptr %0, align 1
%3 = load i8, ptr %0, align 1, !range !2, !noundef !3
%4 = trunc i8 %3 to i1
br label %bb1
bb1: ; preds = %start
ret i1 %4
}