[PATCH] D41940: [InstSimplify] Missed optimization in math expression: log10(pow(10.0, x)) == x, log2(pow(2.0, x)) == x
Dmitry Venikov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 2 19:48:23 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL352981: [InstSimplify] Missed optimization in math expression: log10(pow(10.0,x)) == x… (authored by Quolyk, committed by ).
Herald added a project: LLVM.
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D41940/new/
https://reviews.llvm.org/D41940
Files:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/test/Transforms/InstSimplify/log10-pow10-intrinsic.ll
llvm/trunk/test/Transforms/InstSimplify/log2-pow2-intrinsic.ll
Index: llvm/trunk/test/Transforms/InstSimplify/log2-pow2-intrinsic.ll
===================================================================
--- llvm/trunk/test/Transforms/InstSimplify/log2-pow2-intrinsic.ll
+++ llvm/trunk/test/Transforms/InstSimplify/log2-pow2-intrinsic.ll
@@ -28,9 +28,7 @@
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_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)
Index: llvm/trunk/test/Transforms/InstSimplify/log10-pow10-intrinsic.ll
===================================================================
--- llvm/trunk/test/Transforms/InstSimplify/log10-pow10-intrinsic.ll
+++ llvm/trunk/test/Transforms/InstSimplify/log10-pow10-intrinsic.ll
@@ -28,9 +28,7 @@
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_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)
Index: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp
@@ -4940,7 +4940,15 @@
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41940.184926.patch
Type: text/x-patch
Size: 3496 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190203/a2c34ac1/attachment.bin>
More information about the llvm-commits
mailing list