[llvm] r324967 - [InstSimplify] allow exp/log simplifications with only 'reassoc' FMF
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 12 15:51:23 PST 2018
Author: spatel
Date: Mon Feb 12 15:51:23 2018
New Revision: 324967
URL: http://llvm.org/viewvc/llvm-project?rev=324967&view=rev
Log:
[InstSimplify] allow exp/log simplifications with only 'reassoc' FMF
These intrinsic folds were added with D41381, but only allowed with isFast().
That's more than necessary because FMF has 'reassoc' to apply to these
kinds of folds after D39304, and that's all we need in these cases.
Differential Revision: https://reviews.llvm.org/D43160
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/test/Transforms/InstSimplify/log-exp-intrinsic.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=324967&r1=324966&r2=324967&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Mon Feb 12 15:51:23 2018
@@ -4571,28 +4571,28 @@ static Value *SimplifyIntrinsic(Function
}
case Intrinsic::exp: {
// exp(log(x)) -> x
- if (Q.CxtI->isFast() &&
+ if (Q.CxtI->hasAllowReassoc() &&
match(IIOperand, m_Intrinsic<Intrinsic::log>(m_Value(X))))
return X;
return nullptr;
}
case Intrinsic::exp2: {
// exp2(log2(x)) -> x
- if (Q.CxtI->isFast() &&
+ if (Q.CxtI->hasAllowReassoc() &&
match(IIOperand, m_Intrinsic<Intrinsic::log2>(m_Value(X))))
return X;
return nullptr;
}
case Intrinsic::log: {
// log(exp(x)) -> x
- if (Q.CxtI->isFast() &&
+ if (Q.CxtI->hasAllowReassoc() &&
match(IIOperand, m_Intrinsic<Intrinsic::exp>(m_Value(X))))
return X;
return nullptr;
}
case Intrinsic::log2: {
// log2(exp2(x)) -> x
- if (Q.CxtI->isFast() &&
+ if (Q.CxtI->hasAllowReassoc() &&
match(IIOperand, m_Intrinsic<Intrinsic::exp2>(m_Value(X)))) {
return X;
}
Modified: llvm/trunk/test/Transforms/InstSimplify/log-exp-intrinsic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/log-exp-intrinsic.ll?rev=324967&r1=324966&r2=324967&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/log-exp-intrinsic.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/log-exp-intrinsic.ll Mon Feb 12 15:51:23 2018
@@ -3,23 +3,25 @@
declare double @llvm.log.f64(double)
declare double @llvm.exp.f64(double)
+declare double @llvm.log2.f64(double)
+declare double @llvm.exp2.f64(double)
-define double @log_fast_exp_strict(double %a) {
-; CHECK-LABEL: @log_fast_exp_strict(
+define double @log_reassoc_exp_strict(double %a) {
+; CHECK-LABEL: @log_reassoc_exp_strict(
; CHECK-NEXT: ret double [[A:%.*]]
;
%1 = call double @llvm.exp.f64(double %a)
- %2 = call fast double @llvm.log.f64(double %1)
+ %2 = call reassoc double @llvm.log.f64(double %1)
ret double %2
}
-define double @log_strict_exp_fast(double %a) {
-; CHECK-LABEL: @log_strict_exp_fast(
-; CHECK-NEXT: [[TMP1:%.*]] = call fast double @llvm.exp.f64(double [[A:%.*]])
+define double @log_strict_exp_reassoc(double %a) {
+; CHECK-LABEL: @log_strict_exp_reassoc(
+; CHECK-NEXT: [[TMP1:%.*]] = call reassoc double @llvm.exp.f64(double [[A:%.*]])
; CHECK-NEXT: [[TMP2:%.*]] = call double @llvm.log.f64(double [[TMP1]])
; CHECK-NEXT: ret double [[TMP2]]
;
- %1 = call fast double @llvm.exp.f64(double %a)
+ %1 = call reassoc double @llvm.exp.f64(double %a)
%2 = call double @llvm.log.f64(double %1)
ret double %2
}
@@ -39,36 +41,33 @@ define double @log_exp_log_exp(double %a
ret double %4
}
-define double @log_exp_log_exp_fast(double %a) {
-; CHECK-LABEL: @log_exp_log_exp_fast(
+define double @log_exp_log_exp_reassoc(double %a) {
+; CHECK-LABEL: @log_exp_log_exp_reassoc(
; CHECK-NEXT: ret double [[A:%.*]]
;
%1 = call double @llvm.exp.f64(double %a)
- %2 = call fast double @llvm.log.f64(double %1)
+ %2 = call reassoc double @llvm.log.f64(double %1)
%3 = call double @llvm.exp.f64(double %2)
- %4 = call fast double @llvm.log.f64(double %3)
+ %4 = call reassoc double @llvm.log.f64(double %3)
ret double %4
}
-declare double @llvm.log2.f64(double)
-declare double @llvm.exp2.f64(double)
-
-define double @log2_fast_exp2_strict(double %a) {
-; CHECK-LABEL: @log2_fast_exp2_strict(
+define double @log2_reassoc_exp2_strict(double %a) {
+; CHECK-LABEL: @log2_reassoc_exp2_strict(
; CHECK-NEXT: ret double [[A:%.*]]
;
%1 = call double @llvm.exp2.f64(double %a)
- %2 = call fast double @llvm.log2.f64(double %1)
+ %2 = call reassoc double @llvm.log2.f64(double %1)
ret double %2
}
-define double @log2_strict_exp2_fast(double %a) {
-; CHECK-LABEL: @log2_strict_exp2_fast(
-; CHECK-NEXT: [[TMP1:%.*]] = call fast double @llvm.exp2.f64(double [[A:%.*]])
+define double @log2_strict_exp2_reassoc(double %a) {
+; CHECK-LABEL: @log2_strict_exp2_reassoc(
+; CHECK-NEXT: [[TMP1:%.*]] = call reassoc double @llvm.exp2.f64(double [[A:%.*]])
; CHECK-NEXT: [[TMP2:%.*]] = call double @llvm.log2.f64(double [[TMP1]])
; CHECK-NEXT: ret double [[TMP2]]
;
- %1 = call fast double @llvm.exp2.f64(double %a)
+ %1 = call reassoc double @llvm.exp2.f64(double %a)
%2 = call double @llvm.log2.f64(double %1)
ret double %2
}
@@ -88,33 +87,33 @@ define double @log2_exp2_log2_exp2(doubl
ret double %4
}
-define double @log2_exp2_log2_exp2_fast(double %a) {
-; CHECK-LABEL: @log2_exp2_log2_exp2_fast(
+define double @log2_exp2_log2_exp2_reassoc(double %a) {
+; CHECK-LABEL: @log2_exp2_log2_exp2_reassoc(
; CHECK-NEXT: ret double [[A:%.*]]
;
%1 = call double @llvm.exp2.f64(double %a)
- %2 = call fast double @llvm.log2.f64(double %1)
+ %2 = call reassoc double @llvm.log2.f64(double %1)
%3 = call double @llvm.exp2.f64(double %2)
- %4 = call fast double @llvm.log2.f64(double %3)
+ %4 = call reassoc double @llvm.log2.f64(double %3)
ret double %4
}
-define double @exp_fast_log_strict(double %a) {
-; CHECK-LABEL: @exp_fast_log_strict(
+define double @exp_reassoc_log_strict(double %a) {
+; CHECK-LABEL: @exp_reassoc_log_strict(
; CHECK-NEXT: ret double [[A:%.*]]
;
%1 = call double @llvm.log.f64(double %a)
- %2 = call fast double @llvm.exp.f64(double %1)
+ %2 = call reassoc double @llvm.exp.f64(double %1)
ret double %2
}
-define double @exp_strict_log_fast(double %a) {
-; CHECK-LABEL: @exp_strict_log_fast(
-; CHECK-NEXT: [[TMP1:%.*]] = call fast double @llvm.log.f64(double [[A:%.*]])
+define double @exp_strict_log_reassoc(double %a) {
+; CHECK-LABEL: @exp_strict_log_reassoc(
+; CHECK-NEXT: [[TMP1:%.*]] = call reassoc double @llvm.log.f64(double [[A:%.*]])
; CHECK-NEXT: [[TMP2:%.*]] = call double @llvm.exp.f64(double [[TMP1]])
; CHECK-NEXT: ret double [[TMP2]]
;
- %1 = call fast double @llvm.log.f64(double %a)
+ %1 = call reassoc double @llvm.log.f64(double %a)
%2 = call double @llvm.exp.f64(double %1)
ret double %2
}
@@ -134,33 +133,33 @@ define double @exp_log_exp_log(double %a
ret double %4
}
-define double @exp_log_exp_log_fast(double %a) {
-; CHECK-LABEL: @exp_log_exp_log_fast(
+define double @exp_log_exp_log_reassoc(double %a) {
+; CHECK-LABEL: @exp_log_exp_log_reassoc(
; CHECK-NEXT: ret double [[A:%.*]]
;
%1 = call double @llvm.log.f64(double %a)
- %2 = call fast double @llvm.exp.f64(double %1)
+ %2 = call reassoc double @llvm.exp.f64(double %1)
%3 = call double @llvm.log.f64(double %2)
- %4 = call fast double @llvm.exp.f64(double %3)
+ %4 = call reassoc double @llvm.exp.f64(double %3)
ret double %4
}
-define double @exp2_fast_log2_strict(double %a) {
-; CHECK-LABEL: @exp2_fast_log2_strict(
+define double @exp2_reassoc_log2_strict(double %a) {
+; CHECK-LABEL: @exp2_reassoc_log2_strict(
; CHECK-NEXT: ret double [[A:%.*]]
;
%1 = call double @llvm.log2.f64(double %a)
- %2 = call fast double @llvm.exp2.f64(double %1)
+ %2 = call reassoc double @llvm.exp2.f64(double %1)
ret double %2
}
-define double @exp2_strict_log2_fast(double %a) {
-; CHECK-LABEL: @exp2_strict_log2_fast(
-; CHECK-NEXT: [[TMP1:%.*]] = call fast double @llvm.log2.f64(double [[A:%.*]])
+define double @exp2_strict_log2_reassoc(double %a) {
+; CHECK-LABEL: @exp2_strict_log2_reassoc(
+; CHECK-NEXT: [[TMP1:%.*]] = call reassoc double @llvm.log2.f64(double [[A:%.*]])
; CHECK-NEXT: [[TMP2:%.*]] = call double @llvm.exp2.f64(double [[TMP1]])
; CHECK-NEXT: ret double [[TMP2]]
;
- %1 = call fast double @llvm.log2.f64(double %a)
+ %1 = call reassoc double @llvm.log2.f64(double %a)
%2 = call double @llvm.exp2.f64(double %1)
ret double %2
}
@@ -180,14 +179,14 @@ define double @exp2_log2_exp2_log2(doubl
ret double %4
}
-define double @exp2_log2_exp2_log2_fast(double %a) {
-; CHECK-LABEL: @exp2_log2_exp2_log2_fast(
+define double @exp2_log2_exp2_log2_reassoc(double %a) {
+; CHECK-LABEL: @exp2_log2_exp2_log2_reassoc(
; CHECK-NEXT: ret double [[A:%.*]]
;
%1 = call double @llvm.log2.f64(double %a)
- %2 = call fast double @llvm.exp2.f64(double %1)
+ %2 = call reassoc double @llvm.exp2.f64(double %1)
%3 = call double @llvm.log2.f64(double %2)
- %4 = call fast double @llvm.exp2.f64(double %3)
+ %4 = call reassoc double @llvm.exp2.f64(double %3)
ret double %4
}
More information about the llvm-commits
mailing list