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