[PATCH] D130311: [RISCV] Enable strict FP in clang as long as Zve* or V are not enabled.

Craig Topper via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 21 15:01:59 PDT 2022


craig.topper created this revision.
craig.topper added reviewers: reames, asb, luismarques, arcbbb, frasercrmck, kito-cheng.
Herald added subscribers: sunshaoce, VincentWu, luke957, StephenFan, vkmr, evandro, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: pcwang-thead, eopXD, MaskRay.
Herald added projects: clang, LLVM.

As far as I know, scalar support for strict FP in the backend is
complete. Unfortunately, vector is missing.

This patch enables strict FP support as long as there's no chance
of any vector code. This isn't ideal, but it's a start.

Given the proximity to the LLVM 15 branch, I don't intend to commit this
until after that if this is approved.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130311

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/test/CodeGen/builtin_float_strictfp.c
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp


Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -928,6 +928,10 @@
     }
   }
 
+  // FIXME: Strict FP support is incomplete for vectors.
+  if (!Subtarget.hasVInstructions())
+    IsStrictFPEnabled = true;
+
   // Function alignments.
   const Align FunctionAlignment(Subtarget.hasStdExtC() ? 2 : 4);
   setMinFunctionAlignment(FunctionAlignment);
Index: clang/test/CodeGen/builtin_float_strictfp.c
===================================================================
--- clang/test/CodeGen/builtin_float_strictfp.c
+++ clang/test/CodeGen/builtin_float_strictfp.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple x86_64-windows-pc -ffp-exception-behavior=maytrap -o - %s | FileCheck %s --check-prefixes=CHECK,FP16
 // RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple ppc64-be -ffp-exception-behavior=maytrap -o - %s | FileCheck %s --check-prefixes=CHECK,NOFP16
+// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple riscv64 -ffp-exception-behavior=maytrap -o - %s | FileCheck %s --check-prefixes=CHECK,FP16
 
 // test to ensure that these builtins don't do the variadic promotion of float->double.
 
Index: clang/lib/Basic/Targets/RISCV.h
===================================================================
--- clang/lib/Basic/Targets/RISCV.h
+++ clang/lib/Basic/Targets/RISCV.h
@@ -41,6 +41,7 @@
     HasRISCVVTypes = true;
     MCountName = "_mcount";
     HasFloat16 = true;
+    HasStrictFP = true;
   }
 
   bool setCPU(const std::string &Name) override {
Index: clang/lib/Basic/Targets/RISCV.cpp
===================================================================
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -282,6 +282,10 @@
   if (ABI.empty())
     ABI = ISAInfo->computeDefaultABI().str();
 
+  // StrictFP support for vectors is incomplete.
+  if (ISAInfo->hasExtension("zve32x"))
+    HasStrictFP = false;
+
   return true;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130311.446645.patch
Type: text/x-patch
Size: 2081 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220721/c4556395/attachment-0001.bin>


More information about the cfe-commits mailing list