@@ -186,9 +186,7 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
186186 Some ( instance) ,
187187 )
188188 }
189- sym:: likely => {
190- self . call_intrinsic ( "llvm.expect.i1" , & [ args[ 0 ] . immediate ( ) , self . const_bool ( true ) ] )
191- }
189+ sym:: likely => self . expect ( args[ 0 ] . immediate ( ) , true ) ,
192190 sym:: is_val_statically_known => {
193191 let intrinsic_type = args[ 0 ] . layout . immediate_llvm_type ( self . cx ) ;
194192 match self . type_kind ( intrinsic_type) {
@@ -201,8 +199,8 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
201199 _ => self . const_bool ( false ) ,
202200 }
203201 }
204- sym :: unlikely => self
205- . call_intrinsic ( "llvm. expect.i1" , & [ args[ 0 ] . immediate ( ) , self . const_bool ( false ) ] ) ,
202+
203+ sym :: unlikely => self . expect ( args[ 0 ] . immediate ( ) , false ) ,
206204 sym:: catch_unwind => {
207205 catch_unwind_intrinsic (
208206 self ,
@@ -566,11 +564,17 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
566564 }
567565
568566 fn assume ( & mut self , val : Self :: Value ) {
569- self . call_intrinsic ( "llvm.assume" , & [ val] ) ;
567+ if self . cx . sess ( ) . opts . optimize != rustc_session:: config:: OptLevel :: No {
568+ self . call_intrinsic ( "llvm.assume" , & [ val] ) ;
569+ }
570570 }
571571
572572 fn expect ( & mut self , cond : Self :: Value , expected : bool ) -> Self :: Value {
573- self . call_intrinsic ( "llvm.expect.i1" , & [ cond, self . const_bool ( expected) ] )
573+ if self . cx . sess ( ) . opts . optimize != rustc_session:: config:: OptLevel :: No {
574+ self . call_intrinsic ( "llvm.expect.i1" , & [ cond, self . const_bool ( expected) ] )
575+ } else {
576+ cond
577+ }
574578 }
575579
576580 fn type_test ( & mut self , pointer : Self :: Value , typeid : Self :: Value ) -> Self :: Value {
0 commit comments