# Mapping LLVM type i1 to Julia type

**URL:** <https://discourse.julialang.org/t/mapping-llvm-type-i1-to-julia-type/45733>\
**Category:** General Usage\
**Tags:** llvm\
**Created:** [August 29, 2020, 11:12am UTC](https://discourse.julialang.org/t/mapping-llvm-type-i1-to-julia-type/45733 "2020-08-29T11:12:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![msoeken](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/msoeken/32/17561_2.png) [@msoeken](https://discourse.julialang.org/u/msoeken)\
**Post date:** [August 29, 2020, 11:12am UTC](https://discourse.julialang.org/t/mapping-llvm-type-i1-to-julia-type/45733/1 "2020-08-29T11:12:24Z")

</div>

I am trying to use `llvmcall` and want to map a return value of LLVM type `i1` to a Julia `Bool` value.

```julia
using Base

function isodd(a)
    Base.llvmcall("""%mod = srem i64 %0, 2\n%cmp = icmp eq i64 %mod, 1\nret i1 %cmp""", Bool, Tuple{Int64,}, a)
end

print(isodd(13))

```

The following error is thrown when executing the program:

```julia
ERROR: LoadError: Failed to parse LLVM assembly: 
llvmcall:5:5: error: value doesn't match function result type 'i8'
ret i1 %cmp

```

Could anyone help? Is there an alternative type I can use instead of `Bool` to match to `i1`?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [August 29, 2020, 11:23am UTC](https://discourse.julialang.org/t/mapping-llvm-type-i1-to-julia-type/45733/2 "2020-08-29T11:23:31Z")

</div>

You need to zero extend it to i8. See

[https://github.com/eschnett/SIMD.jl/blob/24016b1790cf105e20fa10e374206589f8f9bb4c/src/LLVM\_intrinsics.jl#L349](https://github.com/eschnett/SIMD.jl/blob/24016b1790cf105e20fa10e374206589f8f9bb4c/src/LLVM_intrinsics.jl#L349)

---

<div class="post-metadata">

**Author:** ![msoeken](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/msoeken/32/17561_2.png) [@msoeken](https://discourse.julialang.org/u/msoeken)\
**Post date:** [August 29, 2020, 4:37pm UTC](https://discourse.julialang.org/t/mapping-llvm-type-i1-to-julia-type/45733/3 "2020-08-29T16:37:44Z")

</div>

Thanks for the answer. But would it be possible to do this without changing the LLVM code, and by adding some compatible Julia type?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [August 29, 2020, 8:02pm UTC](https://discourse.julialang.org/t/mapping-llvm-type-i1-to-julia-type/45733/4 "2020-08-29T20:02:36Z")

</div>

> [@msoeken](#):
>
> and by adding some compatible Julia type?

I don’t think so. Even `primitive type` restricts the size to be a multiple of 8.

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [August 29, 2020, 9:29pm UTC](https://discourse.julialang.org/t/mapping-llvm-type-i1-to-julia-type/45733/5 "2020-08-29T21:29:55Z")

</div>

FWIW, I haven’t seen an example where LLVM fails to get rid of the `zext`/`truncs`.
