[llvm] r339958 - [InstCombine] add reflection fold for tan(-x)
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 16 15:46:20 PDT 2018
Author: spatel
Date: Thu Aug 16 15:46:20 2018
New Revision: 339958
URL: http://llvm.org/viewvc/llvm-project?rev=339958&view=rev
Log:
[InstCombine] add reflection fold for tan(-x)
This is a follow-up suggested with rL339604.
For tan(), we don't have a corresponding LLVM
intrinsic -- unlike sin/cos -- so this is the
only way/place that we can do this fold currently.
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=339958&r1=339957&r2=339958&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Thu Aug 16 15:46:20 2018
@@ -1130,16 +1130,19 @@ static Value *optimizeTrigReflections(Ca
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;
switch (Func) {
case LibFunc_sin:
case LibFunc_sinf:
case LibFunc_sinl:
+ case LibFunc_tan:
+ case LibFunc_tanf:
+ case LibFunc_tanl:
// sin(-X) --> -sin(X)
+ // tan(-X) --> -tan(X)
if (match(Call->getArgOperand(0), m_OneUse(m_FNeg(m_Value(X)))))
- return B.CreateFNeg(B.CreateCall(Call->getCalledFunction(), X, "sin"));
+ return B.CreateFNeg(B.CreateCall(Call->getCalledFunction(), X));
break;
case LibFunc_cos:
case LibFunc_cosf:
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=339958&r1=339957&r2=339958&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/cos-1.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/cos-1.ll Thu Aug 16 15:46:20 2018
@@ -117,9 +117,9 @@ define double @neg_sin_negated_arg(doubl
define double @tan_negated_arg(double %x) {
; ANY-LABEL: @tan_negated_arg(
-; ANY-NEXT: [[NEG:%.*]] = fsub double -0.000000e+00, [[X:%.*]]
-; ANY-NEXT: [[R:%.*]] = call double @tan(double [[NEG]])
-; ANY-NEXT: ret double [[R]]
+; ANY-NEXT: [[TMP1:%.*]] = call double @tan(double [[X:%.*]])
+; ANY-NEXT: [[TMP2:%.*]] = fsub double -0.000000e+00, [[TMP1]]
+; ANY-NEXT: ret double [[TMP2]]
;
%neg = fsub double -0.0, %x
%r = call double @tan(double %neg)
@@ -130,9 +130,9 @@ define double @tan_negated_arg(double %x
define fp128 @tanl_negated_arg(fp128 %x) {
; ANY-LABEL: @tanl_negated_arg(
-; ANY-NEXT: [[NEG:%.*]] = fsub fp128 0xL00000000000000008000000000000000, [[X:%.*]]
-; ANY-NEXT: [[R:%.*]] = call fp128 @tanl(fp128 [[NEG]])
-; ANY-NEXT: ret fp128 [[R]]
+; ANY-NEXT: [[TMP1:%.*]] = call fp128 @tanl(fp128 [[X:%.*]])
+; ANY-NEXT: [[TMP2:%.*]] = fsub fp128 0xL00000000000000008000000000000000, [[TMP1]]
+; ANY-NEXT: ret fp128 [[TMP2]]
;
%neg = fsub fp128 0xL00000000000000008000000000000000, %x
%r = call fp128 @tanl(fp128 %neg)
More information about the llvm-commits
mailing list