[llvm] r339618 - [SimplifyLibCalls] don't drop fast-math-flags on trig reflection folds (retry r339608)
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 13 14:49:19 PDT 2018
Author: spatel
Date: Mon Aug 13 14:49:19 2018
New Revision: 339618
URL: http://llvm.org/viewvc/llvm-project?rev=339618&view=rev
Log:
[SimplifyLibCalls] don't drop fast-math-flags on trig reflection folds (retry r339608)
Even though this code is below a function called optimizeFloatingPointLibCall(),
we apparently can't guarantee that we're dealing with FPMathOperators, so bail
out immediately if that's not true.
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/trunk/test/Transforms/InstCombine/cos-1.ll
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=339618&r1=339617&r2=339618&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Mon Aug 13 14:49:19 2018
@@ -1124,7 +1124,12 @@ Value *LibCallSimplifier::optimizeCAbs(C
static Value *optimizeTrigReflections(CallInst *Call, LibFunc Func,
IRBuilder<> &B) {
- // FIXME: This drops FMF.
+ if (!isa<FPMathOperator>(Call))
+ return nullptr;
+
+ IRBuilder<>::FastMathFlagGuard Guard(B);
+ B.setFastMathFlags(Call->getFastMathFlags());
+
// TODO: Add tan() and other calls.
// TODO: Can this be shared to also handle LLVM intrinsics?
Value *X;
Modified: llvm/trunk/test/Transforms/InstCombine/cos-1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/cos-1.ll?rev=339618&r1=339617&r2=339618&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/cos-1.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/cos-1.ll Mon Aug 13 14:49:19 2018
@@ -40,7 +40,7 @@ define float @cosf_negated_arg(float %x)
define float @cosf_negated_arg_FMF(float %x) {
; ANY-LABEL: @cosf_negated_arg_FMF(
-; ANY-NEXT: [[COS:%.*]] = call float @cosf(float [[X:%.*]])
+; ANY-NEXT: [[COS:%.*]] = call reassoc nnan float @cosf(float [[X:%.*]])
; ANY-NEXT: ret float [[COS]]
;
%neg = fsub float -0.0, %x
@@ -72,6 +72,17 @@ define float @sinf_negated_arg(float %x)
ret float %r
}
+define float @sinf_negated_arg_FMF(float %x) {
+; ANY-LABEL: @sinf_negated_arg_FMF(
+; ANY-NEXT: [[SIN:%.*]] = call nnan afn float @sinf(float [[X:%.*]])
+; ANY-NEXT: [[TMP1:%.*]] = fsub nnan afn float -0.000000e+00, [[SIN]]
+; ANY-NEXT: ret float [[TMP1]]
+;
+ %neg = fsub ninf float -0.0, %x
+ %r = call afn nnan float @sinf(float %neg)
+ ret float %r
+}
+
declare void @use(double)
define double @sin_negated_arg_extra_use(double %x) {
More information about the llvm-commits
mailing list