@@ -187,9 +187,7 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
187187 Some ( instance) ,
188188 )
189189 }
190- sym:: likely => {
191- self . call_intrinsic ( "llvm.expect.i1" , & [ args[ 0 ] . immediate ( ) , self . const_bool ( true ) ] )
192- }
190+ sym:: likely => self . expect ( args[ 0 ] . immediate ( ) , true ) ,
193191 sym:: is_val_statically_known => {
194192 let intrinsic_type = args[ 0 ] . layout . immediate_llvm_type ( self . cx ) ;
195193 let kind = self . type_kind ( intrinsic_type) ;
@@ -210,8 +208,7 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
210208 self . const_bool ( false )
211209 }
212210 }
213- sym:: unlikely => self
214- . call_intrinsic ( "llvm.expect.i1" , & [ args[ 0 ] . immediate ( ) , self . const_bool ( false ) ] ) ,
211+ sym:: unlikely => self . expect ( args[ 0 ] . immediate ( ) , false ) ,
215212 sym:: select_unpredictable => {
216213 let cond = args[ 0 ] . immediate ( ) ;
217214 assert_eq ! ( args[ 1 ] . layout, args[ 2 ] . layout) ;
@@ -604,11 +601,17 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
604601 }
605602
606603 fn assume ( & mut self , val : Self :: Value ) {
607- self . call_intrinsic ( "llvm.assume" , & [ val] ) ;
604+ if self . cx . sess ( ) . opts . optimize != rustc_session:: config:: OptLevel :: No {
605+ self . call_intrinsic ( "llvm.assume" , & [ val] ) ;
606+ }
608607 }
609608
610609 fn expect ( & mut self , cond : Self :: Value , expected : bool ) -> Self :: Value {
611- self . call_intrinsic ( "llvm.expect.i1" , & [ cond, self . const_bool ( expected) ] )
610+ if self . cx . sess ( ) . opts . optimize != rustc_session:: config:: OptLevel :: No {
611+ self . call_intrinsic ( "llvm.expect.i1" , & [ cond, self . const_bool ( expected) ] )
612+ } else {
613+ cond
614+ }
612615 }
613616
614617 fn type_test ( & mut self , pointer : Self :: Value , typeid : Self :: Value ) -> Self :: Value {
0 commit comments