yaxunl created this revision.
yaxunl added reviewers: arsenm, rjmccall.
Herald added a project: All.
yaxunl requested review of this revision.
Herald added a subscriber: wdng.

Fix: https://github.com/llvm/llvm-project/issues/64653


https://reviews.llvm.org/D158695

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/fp-contract-fast-pragma.cpp


Index: clang/test/CodeGen/fp-contract-fast-pragma.cpp
===================================================================
--- clang/test/CodeGen/fp-contract-fast-pragma.cpp
+++ clang/test/CodeGen/fp-contract-fast-pragma.cpp
@@ -5,8 +5,10 @@
 // CHECK: _Z13fp_contract_1fff
 // CHECK: %[[M:.+]] = fmul contract float %a, %b
 // CHECK-NEXT: fadd contract float %[[M]], %c
+// CHECK-NEXT: tail call contract float @llvm.sqrt.f32(float %a)
+
 #pragma clang fp contract(fast)
-  return a * b + c;
+  return a * b + c + __builtin_sqrtf(a);
 }
 
 // Is FP_CONTRACT state cleared on exiting compound statements?
Index: clang/lib/CodeGen/CGBuiltin.cpp
===================================================================
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -495,6 +495,8 @@
                                 unsigned ConstrainedIntrinsicID) {
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(
+      CGF, E->getFPFeaturesInEffect(CGF.getLangOpts()));
   if (CGF.Builder.getIsFPConstrained()) {
     CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
     Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, 
Src0->getType());


Index: clang/test/CodeGen/fp-contract-fast-pragma.cpp
===================================================================
--- clang/test/CodeGen/fp-contract-fast-pragma.cpp
+++ clang/test/CodeGen/fp-contract-fast-pragma.cpp
@@ -5,8 +5,10 @@
 // CHECK: _Z13fp_contract_1fff
 // CHECK: %[[M:.+]] = fmul contract float %a, %b
 // CHECK-NEXT: fadd contract float %[[M]], %c
+// CHECK-NEXT: tail call contract float @llvm.sqrt.f32(float %a)
+
 #pragma clang fp contract(fast)
-  return a * b + c;
+  return a * b + c + __builtin_sqrtf(a);
 }
 
 // Is FP_CONTRACT state cleared on exiting compound statements?
Index: clang/lib/CodeGen/CGBuiltin.cpp
===================================================================
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -495,6 +495,8 @@
                                 unsigned ConstrainedIntrinsicID) {
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(
+      CGF, E->getFPFeaturesInEffect(CGF.getLangOpts()));
   if (CGF.Builder.getIsFPConstrained()) {
     CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
     Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, Src0->getType());
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to