1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

[InstCombine] Remove hasOneUse check for pow(C,x) -> exp2(log2(C)*x)

I don't think there's any good reason not to do this transformation when
the pow has multiple uses.

Differential Revision: https://reviews.llvm.org/D79407
This commit is contained in:
Jay Foad 2020-05-05 11:35:23 +01:00
parent 6a5768da2a
commit d7f05cb34a
2 changed files with 10 additions and 8 deletions

View File

@ -1564,8 +1564,8 @@ Value *LibCallSimplifier::replacePowWithExp(CallInst *Pow, IRBuilderBase &B) {
LibFunc_exp10l, B, Attrs);
// pow(n, x) -> exp2(log2(n) * x)
if (Pow->hasOneUse() && Pow->hasApproxFunc() && Pow->hasNoNaNs() &&
Pow->hasNoInfs() && BaseF->isNormal() && !BaseF->isNegative()) {
if (Pow->hasApproxFunc() && Pow->hasNoNaNs() && Pow->hasNoInfs() &&
BaseF->isNormal() && !BaseF->isNegative()) {
Value *Log = nullptr;
if (Ty->isFloatTy())
Log = ConstantFP::get(Ty, std::log2(BaseF->convertToFloat()));

View File

@ -350,9 +350,10 @@ define double @pow_negative_base(double %e) {
define double @pow_multiuse(double %e) {
; CHECK-LABEL: @pow_multiuse(
; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn double @pow(double 5.000000e+00, double [[E:%.*]])
; CHECK-NEXT: tail call void @use_d(double [[CALL]])
; CHECK-NEXT: ret double [[CALL]]
; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn double [[E:%.*]], 0x4002934{{.*}}
; CHECK-NEXT: [[EXP2:%.*]] = call nnan ninf afn double @exp2(double [[MUL]])
; CHECK-NEXT: tail call void @use_d(double [[EXP2]])
; CHECK-NEXT: ret double [[EXP2]]
;
%call = tail call afn nnan ninf double @pow(double 5.000000e+00, double %e)
tail call void @use_d(double %call)
@ -433,9 +434,10 @@ define float @powf_negative_base(float %e) {
define float @powf_multiuse(float %e) {
; CHECK-LABEL: @powf_multiuse(
; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn float @powf(float 5.000000e+00, float [[E:%.*]])
; CHECK-NEXT: tail call void @use_f(float [[CALL]])
; CHECK-NEXT: ret float [[CALL]]
; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn float [[E:%.*]], 0x4002934{{.*}}
; CHECK-NEXT: [[EXP2F:%.*]] = call nnan ninf afn float @exp2f(float [[MUL]])
; CHECK-NEXT: tail call void @use_f(float [[EXP2F]])
; CHECK-NEXT: ret float [[EXP2F]]
;
%call = tail call afn nnan ninf float @powf(float 5.000000e+00, float %e)
tail call void @use_f(float %call)