[llvm] 99e9585 - [PartiallyInlineLibCalls] Disable sqrt expansion for strictfp.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 17 14:15:20 PDT 2021


Author: Craig Topper
Date: 2021-06-17T14:15:12-07:00
New Revision: 99e95856fb785cb22d898e963a54e8d9a8459fc7

URL: https://github.com/llvm/llvm-project/commit/99e95856fb785cb22d898e963a54e8d9a8459fc7
DIFF: https://github.com/llvm/llvm-project/commit/99e95856fb785cb22d898e963a54e8d9a8459fc7.diff

LOG: [PartiallyInlineLibCalls] Disable sqrt expansion for strictfp.

This pass emits a floating point compare and a conditional branch,
but if strictfp is enabled we don't emit a constrained compare
intrinsic.

The backend also won't expand the readonly sqrt call this pass inserts
to a sqrt instruction under strictfp. So we end up with 2 libcalls as
seen here. https://godbolt.org/z/oax5zMEWd

Fix these things by disabling the pass.

Differential Revision: https://reviews.llvm.org/D104479

Added: 
    llvm/test/Transforms/PartiallyInlineLibCalls/strictfp.ll

Modified: 
    llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
index c1d8a2c398ece..7872c553b412c 100644
--- a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
+++ b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
@@ -121,7 +121,7 @@ static bool runPartiallyInlineLibCalls(Function &F, TargetLibraryInfo *TLI,
       if (!Call || !(CalledFunc = Call->getCalledFunction()))
         continue;
 
-      if (Call->isNoBuiltin())
+      if (Call->isNoBuiltin() || Call->isStrictFP())
         continue;
 
       // Skip if function either has local linkage or is not a known library

diff  --git a/llvm/test/Transforms/PartiallyInlineLibCalls/strictfp.ll b/llvm/test/Transforms/PartiallyInlineLibCalls/strictfp.ll
new file mode 100644
index 0000000000000..b4c5f605e6769
--- /dev/null
+++ b/llvm/test/Transforms/PartiallyInlineLibCalls/strictfp.ll
@@ -0,0 +1,12 @@
+; RUN: opt -S -partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
+; RUN: opt -S -passes=partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
+
+define float @f(float %val) strictfp {
+; CHECK-LABEL: @f
+; CHECK: call{{.*}}@sqrtf
+; CHECK-NOT: call{{.*}}@sqrtf
+  %res = tail call float @sqrtf(float %val) strictfp
+  ret float %res
+}
+
+declare float @sqrtf(float)


        


More information about the llvm-commits mailing list