Skip to content

Commit 6768d0d

Browse files
committed
Booleans have been removed from Cranelift
1 parent 70ba23b commit 6768d0d

File tree

5 files changed

+9
-39
lines changed

5 files changed

+9
-39
lines changed

src/base.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,9 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
388388
_ => unreachable!("{:?}", targets),
389389
};
390390

391-
let discr = crate::optimize::peephole::maybe_unwrap_bint(&mut fx.bcx, discr);
392391
let (discr, is_inverted) =
393392
crate::optimize::peephole::maybe_unwrap_bool_not(&mut fx.bcx, discr);
394393
let test_zero = if is_inverted { !test_zero } else { test_zero };
395-
let discr = crate::optimize::peephole::maybe_unwrap_bint(&mut fx.bcx, discr);
396394
if let Some(taken) = crate::optimize::peephole::maybe_known_branch_taken(
397395
&fx.bcx, discr, test_zero,
398396
) {
@@ -569,7 +567,7 @@ fn codegen_stmt<'tcx>(
569567
UnOp::Not => match layout.ty.kind() {
570568
ty::Bool => {
571569
let res = fx.bcx.ins().icmp_imm(IntCC::Equal, val, 0);
572-
CValue::by_val(fx.bcx.ins().bint(types::I8, res), layout)
570+
CValue::by_val(res, layout)
573571
}
574572
ty::Uint(_) | ty::Int(_) => {
575573
CValue::by_val(fx.bcx.ins().bnot(val), layout)

src/intrinsics/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ fn bool_to_zero_or_max_uint<'tcx>(
197197
ty => ty,
198198
};
199199

200-
let val = fx.bcx.ins().bint(int_ty, val);
200+
let val = if int_ty == types::I8 { val } else { fx.bcx.ins().uextend(int_ty, val) };
201+
202+
// FIXME use bmask instead
201203
let mut res = fx.bcx.ins().ineg(val);
202204

203205
if ty.is_float() {
@@ -938,8 +940,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
938940
let old = fx.bcx.ins().atomic_cas(MemFlags::trusted(), ptr, test_old, new);
939941
let is_eq = fx.bcx.ins().icmp(IntCC::Equal, old, test_old);
940942

941-
let ret_val =
942-
CValue::by_val_pair(old, fx.bcx.ins().bint(types::I8, is_eq), ret.layout());
943+
let ret_val = CValue::by_val_pair(old, is_eq, ret.layout());
943944
ret.write_cvalue(fx, ret_val)
944945
}
945946

@@ -1261,8 +1262,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
12611262
flags.set_notrap();
12621263
let lhs_val = fx.bcx.ins().load(clty, flags, lhs_ref, 0);
12631264
let rhs_val = fx.bcx.ins().load(clty, flags, rhs_ref, 0);
1264-
let eq = fx.bcx.ins().icmp(IntCC::Equal, lhs_val, rhs_val);
1265-
fx.bcx.ins().bint(types::I8, eq)
1265+
fx.bcx.ins().icmp(IntCC::Equal, lhs_val, rhs_val)
12661266
} else {
12671267
// Just call `memcmp` (like slices do in core) when the
12681268
// size is too large or it's not a power-of-two.
@@ -1272,8 +1272,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
12721272
let returns = vec![AbiParam::new(types::I32)];
12731273
let args = &[lhs_ref, rhs_ref, bytes_val];
12741274
let cmp = fx.lib_call("memcmp", params, returns, args)[0];
1275-
let eq = fx.bcx.ins().icmp_imm(IntCC::Equal, cmp, 0);
1276-
fx.bcx.ins().bint(types::I8, eq)
1275+
fx.bcx.ins().icmp_imm(IntCC::Equal, cmp, 0)
12771276
};
12781277
ret.write_cvalue(fx, CValue::by_val(is_eq_value, ret.layout()));
12791278
}

src/intrinsics/simd.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
112112
_ => unreachable!(),
113113
};
114114

115-
let ty = fx.clif_type(res_lane_ty).unwrap();
116-
117-
let res_lane = fx.bcx.ins().bint(ty, res_lane);
118-
fx.bcx.ins().ineg(res_lane)
115+
bool_to_zero_or_max_uint(fx, res_lane_ty, res_lane)
119116
});
120117
}
121118

src/num.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ fn codegen_compare_bin_op<'tcx>(
4949
) -> CValue<'tcx> {
5050
let intcc = crate::num::bin_op_to_intcc(bin_op, signed).unwrap();
5151
let val = fx.bcx.ins().icmp(intcc, lhs, rhs);
52-
let val = fx.bcx.ins().bint(types::I8, val);
5352
CValue::by_val(val, fx.layout_of(fx.tcx.types.bool))
5453
}
5554

@@ -290,8 +289,6 @@ pub(crate) fn codegen_checked_int_binop<'tcx>(
290289
_ => bug!("binop {:?} on checked int/uint lhs: {:?} rhs: {:?}", bin_op, in_lhs, in_rhs),
291290
};
292291

293-
let has_overflow = fx.bcx.ins().bint(types::I8, has_overflow);
294-
295292
let out_layout = fx.layout_of(fx.tcx.mk_tup([in_lhs.layout().ty, fx.tcx.types.bool].iter()));
296293
CValue::by_val_pair(res, has_overflow, out_layout)
297294
}
@@ -368,7 +365,6 @@ pub(crate) fn codegen_float_binop<'tcx>(
368365
_ => unreachable!(),
369366
};
370367
let val = fx.bcx.ins().fcmp(fltcc, lhs, rhs);
371-
let val = fx.bcx.ins().bint(types::I8, val);
372368
return CValue::by_val(val, fx.layout_of(fx.tcx.types.bool));
373369
}
374370
_ => unreachable!("{:?}({:?}, {:?})", bin_op, in_lhs, in_rhs),
@@ -440,7 +436,7 @@ pub(crate) fn codegen_ptr_binop<'tcx>(
440436
_ => panic!("bin_op {:?} on ptr", bin_op),
441437
};
442438

443-
CValue::by_val(fx.bcx.ins().bint(types::I8, res), fx.layout_of(fx.tcx.types.bool))
439+
CValue::by_val(res, fx.layout_of(fx.tcx.types.bool))
444440
}
445441
}
446442

src/optimize/peephole.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@
33
use cranelift_codegen::ir::{condcodes::IntCC, InstructionData, Opcode, Value, ValueDef};
44
use cranelift_frontend::FunctionBuilder;
55

6-
/// If the given value was produced by a `bint` instruction, return it's input, otherwise return the
7-
/// given value.
8-
pub(crate) fn maybe_unwrap_bint(bcx: &mut FunctionBuilder<'_>, arg: Value) -> Value {
9-
if let ValueDef::Result(arg_inst, 0) = bcx.func.dfg.value_def(arg) {
10-
match bcx.func.dfg[arg_inst] {
11-
InstructionData::Unary { opcode: Opcode::Bint, arg } => arg,
12-
_ => arg,
13-
}
14-
} else {
15-
arg
16-
}
17-
}
18-
196
/// If the given value was produced by the lowering of `Rvalue::Not` return the input and true,
207
/// otherwise return the given value and false.
218
pub(crate) fn maybe_unwrap_bool_not(bcx: &mut FunctionBuilder<'_>, arg: Value) -> (Value, bool) {
@@ -48,13 +35,6 @@ pub(crate) fn maybe_known_branch_taken(
4835
};
4936

5037
match bcx.func.dfg[arg_inst] {
51-
InstructionData::UnaryBool { opcode: Opcode::Bconst, imm } => {
52-
if test_zero {
53-
Some(!imm)
54-
} else {
55-
Some(imm)
56-
}
57-
}
5838
InstructionData::UnaryImm { opcode: Opcode::Iconst, imm } => {
5939
if test_zero {
6040
Some(imm.bits() == 0)

0 commit comments

Comments
 (0)