[llvm] r352981 - [InstSimplify] Missed optimization in math expression: log10(pow(10.0, x)) == x, log2(pow(2.0, x)) == x
Dmitry Venikov via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 2 19:48:31 PST 2019
Author: quolyk
Date: Sat Feb 2 19:48:30 2019
New Revision: 352981
URL: http://llvm.org/viewvc/llvm-project?rev=352981&view=rev
Log:
[InstSimplify] Missed optimization in math expression: log10(pow(10.0,x)) == x, log2(pow(2.0,x)) == x
Summary: This patch enables folding following instructions under -ffast-math flag: log10(pow(10.0,x)) -> x, log2(pow(2.0,x)) -> x
Reviewers: hfinkel, spatel, efriedma, craig.topper, zvi, majnemer, lebedev.ri
Reviewed By: spatel, lebedev.ri
Subscribers: lebedev.ri, llvm-commits
Differential Revision: https://reviews.llvm.org/D41940
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/test/Transforms/InstSimplify/log10-pow10-intrinsic.ll
llvm/trunk/test/Transforms/InstSimplify/log2-pow2-intrinsic.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=352981&r1=352980&r2=352981&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Sat Feb 2 19:48:30 2019
@@ -4940,7 +4940,15 @@ static Value *simplifyUnaryIntrinsic(Fun
case Intrinsic::log2:
// log2(exp2(x)) -> x
if (Q.CxtI->hasAllowReassoc() &&
- match(Op0, m_Intrinsic<Intrinsic::exp2>(m_Value(X)))) return X;
+ (match(Op0, m_Intrinsic<Intrinsic::exp2>(m_Value(X))) ||
+ match(Op0, m_Intrinsic<Intrinsic::pow>(m_SpecificFP(2.0),
+ m_Value(X))))) return X;
+ break;
+ case Intrinsic::log10:
+ // log10(pow(10.0, x)) -> x
+ if (Q.CxtI->hasAllowReassoc() &&
+ match(Op0, m_Intrinsic<Intrinsic::pow>(m_SpecificFP(10.0),
+ m_Value(X)))) return X;
break;
default:
break;
Modified: llvm/trunk/test/Transforms/InstSimplify/log10-pow10-intrinsic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/log10-pow10-intrinsic.ll?rev=352981&r1=352980&r2=352981&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/log10-pow10-intrinsic.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/log10-pow10-intrinsic.ll Sat Feb 2 19:48:30 2019
@@ -28,9 +28,7 @@ define double @log10_strict_pow10_reasso
define double @log10_reassoc_pow10_strict(double %x) {
; CHECK-LABEL: @log10_reassoc_pow10_strict(
-; CHECK-NEXT: [[TMP1:%.*]] = call double @llvm.pow.f64(double 1.000000e+01, double [[X:%.*]])
-; CHECK-NEXT: [[TMP2:%.*]] = call reassoc double @llvm.log10.f64(double [[TMP1]])
-; CHECK-NEXT: ret double [[TMP2]]
+; CHECK-NEXT: ret double [[X:%.*]]
;
%tmp = call double @llvm.pow.f64(double 1.000000e+01, double %x)
%tmp1 = call reassoc double @llvm.log10.f64(double %tmp)
@@ -39,9 +37,7 @@ define double @log10_reassoc_pow10_stric
define double @log10_pow10_reassoc(double %x) {
; CHECK-LABEL: @log10_pow10_reassoc(
-; CHECK-NEXT: [[TMP1:%.*]] = call reassoc double @llvm.pow.f64(double 1.000000e+01, double [[X:%.*]])
-; CHECK-NEXT: [[TMP2:%.*]] = call reassoc double @llvm.log10.f64(double [[TMP1]])
-; CHECK-NEXT: ret double [[TMP2]]
+; CHECK-NEXT: ret double [[X:%.*]]
;
%tmp = call reassoc double @llvm.pow.f64(double 1.000000e+01, double %x)
%tmp1 = call reassoc double @llvm.log10.f64(double %tmp)
Modified: llvm/trunk/test/Transforms/InstSimplify/log2-pow2-intrinsic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/log2-pow2-intrinsic.ll?rev=352981&r1=352980&r2=352981&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/log2-pow2-intrinsic.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/log2-pow2-intrinsic.ll Sat Feb 2 19:48:30 2019
@@ -28,9 +28,7 @@ define double @log2_strict_pow2_reassoc(
define double @log2_reassoc_pow2_strict(double %x) {
; CHECK-LABEL: @log2_reassoc_pow2_strict(
-; CHECK-NEXT: [[TMP:%.*]] = call double @llvm.pow.f64(double 2.000000e+00, double [[X:%.*]])
-; CHECK-NEXT: [[TMP1:%.*]] = call reassoc double @llvm.log2.f64(double [[TMP]])
-; CHECK-NEXT: ret double [[TMP1]]
+; CHECK-NEXT: ret double [[X:%.*]]
;
%tmp = call double @llvm.pow.f64(double 2.000000e+00, double %x)
%tmp1 = call reassoc double @llvm.log2.f64(double %tmp)
@@ -39,9 +37,7 @@ define double @log2_reassoc_pow2_strict(
define double @log2_pow2_reassoc(double %x) {
; CHECK-LABEL: @log2_pow2_reassoc(
-; CHECK-NEXT: [[TMP:%.*]] = call reassoc double @llvm.pow.f64(double 2.000000e+00, double [[X:%.*]])
-; CHECK-NEXT: [[TMP1:%.*]] = call reassoc double @llvm.log2.f64(double [[TMP]])
-; CHECK-NEXT: ret double [[TMP1]]
+; CHECK-NEXT: ret double [[X:%.*]]
;
%tmp = call reassoc double @llvm.pow.f64(double 2.000000e+00, double %x)
%tmp1 = call reassoc double @llvm.log2.f64(double %tmp)
More information about the llvm-commits
mailing list