@@ -375,28 +375,28 @@ static Value *MakeCpAsync(unsigned IntrinsicID, unsigned IntrinsicIDS,
375375 CGF.EmitScalarExpr (E->getArg (1 ))});
376376}
377377
378- static Value * MakeHalfType (unsigned IntrinsicID, unsigned BuiltinID ,
379- const CallExpr *E, CodeGenFunction &CGF) {
378+ static bool EnsureNativeHalfSupport (unsigned BuiltinID, const CallExpr *E ,
379+ CodeGenFunction &CGF) {
380380 auto &C = CGF.CGM .getContext ();
381- if (!( C.getLangOpts ().NativeHalfType ||
382- ! C.getTargetInfo ().useFP16ConversionIntrinsics () )) {
381+ if (!C.getLangOpts ().NativeHalfType &&
382+ C.getTargetInfo ().useFP16ConversionIntrinsics ()) {
383383 CGF.CGM .Error (E->getExprLoc (), C.BuiltinInfo .getQuotedName (BuiltinID) +
384384 " requires native half type support." );
385- return nullptr ;
385+ return false ;
386386 }
387+ return true ;
388+ }
387389
388- if (BuiltinID == NVPTX::BI__nvvm_ldg_h || BuiltinID == NVPTX::BI__nvvm_ldg_h2)
389- return MakeLdg (CGF, E);
390-
391- if (IntrinsicID == Intrinsic::nvvm_ldu_global_f)
392- return MakeLdu (IntrinsicID, CGF, E);
390+ static Value *MakeHalfType (Function *Intrinsic, unsigned BuiltinID,
391+ const CallExpr *E, CodeGenFunction &CGF) {
392+ if (!EnsureNativeHalfSupport (BuiltinID, E, CGF))
393+ return nullptr ;
393394
394395 SmallVector<Value *, 16 > Args;
395- auto *F = CGF.CGM .getIntrinsic (IntrinsicID);
396- auto *FTy = F->getFunctionType ();
396+ auto *FTy = Intrinsic->getFunctionType ();
397397 unsigned ICEArguments = 0 ;
398398 ASTContext::GetBuiltinTypeError Error;
399- C .GetBuiltinType (BuiltinID, Error, &ICEArguments);
399+ CGF. CGM . getContext () .GetBuiltinType (BuiltinID, Error, &ICEArguments);
400400 assert (Error == ASTContext::GE_None && " Should not codegen an error" );
401401 for (unsigned i = 0 , e = E->getNumArgs (); i != e; ++i) {
402402 assert ((ICEArguments & (1 << i)) == 0 );
@@ -407,8 +407,14 @@ static Value *MakeHalfType(unsigned IntrinsicID, unsigned BuiltinID,
407407 Args.push_back (ArgValue);
408408 }
409409
410- return CGF.Builder .CreateCall (F , Args);
410+ return CGF.Builder .CreateCall (Intrinsic , Args);
411411}
412+
413+ static Value *MakeHalfType (unsigned IntrinsicID, unsigned BuiltinID,
414+ const CallExpr *E, CodeGenFunction &CGF) {
415+ return MakeHalfType (CGF.CGM .getIntrinsic (IntrinsicID), BuiltinID, E, CGF);
416+ }
417+
412418} // namespace
413419
414420Value *CodeGenFunction::EmitNVPTXBuiltinExpr (unsigned BuiltinID,
@@ -913,9 +919,14 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID,
913919 }
914920 // The following builtins require half type support
915921 case NVPTX::BI__nvvm_ex2_approx_f16:
916- return MakeHalfType (Intrinsic::nvvm_ex2_approx_f16, BuiltinID, E, *this );
922+ return MakeHalfType (
923+ CGM.getIntrinsic (Intrinsic::nvvm_ex2_approx, Builder.getHalfTy ()),
924+ BuiltinID, E, *this );
917925 case NVPTX::BI__nvvm_ex2_approx_f16x2:
918- return MakeHalfType (Intrinsic::nvvm_ex2_approx_f16x2, BuiltinID, E, *this );
926+ return MakeHalfType (
927+ CGM.getIntrinsic (Intrinsic::nvvm_ex2_approx,
928+ FixedVectorType::get (Builder.getHalfTy (), 2 )),
929+ BuiltinID, E, *this );
919930 case NVPTX::BI__nvvm_ff2f16x2_rn:
920931 return MakeHalfType (Intrinsic::nvvm_ff2f16x2_rn, BuiltinID, E, *this );
921932 case NVPTX::BI__nvvm_ff2f16x2_rn_relu:
@@ -1049,12 +1060,22 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID,
10491060 case NVPTX::BI__nvvm_fabs_d:
10501061 return Builder.CreateUnaryIntrinsic (Intrinsic::fabs,
10511062 EmitScalarExpr (E->getArg (0 )));
1063+ case NVPTX::BI__nvvm_ex2_approx_d:
1064+ case NVPTX::BI__nvvm_ex2_approx_f:
1065+ return Builder.CreateUnaryIntrinsic (Intrinsic::nvvm_ex2_approx,
1066+ EmitScalarExpr (E->getArg (0 )));
1067+ case NVPTX::BI__nvvm_ex2_approx_ftz_f:
1068+ return Builder.CreateUnaryIntrinsic (Intrinsic::nvvm_ex2_approx_ftz,
1069+ EmitScalarExpr (E->getArg (0 )));
10521070 case NVPTX::BI__nvvm_ldg_h:
10531071 case NVPTX::BI__nvvm_ldg_h2:
1054- return MakeHalfType (Intrinsic::not_intrinsic, BuiltinID, E, *this );
1072+ return EnsureNativeHalfSupport (BuiltinID, E, *this ) ? MakeLdg (*this , E)
1073+ : nullptr ;
10551074 case NVPTX::BI__nvvm_ldu_h:
10561075 case NVPTX::BI__nvvm_ldu_h2:
1057- return MakeHalfType (Intrinsic::nvvm_ldu_global_f, BuiltinID, E, *this );
1076+ return EnsureNativeHalfSupport (BuiltinID, E, *this )
1077+ ? MakeLdu (Intrinsic::nvvm_ldu_global_f, *this , E)
1078+ : nullptr ;
10581079 case NVPTX::BI__nvvm_cp_async_ca_shared_global_4:
10591080 return MakeCpAsync (Intrinsic::nvvm_cp_async_ca_shared_global_4,
10601081 Intrinsic::nvvm_cp_async_ca_shared_global_4_s, *this , E,
0 commit comments