Llvm code excess line?

hello,

what is this line for? %3 = and i8 %2, 1

in this:

julia> @code_llvm true | false
define i8 @"julia_|_7397"(i8 zeroext %0, i8 zeroext %1) #0 {
top:
  %2 = or i8 %1, %0
  %3 = and i8 %2, 1
  ret i8 %3
}

it is work

function llvm_or(x1::Bool, x2::Bool)
    Base.Intrinsics.llvmcall("""
            %3 = or i8 %1, %0
            ret i8 %3
        """,
        Bool, Tuple{Bool,Bool}, x1, x2
    )
end

llvm_or(true, true)    # -> true
llvm_or(true, false)   # -> true
llvm_or(false, true)   # -> true
llvm_or(false, false)  # -> false

julia> @code_llvm llvm_or(true, false)
define i8 @julia_llvm_or_7399(i8 zeroext %0, i8 zeroext %1) #0 {
top:
  %2 = or i8 %1, %0
  ret i8 %2
}
1 Like

I understand, apparently %3 = and i8 %2, 1 cleans other bits

1 Like

As you said, and “cleans” the other bits, by applying a mask so that all the leading bits of the 8 bit integer are set to 0, and the final bit will be whatever the input bit says.