@@ -966,12 +966,13 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
966
966
}
967
967
} ;
968
968
969
- // Represent the values as `Ok(bits)` or `Err(VnIndex)`.
970
- let a = as_bits ( lhs) . ok_or ( lhs) ;
971
- let b = as_bits ( rhs) . ok_or ( rhs) ;
969
+ // Represent the values as `Left(bits)` or `Right(VnIndex)`.
970
+ use Either :: { Left , Right } ;
971
+ let a = as_bits ( lhs) . map_or ( Right ( lhs) , Left ) ;
972
+ let b = as_bits ( rhs) . map_or ( Right ( rhs) , Left ) ;
972
973
let result = match ( op, a, b) {
973
974
// Neutral elements.
974
- ( BinOp :: Add | BinOp :: BitOr | BinOp :: BitXor , Ok ( 0 ) , Err ( p) )
975
+ ( BinOp :: Add | BinOp :: BitOr | BinOp :: BitXor , Left ( 0 ) , Right ( p) )
975
976
| (
976
977
BinOp :: Add
977
978
| BinOp :: BitOr
@@ -980,28 +981,28 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
980
981
| BinOp :: Offset
981
982
| BinOp :: Shl
982
983
| BinOp :: Shr ,
983
- Err ( p) ,
984
- Ok ( 0 ) ,
984
+ Right ( p) ,
985
+ Left ( 0 ) ,
985
986
)
986
- | ( BinOp :: Mul , Ok ( 1 ) , Err ( p) )
987
- | ( BinOp :: Mul | BinOp :: Div , Err ( p) , Ok ( 1 ) ) => p,
987
+ | ( BinOp :: Mul , Left ( 1 ) , Right ( p) )
988
+ | ( BinOp :: Mul | BinOp :: Div , Right ( p) , Left ( 1 ) ) => p,
988
989
// Attempt to simplify `x & ALL_ONES` to `x`, with `ALL_ONES` depending on type size.
989
- ( BinOp :: BitAnd , Err ( p) , Ok ( ones) ) | ( BinOp :: BitAnd , Ok ( ones) , Err ( p) )
990
+ ( BinOp :: BitAnd , Right ( p) , Left ( ones) ) | ( BinOp :: BitAnd , Left ( ones) , Right ( p) )
990
991
if ones == layout. size . truncate ( u128:: MAX )
991
992
|| ( layout. ty . is_bool ( ) && ones == 1 ) =>
992
993
{
993
994
p
994
995
}
995
996
// Absorbing elements.
996
- ( BinOp :: Mul | BinOp :: BitAnd , _, Ok ( 0 ) )
997
- | ( BinOp :: Rem , _, Ok ( 1 ) )
997
+ ( BinOp :: Mul | BinOp :: BitAnd , _, Left ( 0 ) )
998
+ | ( BinOp :: Rem , _, Left ( 1 ) )
998
999
| (
999
1000
BinOp :: Mul | BinOp :: Div | BinOp :: Rem | BinOp :: BitAnd | BinOp :: Shl | BinOp :: Shr ,
1000
- Ok ( 0 ) ,
1001
+ Left ( 0 ) ,
1001
1002
_,
1002
1003
) => self . insert_scalar ( Scalar :: from_uint ( 0u128 , layout. size ) , lhs_ty) ,
1003
1004
// Attempt to simplify `x | ALL_ONES` to `ALL_ONES`.
1004
- ( BinOp :: BitOr , _, Ok ( ones) ) | ( BinOp :: BitOr , Ok ( ones) , _)
1005
+ ( BinOp :: BitOr , _, Left ( ones) ) | ( BinOp :: BitOr , Left ( ones) , _)
1005
1006
if ones == layout. size . truncate ( u128:: MAX )
1006
1007
|| ( layout. ty . is_bool ( ) && ones == 1 ) =>
1007
1008
{
@@ -1015,8 +1016,10 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
1015
1016
// - if both operands can be computed as bits, just compare the bits;
1016
1017
// - if we proved that both operands have the same value, we can insert true/false;
1017
1018
// - otherwise, do nothing, as we do not try to prove inequality.
1018
- ( BinOp :: Eq , a, b) if ( a. is_ok ( ) && b. is_ok ( ) ) || a == b => self . insert_bool ( a == b) ,
1019
- ( BinOp :: Ne , a, b) if ( a. is_ok ( ) && b. is_ok ( ) ) || a == b => self . insert_bool ( a != b) ,
1019
+ ( BinOp :: Eq , Left ( a) , Left ( b) ) => self . insert_bool ( a == b) ,
1020
+ ( BinOp :: Eq , a, b) if a == b => self . insert_bool ( true ) ,
1021
+ ( BinOp :: Ne , Left ( a) , Left ( b) ) => self . insert_bool ( a != b) ,
1022
+ ( BinOp :: Ne , a, b) if a == b => self . insert_bool ( false ) ,
1020
1023
_ => return None ,
1021
1024
} ;
1022
1025
0 commit comments