[llvm] r322284 - [InstCombine] For cos/sin -> tan copy attributes from cos instead of the

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 11 07:19:02 PST 2018


Author: d0k
Date: Thu Jan 11 07:19:02 2018
New Revision: 322284

URL: http://llvm.org/viewvc/llvm-project?rev=322284&view=rev
Log:
[InstCombine] For cos/sin -> tan copy attributes from cos instead of the
parent function

Ideally we should merge the attributes from the functions somehow, but
this is obviously an improvement over taking random attributes from the
caller which will trip up the verifier if they're nonsensical for an
unary intrinsic call.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
    llvm/trunk/test/Transforms/InstCombine/fdiv-cos-sin.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=322284&r1=322283&r2=322284&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Thu Jan 11 07:19:02 2018
@@ -1494,8 +1494,9 @@ Instruction *InstCombiner::visitFDiv(Bin
         IRBuilder<> B(&I);
         IRBuilder<>::FastMathFlagGuard Guard(B);
         B.setFastMathFlags(I.getFastMathFlags());
-        Value *Tan = emitUnaryFloatFnCall(A, TLI.getName(LibFunc_tan),
-                                          B, I.getFunction()->getAttributes());
+        Value *Tan = emitUnaryFloatFnCall(
+            A, TLI.getName(LibFunc_tan), B,
+            CallSite(Op0).getCalledFunction()->getAttributes());
         Value *One = ConstantFP::get(Tan->getType(), 1.0);
         Value *Div = B.CreateFDiv(One, Tan);
         return replaceInstUsesWith(I, Div);

Modified: llvm/trunk/test/Transforms/InstCombine/fdiv-cos-sin.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fdiv-cos-sin.ll?rev=322284&r1=322283&r2=322284&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fdiv-cos-sin.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fdiv-cos-sin.ll Thu Jan 11 07:19:02 2018
@@ -27,9 +27,9 @@ define double @fdiv_strict_cos_strict_si
   ret double %div
 }
 
-define double @fdiv_fast_cos_strict_sin_strict(double %a) {
+define double @fdiv_fast_cos_strict_sin_strict(double %a, i32* dereferenceable(2) %dummy) {
 ; CHECK-LABEL: @fdiv_fast_cos_strict_sin_strict(
-; CHECK-NEXT:    [[TAN:%.*]] = call fast double @tan(double [[A:%.*]])
+; CHECK-NEXT:    [[TAN:%.*]] = call fast double @tan(double [[A:%.*]]) #1
 ; CHECK-NEXT:    [[TMP1:%.*]] = fdiv fast double 1.000000e+00, [[TAN]]
 ; CHECK-NEXT:    ret double [[TMP1]]
 ;
@@ -41,7 +41,7 @@ define double @fdiv_fast_cos_strict_sin_
 
 define double @fdiv_fast_cos_fast_sin_strict(double %a) {
 ; CHECK-LABEL: @fdiv_fast_cos_fast_sin_strict(
-; CHECK-NEXT:    [[TAN:%.*]] = call fast double @tan(double [[A:%.*]])
+; CHECK-NEXT:    [[TAN:%.*]] = call fast double @tan(double [[A:%.*]]) #1
 ; CHECK-NEXT:    [[TMP1:%.*]] = fdiv fast double 1.000000e+00, [[TAN]]
 ; CHECK-NEXT:    ret double [[TMP1]]
 ;
@@ -68,7 +68,7 @@ define double @fdiv_cos_sin_fast_multipl
 
 define double @fdiv_cos_sin_fast(double %a) {
 ; CHECK-LABEL: @fdiv_cos_sin_fast(
-; CHECK-NEXT:    [[TAN:%.*]] = call fast double @tan(double [[A:%.*]])
+; CHECK-NEXT:    [[TAN:%.*]] = call fast double @tan(double [[A:%.*]]) #1
 ; CHECK-NEXT:    [[TMP1:%.*]] = fdiv fast double 1.000000e+00, [[TAN]]
 ; CHECK-NEXT:    ret double [[TMP1]]
 ;
@@ -80,7 +80,7 @@ define double @fdiv_cos_sin_fast(double
 
 define float @fdiv_cosf_sinf_fast(float %a) {
 ; CHECK-LABEL: @fdiv_cosf_sinf_fast(
-; CHECK-NEXT:    [[TANF:%.*]] = call fast float @tanf(float [[A:%.*]])
+; CHECK-NEXT:    [[TANF:%.*]] = call fast float @tanf(float [[A:%.*]]) #1
 ; CHECK-NEXT:    [[TMP1:%.*]] = fdiv fast float 1.000000e+00, [[TANF]]
 ; CHECK-NEXT:    ret float [[TMP1]]
 ;
@@ -92,7 +92,7 @@ define float @fdiv_cosf_sinf_fast(float
 
 define fp128 @fdiv_cosfp128_sinfp128_fast(fp128 %a) {
 ; CHECK-LABEL: @fdiv_cosfp128_sinfp128_fast(
-; CHECK-NEXT:    [[TANL:%.*]] = call fast fp128 @tanl(fp128 [[A:%.*]])
+; CHECK-NEXT:    [[TANL:%.*]] = call fast fp128 @tanl(fp128 [[A:%.*]]) #1
 ; CHECK-NEXT:    [[TMP1:%.*]] = fdiv fast fp128 0xL00000000000000003FFF000000000000, [[TANL]]
 ; CHECK-NEXT:    ret fp128 [[TMP1]]
 ;
@@ -102,12 +102,15 @@ define fp128 @fdiv_cosfp128_sinfp128_fas
   ret fp128 %div
 }
 
-declare double @llvm.cos.f64(double)
-declare float @llvm.cos.f32(float)
-declare fp128 @llvm.cos.fp128(fp128)
-
-declare double @llvm.sin.f64(double)
-declare float @llvm.sin.f32(float)
-declare fp128 @llvm.sin.fp128(fp128)
+declare double @llvm.cos.f64(double) #1
+declare float @llvm.cos.f32(float) #1
+declare fp128 @llvm.cos.fp128(fp128) #1
+
+declare double @llvm.sin.f64(double) #1
+declare float @llvm.sin.f32(float) #1
+declare fp128 @llvm.sin.fp128(fp128) #1
 
 declare void @use(double)
+
+attributes #0 = { nounwind readnone speculatable }
+attributes #1 = { nounwind readnone }




More information about the llvm-commits mailing list