[PATCH] D157895: InstSimplify: Handle log10(exp10(x))

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 14 08:47:46 PDT 2023


arsenm created this revision.
arsenm added reviewers: jcranmer-intel, foad, kpn, andrew.w.kaylor, sepavloff.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

Copied from the exp/exp2 cases


https://reviews.llvm.org/D157895

Files:
  llvm/lib/Analysis/InstructionSimplify.cpp
  llvm/test/Transforms/InstSimplify/log-exp-intrinsic.ll


Index: llvm/test/Transforms/InstSimplify/log-exp-intrinsic.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/log-exp-intrinsic.ll
+++ llvm/test/Transforms/InstSimplify/log-exp-intrinsic.ll
@@ -194,9 +194,7 @@
 
 define double @log10_reassoc_exp10_strict(double %a) {
 ; CHECK-LABEL: @log10_reassoc_exp10_strict(
-; CHECK-NEXT:    [[TMP1:%.*]] = call double @llvm.exp10.f64(double [[A:%.*]])
-; CHECK-NEXT:    [[TMP2:%.*]] = call reassoc double @llvm.log10.f64(double [[TMP1]])
-; CHECK-NEXT:    ret double [[TMP2]]
+; CHECK-NEXT:    ret double [[A:%.*]]
 ;
   %1 = call double @llvm.exp10.f64(double %a)
   %2 = call reassoc double @llvm.log10.f64(double %1)
@@ -231,11 +229,7 @@
 
 define double @log10_exp10_log10_exp10_reassoc(double %a) {
 ; CHECK-LABEL: @log10_exp10_log10_exp10_reassoc(
-; CHECK-NEXT:    [[TMP1:%.*]] = call double @llvm.exp10.f64(double [[A:%.*]])
-; CHECK-NEXT:    [[TMP2:%.*]] = call reassoc double @llvm.log10.f64(double [[TMP1]])
-; CHECK-NEXT:    [[TMP3:%.*]] = call double @llvm.exp10.f64(double [[TMP2]])
-; CHECK-NEXT:    [[TMP4:%.*]] = call reassoc double @llvm.log10.f64(double [[TMP3]])
-; CHECK-NEXT:    ret double [[TMP4]]
+; CHECK-NEXT:    ret double [[A:%.*]]
 ;
   %1 = call double @llvm.exp10.f64(double %a)
   %2 = call reassoc double @llvm.log10.f64(double %1)
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -6175,8 +6175,11 @@
     break;
   case Intrinsic::log10:
     // log10(pow(10.0, x)) -> x
+    // log10(exp10(x)) -> x
     if (Q.CxtI->hasAllowReassoc() &&
-        match(Op0, m_Intrinsic<Intrinsic::pow>(m_SpecificFP(10.0), m_Value(X))))
+        (match(Op0, m_Intrinsic<Intrinsic::exp10>(m_Value(X))) ||
+         match(Op0,
+               m_Intrinsic<Intrinsic::pow>(m_SpecificFP(10.0), m_Value(X)))))
       return X;
     break;
   case Intrinsic::experimental_vector_reverse:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157895.549974.patch
Type: text/x-patch
Size: 2059 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230814/407dd1db/attachment.bin>


More information about the llvm-commits mailing list