@@ -150,14 +150,6 @@ impl Condition {
150
150
fn matches ( & self , value : ScalarInt ) -> bool {
151
151
( self . value == value) == ( self . polarity == Polarity :: Eq )
152
152
}
153
-
154
- fn inv ( mut self ) -> Self {
155
- self . polarity = match self . polarity {
156
- Polarity :: Eq => Polarity :: Ne ,
157
- Polarity :: Ne => Polarity :: Eq ,
158
- } ;
159
- self
160
- }
161
153
}
162
154
163
155
#[ derive( Copy , Clone , Debug ) ]
@@ -495,19 +487,20 @@ impl<'a, 'tcx> TOFinder<'a, 'tcx> {
495
487
}
496
488
}
497
489
}
498
- // Transfer the conditions on the copy rhs, after inversing polarity .
490
+ // Transfer the conditions on the copy rhs, after inverting the value of the condition .
499
491
Rvalue :: UnaryOp ( UnOp :: Not , Operand :: Move ( place) | Operand :: Copy ( place) ) => {
500
- if !place. ty ( self . body , self . tcx ) . ty . is_bool ( ) {
501
- // Constructing the conditions by inverting the polarity
502
- // of equality is only correct for bools. That is to say,
503
- // `!a == b` is not `a != b` for integers greater than 1 bit.
504
- return ;
505
- }
492
+ let layout = self . ecx . layout_of ( place. ty ( self . body , self . tcx ) . ty ) . unwrap ( ) ;
506
493
let Some ( conditions) = state. try_get_idx ( lhs, & self . map ) else { return } ;
507
494
let Some ( place) = self . map . find ( place. as_ref ( ) ) else { return } ;
508
- // FIXME: I think This could be generalized to not bool if we
509
- // actually perform a logical not on the condition's value.
510
- let conds = conditions. map ( self . arena , Condition :: inv) ;
495
+ let conds = conditions. map ( self . arena , |mut cond| {
496
+ cond. value = self
497
+ . ecx
498
+ . unary_op ( UnOp :: Not , & ImmTy :: from_scalar_int ( cond. value , layout) )
499
+ . unwrap ( )
500
+ . to_scalar_int ( )
501
+ . unwrap ( ) ;
502
+ cond
503
+ } ) ;
511
504
state. insert_value_idx ( place, conds, & self . map ) ;
512
505
}
513
506
// We expect `lhs ?= A`. We found `lhs = Eq(rhs, B)`.
0 commit comments