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:
0 as b1
means true here orb64
true
to i64
would have a value of 1
.Am I misunderstanding anything here? I can't tell where the error is.
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.
@mental
Can you open an issue?
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.
Will open an issue later on :thumbs_up:
@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: Nov 22 2024 at 16:03 UTC