@@ -116,9 +116,7 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
116116 None ,
117117 )
118118 }
119- sym:: likely => {
120- self . call_intrinsic ( "llvm.expect.i1" , & [ args[ 0 ] . immediate ( ) , self . const_bool ( true ) ] )
121- }
119+ sym:: likely => self . expect ( args[ 0 ] . immediate ( ) , true ) ,
122120 sym:: is_val_statically_known => {
123121 let intrinsic_type = args[ 0 ] . layout . immediate_llvm_type ( self . cx ) ;
124122 match self . type_kind ( intrinsic_type) {
@@ -131,8 +129,7 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
131129 _ => self . const_bool ( false ) ,
132130 }
133131 }
134- sym:: unlikely => self
135- . call_intrinsic ( "llvm.expect.i1" , & [ args[ 0 ] . immediate ( ) , self . const_bool ( false ) ] ) ,
132+ sym:: unlikely => self . expect ( args[ 0 ] . immediate ( ) , false ) ,
136133 kw:: Try => {
137134 try_intrinsic (
138135 self ,
@@ -423,11 +420,17 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
423420 }
424421
425422 fn assume ( & mut self , val : Self :: Value ) {
426- self . call_intrinsic ( "llvm.assume" , & [ val] ) ;
423+ if self . cx . sess ( ) . opts . optimize != rustc_session:: config:: OptLevel :: No {
424+ self . call_intrinsic ( "llvm.assume" , & [ val] ) ;
425+ }
427426 }
428427
429428 fn expect ( & mut self , cond : Self :: Value , expected : bool ) -> Self :: Value {
430- self . call_intrinsic ( "llvm.expect.i1" , & [ cond, self . const_bool ( expected) ] )
429+ if self . cx . sess ( ) . opts . optimize != rustc_session:: config:: OptLevel :: No {
430+ self . call_intrinsic ( "llvm.expect.i1" , & [ cond, self . const_bool ( expected) ] )
431+ } else {
432+ cond
433+ }
431434 }
432435
433436 fn type_test ( & mut self , pointer : Self :: Value , typeid : Self :: Value ) -> Self :: Value {
0 commit comments