[PATCH] D158695: [clang] Fix missing contract flag in sqrt intrinsic

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 23 20:46:55 PDT 2023


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());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158695.552970.patch
Type: text/x-patch
Size: 1219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230824/41e6aaec/attachment-0001.bin>


More information about the cfe-commits mailing list