[llvm] [NFC] Turn the StrictFP attribute check to a CompatRule. (PR #82600)

via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 22 08:33:06 PST 2024


https://github.com/DanielKristofKiss updated https://github.com/llvm/llvm-project/pull/82600

>From 2b4dfb10614708f16ecbfdeaf908fc6133f897b1 Mon Sep 17 00:00:00 2001
From: Daniel Kiss <daniel.kiss at arm.com>
Date: Thu, 22 Feb 2024 08:57:50 +0100
Subject: [PATCH 1/3] [NFC] Turn the StrictFP attribute check to a CompatRule.

---
 llvm/include/llvm/IR/Attributes.td           | 2 +-
 llvm/lib/IR/Attributes.cpp                   | 7 +++++++
 llvm/lib/Transforms/Utils/InlineFunction.cpp | 7 -------
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/llvm/include/llvm/IR/Attributes.td b/llvm/include/llvm/IR/Attributes.td
index 864f87f3383891..135eb09709313c 100644
--- a/llvm/include/llvm/IR/Attributes.td
+++ b/llvm/include/llvm/IR/Attributes.td
@@ -359,7 +359,7 @@ def : CompatRule<"isEqual<ShadowCallStackAttr>">;
 def : CompatRule<"isEqual<UseSampleProfileAttr>">;
 def : CompatRule<"isEqual<NoProfileAttr>">;
 def : CompatRule<"checkDenormMode">;
-
+def : CompatRule<"checkStrictFP">;
 
 class MergeRule<string F> {
   // The name of the function called to merge the attributes of the caller and
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index fd5160209506f2..e6ffb231efbf42 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -2039,6 +2039,13 @@ static bool checkDenormMode(const Function &Caller, const Function &Callee) {
   return false;
 }
 
+static bool checkStrictFP(const Function &Caller, const Function &Callee) {
+  // Do not inline strictfp function into non-strictfp one. It would require
+  // conversion of all FP operations in host function to constrained intrinsics.
+  return !(Callee.getAttributes().hasFnAttr(Attribute::StrictFP) &&
+           !Caller.getAttributes().hasFnAttr(Attribute::StrictFP));
+}
+
 template<typename AttrClass>
 static bool isEqual(const Function &Caller, const Function &Callee) {
   return Caller.getFnAttribute(AttrClass::getKind()) ==
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index d4d4bf5ebdf36e..6ea68497d7a6ed 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -2103,13 +2103,6 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
   BasicBlock *OrigBB = CB.getParent();
   Function *Caller = OrigBB->getParent();
 
-  // Do not inline strictfp function into non-strictfp one. It would require
-  // conversion of all FP operations in host function to constrained intrinsics.
-  if (CalledFunc->getAttributes().hasFnAttr(Attribute::StrictFP) &&
-      !Caller->getAttributes().hasFnAttr(Attribute::StrictFP)) {
-    return InlineResult::failure("incompatible strictfp attributes");
-  }
-
   // GC poses two hazards to inlining, which only occur when the callee has GC:
   //  1. If the caller has no GC, then the callee's GC must be propagated to the
   //     caller.

>From ba303f99f0259c2f77ef572522122bd24cca6245 Mon Sep 17 00:00:00 2001
From: Daniel Kiss <daniel.kiss at arm.com>
Date: Thu, 22 Feb 2024 17:27:12 +0100
Subject: [PATCH 2/3] Address review comments.

---
 llvm/lib/IR/Attributes.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index e6ffb231efbf42..ea2ec0145e7164 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -2042,8 +2042,8 @@ static bool checkDenormMode(const Function &Caller, const Function &Callee) {
 static bool checkStrictFP(const Function &Caller, const Function &Callee) {
   // Do not inline strictfp function into non-strictfp one. It would require
   // conversion of all FP operations in host function to constrained intrinsics.
-  return !(Callee.getAttributes().hasFnAttr(Attribute::StrictFP) &&
-           !Caller.getAttributes().hasFnAttr(Attribute::StrictFP));
+  return !Callee.getAttributes().hasFnAttr(Attribute::StrictFP) ||
+           Caller.getAttributes().hasFnAttr(Attribute::StrictFP);
 }
 
 template<typename AttrClass>

>From 255eca09b39c104f092335e4442f330d3c2ad0b9 Mon Sep 17 00:00:00 2001
From: Daniel Kiss <daniel.kiss at arm.com>
Date: Thu, 22 Feb 2024 17:32:36 +0100
Subject: [PATCH 3/3] clang-format.

---
 llvm/lib/IR/Attributes.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index ea2ec0145e7164..077780881ff252 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -2043,7 +2043,7 @@ static bool checkStrictFP(const Function &Caller, const Function &Callee) {
   // Do not inline strictfp function into non-strictfp one. It would require
   // conversion of all FP operations in host function to constrained intrinsics.
   return !Callee.getAttributes().hasFnAttr(Attribute::StrictFP) ||
-           Caller.getAttributes().hasFnAttr(Attribute::StrictFP);
+         Caller.getAttributes().hasFnAttr(Attribute::StrictFP);
 }
 
 template<typename AttrClass>



More information about the llvm-commits mailing list