diff options
| author | Dmitry Venikov <quolyk@gmail.com> | 2019-02-03 03:48:30 +0000 |
|---|---|---|
| committer | Dmitry Venikov <quolyk@gmail.com> | 2019-02-03 03:48:30 +0000 |
| commit | aaa709f2ece1986436c328ce66c05ad509e369f8 (patch) | |
| tree | d9cf8426e398c66dcf12023e4b9b9e017d581c96 | |
| parent | 24a2a48bc2e042ca9684d5dfb71e4a28a12a32b0 (diff) | |
| download | bcm5719-llvm-aaa709f2ece1986436c328ce66c05ad509e369f8.tar.gz bcm5719-llvm-aaa709f2ece1986436c328ce66c05ad509e369f8.zip | |
[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
llvm-svn: 352981
| -rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 10 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstSimplify/log10-pow10-intrinsic.ll | 8 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstSimplify/log2-pow2-intrinsic.ll | 8 |
3 files changed, 13 insertions, 13 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index ed3ba7778a0..c83d62f1542 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -4940,7 +4940,15 @@ static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0, 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; diff --git a/llvm/test/Transforms/InstSimplify/log10-pow10-intrinsic.ll b/llvm/test/Transforms/InstSimplify/log10-pow10-intrinsic.ll index f0ffbf49b9a..a5b7afde1a8 100644 --- a/llvm/test/Transforms/InstSimplify/log10-pow10-intrinsic.ll +++ b/llvm/test/Transforms/InstSimplify/log10-pow10-intrinsic.ll @@ -28,9 +28,7 @@ define double @log10_strict_pow10_reassoc(double %x) { 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_strict(double %x) { 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) diff --git a/llvm/test/Transforms/InstSimplify/log2-pow2-intrinsic.ll b/llvm/test/Transforms/InstSimplify/log2-pow2-intrinsic.ll index 519db518a4a..8d8ef80db72 100644 --- a/llvm/test/Transforms/InstSimplify/log2-pow2-intrinsic.ll +++ b/llvm/test/Transforms/InstSimplify/log2-pow2-intrinsic.ll @@ -28,9 +28,7 @@ define double @log2_strict_pow2_reassoc(double %x) { 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(double %x) { 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) |

