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

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 24 08:23:19 PDT 2023


yaxunl updated this revision to Diff 553141.
yaxunl marked 3 inline comments as done.
yaxunl added a comment.

revised by comments


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158695/new/

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
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -O3 -triple %itanium_abi_triple -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fexperimental-strict-floating-point -O3 \
+// RUN:   -triple %itanium_abi_triple -emit-llvm -o - %s | FileCheck %s
 
 // Is FP_CONTRACT honored in a simple case?
 float fp_contract_1(float a, float b, float c) {
@@ -67,3 +69,18 @@
   // CHECK-NEXT: fadd float %[[M]], %c
   return a * b + c;
 }
+
+
+#pragma clang fp contract(fast)
+float fp_contract_7(float a) {
+// CHECK: _Z13fp_contract_7f
+// CHECK: tail call contract float @llvm.sqrt.f32(float %a)
+  return __builtin_sqrtf(a);
+}
+
+float fp_contract_8(float a) {
+// CHECK: _Z13fp_contract_8f
+// CHECK: tail call float @llvm.sqrt.f32(float %a)
+#pragma clang fp contract(off)
+  return __builtin_sqrtf(a);
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===================================================================
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -495,8 +495,8 @@
                                 unsigned ConstrainedIntrinsicID) {
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   if (CGF.Builder.getIsFPConstrained()) {
-    CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
     Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, Src0->getType());
     return CGF.Builder.CreateConstrainedFPCall(F, { Src0 });
   } else {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158695.553141.patch
Type: text/x-patch
Size: 1655 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230824/87459cdc/attachment.bin>


More information about the cfe-commits mailing list