Stream: cranelift

Topic: question


view this post on Zulip mental (Apr 29 2021 at 17:17):

Hi all, I'm having some trouble figuring out how to combine bint + iconst + icmp + brnz properly and would appreciate some help.

I have a function that looks like this:

function u0:0() -> i64 system_v {
    block0:
        v0 = bconst.b64 true
        v1 = bint.i64 v0
        v2 = icmp_imm eq v1, 1
        brnz v2, block1
        jump block2

    block1:
        v3 = iconst.i64 30
        return v3

    block2:
        v4 = iconst.i64 40
        return v4
    }

and my issue is that block0 never branches to block1 despite the condition being essentially true == 1 I assume that the icmp_imm eq returned value would use b1 set as true so that the following brnz would branch correctly but since it isn't I can assume that either:

Am I misunderstanding anything here? I can't tell where the error is.

view this post on Zulip bjorn3 (Apr 29 2021 at 19:15):

True is represented as 1. does it work with bconst.b1? What does the function you currently have dosassemble to? In either case I think there is a bug in Cranelift.

view this post on Zulip bjorn3 (Apr 29 2021 at 19:15):

@mental

view this post on Zulip bjorn3 (Apr 29 2021 at 19:15):

Can you open an issue?

view this post on Zulip mental (Apr 29 2021 at 19:17):

It's a b64 in the code that I posted but I first got the issue when I was using b8 and assume it was some sort of casting-related-UB, I'll try it with b1 and let you know.

I'm currently using cranelift-object + cranelift-module to produce the object files which are later linked using the systemcc. that particular function there is a C main.

view this post on Zulip mental (Apr 29 2021 at 19:18):

Will open an issue later on :thumbs_up:

view this post on Zulip Chris Fallin (Apr 29 2021 at 19:32):

@mental I'm not sure what's going on with bint here, but fwiw, b64 is not commonly used -- b1 is more common for scalar booleans. Could you try with that? Also, the icmp should not be necessary -- you can just brnz directly on the bint result


Last updated: Dec 23 2024 at 13:07 UTC