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:
@@ -1898,6 +1898,30 @@
|
||||
(hi Reg (value_regs_get regs 1)))
|
||||
(alu_rrr (AluOPRRR.Or) lo hi)))
|
||||
|
||||
;; Default behavior for branching based on an input value.
|
||||
(rule
|
||||
(lower_branch (brif v @ (value_type ty) _ _) targets)
|
||||
(lower_brz_or_nz (IntCC.NotEqual) (normalize_cmp_value ty v) targets ty))
|
||||
|
||||
;; Special case for SI128 to reify the comparison value and branch on it.
|
||||
(rule 2
|
||||
(lower_branch (brif v @ (value_type $I128) _ _) targets)
|
||||
(let ((zero ValueRegs (value_regs (zero_reg) (zero_reg)))
|
||||
(cmp Reg (gen_icmp (IntCC.NotEqual) v zero $I128)))
|
||||
(lower_brz_or_nz (IntCC.NotEqual) cmp targets $I64)))
|
||||
|
||||
;; Branching on the result of an icmp
|
||||
(rule 1
|
||||
(lower_branch (brif (icmp cc a @ (value_type ty) b) _ _) targets)
|
||||
(lower_br_icmp cc a b targets ty))
|
||||
|
||||
;; Branching on the result of an fcmp
|
||||
(rule 1
|
||||
(lower_branch (brif (fcmp cc a @ (value_type ty) b) _ _) targets)
|
||||
(let ((then BranchTarget (label_to_br_target (vec_label_get targets 0)))
|
||||
(else BranchTarget (label_to_br_target (vec_label_get targets 1))))
|
||||
(emit_side_effect (cond_br (emit_fcmp cc ty a b) then else))))
|
||||
|
||||
;;;;;
|
||||
(rule
|
||||
(lower_branch (brz v @ (value_type ty) _) targets)
|
||||
|
||||
@@ -14,8 +14,8 @@ use crate::machinst::{isle::*, MachInst, SmallInstVec};
|
||||
use crate::machinst::{VCodeConstant, VCodeConstantData};
|
||||
use crate::{
|
||||
ir::{
|
||||
immediates::*, types::*, AtomicRmwOp, ExternalName, Inst, InstructionData, MemFlags,
|
||||
StackSlot, TrapCode, Value, ValueList,
|
||||
immediates::*, types::*, AtomicRmwOp, BlockCall, ExternalName, Inst, InstructionData,
|
||||
MemFlags, StackSlot, TrapCode, Value, ValueList,
|
||||
},
|
||||
isa::riscv64::inst::*,
|
||||
machinst::{ArgPair, InstOutput, Lower},
|
||||
|
||||
Reference in New Issue
Block a user