1 //! Peephole optimizations that can be performed while creating clif ir.
3 use cranelift_codegen
::ir
::{condcodes::IntCC, InstructionData, Opcode, Value, ValueDef}
;
4 use cranelift_frontend
::FunctionBuilder
;
6 /// If the given value was produced by the lowering of `Rvalue::Not` return the input and true,
7 /// otherwise return the given value and false.
8 pub(crate) fn maybe_unwrap_bool_not(bcx
: &mut FunctionBuilder
<'_
>, arg
: Value
) -> (Value
, bool
) {
9 if let ValueDef
::Result(arg_inst
, 0) = bcx
.func
.dfg
.value_def(arg
) {
10 match bcx
.func
.dfg
[arg_inst
] {
11 // This is the lowering of `Rvalue::Not`
12 InstructionData
::IntCompareImm
{
13 opcode
: Opcode
::IcmpImm
,
17 } if imm
.bits() == 0 => (arg
, true),
25 /// Returns whether the branch is statically known to be taken or `None` if it isn't statically known.
26 pub(crate) fn maybe_known_branch_taken(
27 bcx
: &FunctionBuilder
<'_
>,
31 let arg_inst
= if let ValueDef
::Result(arg_inst
, 0) = bcx
.func
.dfg
.value_def(arg
) {
37 match bcx
.func
.dfg
[arg_inst
] {
38 InstructionData
::UnaryImm { opcode: Opcode::Iconst, imm }
=> {