@@ -150,10 +150,7 @@ fn generic_f16_builtin<'gcc, 'tcx>(
150150 _ => unreachable ! ( ) ,
151151 } ;
152152
153- let func = cx. context . get_builtin_function ( builtin_name) ;
154- let args: Vec < _ > = args. iter ( ) . map ( |arg| f16_to_f32 ( cx, arg. immediate ( ) ) ) . collect ( ) ;
155- let result = cx. context . new_call ( None , func, & args) ;
156- float_to_f16 ( cx, result, cx. f16_abi_type )
153+ call_f32_builtin_for_f16 ( cx, builtin_name, args)
157154}
158155
159156fn f16_builtin < ' gcc , ' tcx > (
@@ -179,6 +176,14 @@ fn f16_builtin<'gcc, 'tcx>(
179176 _ => unreachable ! ( ) ,
180177 } ;
181178
179+ call_f32_builtin_for_f16 ( cx, builtin_name, args)
180+ }
181+
182+ fn call_f32_builtin_for_f16 < ' gcc , ' tcx > (
183+ cx : & CodegenCx < ' gcc , ' tcx > ,
184+ builtin_name : & str ,
185+ args : & [ OperandRef < ' tcx , RValue < ' gcc > > ] ,
186+ ) -> RValue < ' gcc > {
182187 let func = cx. context . get_builtin_function ( builtin_name) ;
183188 let args: Vec < _ > = args. iter ( ) . map ( |arg| f16_to_f32 ( cx, arg. immediate ( ) ) ) . collect ( ) ;
184189 let result = cx. context . new_call ( None , func, & args) ;
@@ -617,24 +622,20 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
617622 args : & [ OperandRef < ' tcx , Self :: Value > ] ,
618623 is_cleanup : bool ,
619624 ) -> Self :: Value {
625+ let sym = self . tcx . symbol_name ( instance) . name ;
626+ if sym == "llvm.fma.f16" {
627+ return call_f32_builtin_for_f16 ( self . cx , "fmaf" , args) ;
628+ }
629+
620630 let func = if let Some ( & func) = self . intrinsic_instances . borrow ( ) . get ( & instance) {
621631 func
622632 } else {
623- let sym = self . tcx . symbol_name ( instance) . name ;
624-
625633 let func = if let Some ( func) = self . intrinsics . borrow ( ) . get ( sym) {
626634 * func
627635 } else {
628636 self . linkage . set ( FunctionType :: Extern ) ;
629637
630- let func = match sym {
631- "llvm.fma.f16" => {
632- // fma is not a target builtin, but a normal builtin, so we handle it differently
633- // here.
634- self . context . get_builtin_function ( "fma" )
635- }
636- _ => llvm:: intrinsic ( sym, self ) ,
637- } ;
638+ let func = llvm:: intrinsic ( sym, self ) ;
638639
639640 self . intrinsics . borrow_mut ( ) . insert ( sym. to_string ( ) , func) ;
640641
0 commit comments