cranelift: Add a conditional branch instruction with two targets (#5446)
Add a conditional branch instruction with two targets: brif. This instruction will eventually replace brz and brnz, as it encompasses the behavior of both. This PR also changes the InstructionData layout for instruction formats that hold BlockCall values, taking the same approach we use for Value arguments. This allows branch_destination to return a slice to the BlockCall values held in the instruction, rather than requiring that we pattern match on InstructionData to fetch the then/else blocks. Function generation for fuzzing has been updated to generate uses of brif, and I've run the cranelift-fuzzgen target locally for hours without triggering any new failures.
This commit is contained in:
@@ -1615,12 +1615,25 @@ where
|
||||
let _type = *self.u.choose(&condbr_types[..])?;
|
||||
let val = builder.use_var(self.get_variable_of_type(_type)?);
|
||||
|
||||
if bool::arbitrary(self.u)? {
|
||||
builder.ins().brz(val, left, &left_args[..]);
|
||||
} else {
|
||||
builder.ins().brnz(val, left, &left_args[..]);
|
||||
match self.u.int_in_range(0..=2)? {
|
||||
0 => {
|
||||
builder.ins().brnz(val, left, &left_args[..]);
|
||||
builder.ins().jump(right, &right_args[..]);
|
||||
}
|
||||
|
||||
1 => {
|
||||
builder.ins().brz(val, left, &left_args[..]);
|
||||
builder.ins().jump(right, &right_args[..]);
|
||||
}
|
||||
|
||||
2 => {
|
||||
builder
|
||||
.ins()
|
||||
.brif(val, left, &left_args[..], right, &right_args[..]);
|
||||
}
|
||||
|
||||
_ => unreachable!(),
|
||||
}
|
||||
builder.ins().jump(right, &right_args[..]);
|
||||
}
|
||||
BlockTerminator::BrTable(default, targets) => {
|
||||
// Create jump tables on demand
|
||||
|
||||
Reference in New Issue
Block a user