@@ -2,7 +2,7 @@ use crate::abi::FnAbiLlvmExt;
2
2
use crate :: attributes;
3
3
use crate :: common:: Funclet ;
4
4
use crate :: context:: CodegenCx ;
5
- use crate :: llvm:: { self , AtomicOrdering , AtomicRmwBinOp , BasicBlock , False , True } ;
5
+ use crate :: llvm:: { self , AtomicOrdering , AtomicRmwBinOp , BasicBlock , False , LLVMIsALoadInst , True } ;
6
6
use crate :: llvm_util;
7
7
use crate :: type_:: Type ;
8
8
use crate :: type_of:: LayoutLlvmExt ;
@@ -662,12 +662,38 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
662
662
// optimization.
663
663
return ;
664
664
}
665
+ let abi:: WrappingRange { start, end } = range;
666
+ let llty = self . cx . val_ty ( load) ;
667
+ if unsafe { LLVMIsALoadInst ( load) } . is_some ( ) {
668
+ if start <= end {
669
+ if start > 0 {
670
+ let low = self . cx . const_uint_big ( llty, start) ;
671
+ let cmp = self . icmp ( IntPredicate :: IntUGE , load, low) ;
672
+ self . assume ( cmp) ;
673
+ }
674
+ let type_max = Size :: from_bits ( self . cx . int_width ( llty) ) . unsigned_int_max ( ) ;
675
+ if end < type_max {
676
+ let high = self . cx . const_uint_big ( llty, end) ;
677
+ let cmp = self . icmp ( IntPredicate :: IntULE , load, high) ;
678
+ self . assume ( cmp) ;
679
+ }
680
+ } else {
681
+ let low = self . cx . const_uint_big ( llty, start) ;
682
+ let cmp_low = self . icmp ( IntPredicate :: IntUGE , load, low) ;
683
+
684
+ let high = self . cx . const_uint_big ( llty, end) ;
685
+ let cmp_high = self . icmp ( IntPredicate :: IntULE , load, high) ;
686
+
687
+ let or = self . or ( cmp_low, cmp_high) ;
688
+ self . assume ( or) ;
689
+ }
690
+ return ;
691
+ }
665
692
666
693
unsafe {
667
- let llty = self . cx . val_ty ( load) ;
668
694
let v = [
669
- self . cx . const_uint_big ( llty, range . start ) ,
670
- self . cx . const_uint_big ( llty, range . end . wrapping_add ( 1 ) ) ,
695
+ self . cx . const_uint_big ( llty, start) ,
696
+ self . cx . const_uint_big ( llty, end. wrapping_add ( 1 ) ) ,
671
697
] ;
672
698
673
699
llvm:: LLVMSetMetadata (
0 commit comments