2
2
3
3
use crate :: prelude:: * ;
4
4
5
- pub ( crate ) fn bin_op_to_intcc ( bin_op : BinOp , signed : bool ) -> Option < IntCC > {
5
+ pub ( crate ) fn bin_op_to_intcc ( bin_op : BinOp , signed : bool ) -> IntCC {
6
6
use BinOp :: * ;
7
7
use IntCC :: * ;
8
- Some ( match bin_op {
8
+ match bin_op {
9
9
Eq => Equal ,
10
10
Lt => {
11
11
if signed {
@@ -36,8 +36,8 @@ pub(crate) fn bin_op_to_intcc(bin_op: BinOp, signed: bool) -> Option<IntCC> {
36
36
UnsignedGreaterThan
37
37
}
38
38
}
39
- _ => return None ,
40
- } )
39
+ _ => unreachable ! ( ) ,
40
+ }
41
41
}
42
42
43
43
fn codegen_three_way_compare < ' tcx > (
@@ -48,8 +48,8 @@ fn codegen_three_way_compare<'tcx>(
48
48
) -> CValue < ' tcx > {
49
49
// This emits `(lhs > rhs) - (lhs < rhs)`, which is cranelift's preferred form per
50
50
// <https://github.com/bytecodealliance/wasmtime/blob/8052bb9e3b792503b225f2a5b2ba3bc023bff462/cranelift/codegen/src/prelude_opt.isle#L41-L47>
51
- let gt_cc = crate :: num:: bin_op_to_intcc ( BinOp :: Gt , signed) . unwrap ( ) ;
52
- let lt_cc = crate :: num:: bin_op_to_intcc ( BinOp :: Lt , signed) . unwrap ( ) ;
51
+ let gt_cc = crate :: num:: bin_op_to_intcc ( BinOp :: Gt , signed) ;
52
+ let lt_cc = crate :: num:: bin_op_to_intcc ( BinOp :: Lt , signed) ;
53
53
let gt = fx. bcx . ins ( ) . icmp ( gt_cc, lhs, rhs) ;
54
54
let lt = fx. bcx . ins ( ) . icmp ( lt_cc, lhs, rhs) ;
55
55
let val = fx. bcx . ins ( ) . isub ( gt, lt) ;
@@ -63,11 +63,7 @@ fn codegen_compare_bin_op<'tcx>(
63
63
lhs : Value ,
64
64
rhs : Value ,
65
65
) -> CValue < ' tcx > {
66
- if bin_op == BinOp :: Cmp {
67
- return codegen_three_way_compare ( fx, signed, lhs, rhs) ;
68
- }
69
-
70
- let intcc = crate :: num:: bin_op_to_intcc ( bin_op, signed) . unwrap ( ) ;
66
+ let intcc = crate :: num:: bin_op_to_intcc ( bin_op, signed) ;
71
67
let val = fx. bcx . ins ( ) . icmp ( intcc, lhs, rhs) ;
72
68
CValue :: by_val ( val, fx. layout_of ( fx. tcx . types . bool ) )
73
69
}
@@ -79,7 +75,7 @@ pub(crate) fn codegen_binop<'tcx>(
79
75
in_rhs : CValue < ' tcx > ,
80
76
) -> CValue < ' tcx > {
81
77
match bin_op {
82
- BinOp :: Eq | BinOp :: Lt | BinOp :: Le | BinOp :: Ne | BinOp :: Ge | BinOp :: Gt | BinOp :: Cmp => {
78
+ BinOp :: Eq | BinOp :: Lt | BinOp :: Le | BinOp :: Ne | BinOp :: Ge | BinOp :: Gt => {
83
79
match in_lhs. layout ( ) . ty . kind ( ) {
84
80
ty:: Bool | ty:: Uint ( _) | ty:: Int ( _) | ty:: Char => {
85
81
let signed = type_sign ( in_lhs. layout ( ) . ty ) ;
@@ -91,6 +87,16 @@ pub(crate) fn codegen_binop<'tcx>(
91
87
_ => { }
92
88
}
93
89
}
90
+ BinOp :: Cmp => match in_lhs. layout ( ) . ty . kind ( ) {
91
+ ty:: Bool | ty:: Uint ( _) | ty:: Int ( _) | ty:: Char => {
92
+ let signed = type_sign ( in_lhs. layout ( ) . ty ) ;
93
+ let lhs = in_lhs. load_scalar ( fx) ;
94
+ let rhs = in_rhs. load_scalar ( fx) ;
95
+
96
+ return codegen_three_way_compare ( fx, signed, lhs, rhs) ;
97
+ }
98
+ _ => { }
99
+ } ,
94
100
_ => { }
95
101
}
96
102
@@ -357,14 +363,12 @@ pub(crate) fn codegen_float_binop<'tcx>(
357
363
_ => bug ! ( ) ,
358
364
} ;
359
365
360
- let ret_val = fx. lib_call (
366
+ fx. lib_call (
361
367
name,
362
368
vec ! [ AbiParam :: new( ty) , AbiParam :: new( ty) ] ,
363
369
vec ! [ AbiParam :: new( ty) ] ,
364
370
& [ lhs, rhs] ,
365
- ) [ 0 ] ;
366
-
367
- return CValue :: by_val ( ret_val, in_lhs. layout ( ) ) ;
371
+ ) [ 0 ]
368
372
}
369
373
BinOp :: Eq | BinOp :: Lt | BinOp :: Le | BinOp :: Ne | BinOp :: Ge | BinOp :: Gt => {
370
374
let fltcc = match bin_op {
@@ -431,13 +435,9 @@ pub(crate) fn codegen_ptr_binop<'tcx>(
431
435
BinOp :: Lt | BinOp :: Le | BinOp :: Ge | BinOp :: Gt => {
432
436
let ptr_eq = fx. bcx . ins ( ) . icmp ( IntCC :: Equal , lhs_ptr, rhs_ptr) ;
433
437
434
- let ptr_cmp =
435
- fx. bcx . ins ( ) . icmp ( bin_op_to_intcc ( bin_op, false ) . unwrap ( ) , lhs_ptr, rhs_ptr) ;
436
- let extra_cmp = fx. bcx . ins ( ) . icmp (
437
- bin_op_to_intcc ( bin_op, false ) . unwrap ( ) ,
438
- lhs_extra,
439
- rhs_extra,
440
- ) ;
438
+ let ptr_cmp = fx. bcx . ins ( ) . icmp ( bin_op_to_intcc ( bin_op, false ) , lhs_ptr, rhs_ptr) ;
439
+ let extra_cmp =
440
+ fx. bcx . ins ( ) . icmp ( bin_op_to_intcc ( bin_op, false ) , lhs_extra, rhs_extra) ;
441
441
442
442
fx. bcx . ins ( ) . select ( ptr_eq, extra_cmp, ptr_cmp)
443
443
}
0 commit comments