Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit ff8943d

Browse files
committed
Revert r340947 "[InstCombine] Expand the simplification of pow() into exp2()"
It broke the clang-cl self-host. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@340991 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 0bac46f commit ff8943d

File tree

2 files changed

+22
-42
lines changed

2 files changed

+22
-42
lines changed

lib/Transforms/Utils/SimplifyLibCalls.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
#include "llvm/Transforms/Utils/SimplifyLibCalls.h"
16-
#include "llvm/ADT/APSInt.h"
1716
#include "llvm/ADT/SmallString.h"
1817
#include "llvm/ADT/StringMap.h"
1918
#include "llvm/ADT/Triple.h"
@@ -1184,13 +1183,12 @@ static Value *getPow(Value *InnerChain[33], unsigned Exp, IRBuilder<> &B) {
11841183
}
11851184

11861185
/// Use exp{,2}(x * y) for pow(exp{,2}(x), y);
1187-
/// exp2(n * x) for pow(2.0 ** n, x); exp10(x) for pow(10.0, x).
1186+
/// exp2(x) for pow(2.0, x); exp10(x) for pow(10.0, x).
11881187
Value *LibCallSimplifier::replacePowWithExp(CallInst *Pow, IRBuilder<> &B) {
11891188
Value *Base = Pow->getArgOperand(0), *Expo = Pow->getArgOperand(1);
11901189
AttributeList Attrs = Pow->getCalledFunction()->getAttributes();
11911190
Module *Mod = Pow->getModule();
11921191
Type *Ty = Pow->getType();
1193-
bool Ignored;
11941192

11951193
// Evaluate special cases related to a nested function as the base.
11961194

@@ -1251,28 +1249,10 @@ Value *LibCallSimplifier::replacePowWithExp(CallInst *Pow, IRBuilder<> &B) {
12511249

12521250
// Evaluate special cases related to a constant base.
12531251

1254-
const APFloat *BaseF;
1255-
if (!match(Pow->getArgOperand(0), m_APFloat(BaseF)))
1256-
return nullptr;
1257-
1258-
// pow(2.0 ** n, x) -> exp2(n * x)
1259-
APFloat BaseR = APFloat(1.0);
1260-
BaseR.convert(BaseF->getSemantics(), APFloat::rmTowardZero, &Ignored);
1261-
BaseR = BaseR / *BaseF;
1262-
bool IsInteger = BaseF->isInteger(),
1263-
IsReciprocal = BaseR.isInteger();
1264-
const APFloat *NF = IsReciprocal ? &BaseR : BaseF;
1265-
APSInt NI(64, false);
1266-
if ((IsInteger || IsReciprocal) &&
1267-
!NF->convertToInteger(NI, APFloat::rmTowardZero, &Ignored) &&
1268-
NI > 1 && NI.isPowerOf2()) {
1269-
double N = NI.logBase2() * (IsReciprocal ? -1.0 : 1.0);
1270-
Value *FMul = B.CreateFMul(Expo, ConstantFP::get(Ty, N), "mul");
1271-
if (Pow->doesNotAccessMemory())
1272-
return B.CreateCall(Intrinsic::getDeclaration(Mod, Intrinsic::exp2, Ty),
1273-
FMul, "exp2");
1274-
else
1275-
return emitUnaryFloatFnCall(FMul, TLI->getName(LibFunc_exp2), B, Attrs);
1252+
// pow(2.0, x) -> exp2(x)
1253+
if (match(Base, m_SpecificFP(2.0))) {
1254+
Value *Exp2 = Intrinsic::getDeclaration(Mod, Intrinsic::exp2, Ty);
1255+
return B.CreateCall(Exp2, Expo, "exp2");
12761256
}
12771257

12781258
// pow(10.0, x) -> exp10(x)

test/Transforms/InstCombine/pow-1.ll

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
declare float @powf(float, float) nounwind readonly
1818
declare double @pow(double, double) nounwind readonly
19-
declare double @llvm.pow.f64(double, double)
2019
declare <2 x float> @llvm.pow.v2f32(<2 x float>, <2 x float>) nounwind readonly
2120
declare <2 x double> @llvm.pow.v2f64(<2 x double>, <2 x double>) nounwind readonly
2221

@@ -58,18 +57,18 @@ define <2 x double> @test_simplify2v(<2 x double> %x) {
5857

5958
define float @test_simplify3(float %x) {
6059
; ANY-LABEL: @test_simplify3(
61-
; ANY-NEXT: [[EXP2F:%.*]] = call float @exp2f(float [[X:%.*]]) [[NUW_RO:#[0-9]+]]
62-
; ANY-NEXT: ret float [[EXP2F]]
60+
; ANY-NEXT: [[EXP2:%.*]] = call float @llvm.exp2.f32(float [[X:%.*]])
61+
; ANY-NEXT: ret float [[EXP2]]
6362
;
6463
%retval = call float @powf(float 2.0, float %x)
6564
ret float %retval
6665
}
6766

67+
; TODO: Should result in exp2(-2.0 * x).
6868
define double @test_simplify3n(double %x) {
6969
; ANY-LABEL: @test_simplify3n(
70-
; ANY-NEXT: [[MUL:%.*]] = fmul double [[X:%.*]], -2.000000e+00
71-
; ANY-NEXT: [[EXP2:%.*]] = call double @exp2(double [[MUL]]) [[NUW_RO]]
72-
; ANY-NEXT: ret double [[EXP2]]
70+
; ANY-NEXT: [[RETVAL:%.*]] = call double @pow(double 2.500000e-01, double [[X:%.*]])
71+
; ANY-NEXT: ret double [[RETVAL]]
7372
;
7473
%retval = call double @pow(double 0.25, double %x)
7574
ret double %retval
@@ -84,30 +83,30 @@ define <2 x float> @test_simplify3v(<2 x float> %x) {
8483
ret <2 x float> %retval
8584
}
8685

86+
; TODO: Should result in exp2(2.0 * x).
8787
define <2 x double> @test_simplify3vn(<2 x double> %x) {
8888
; ANY-LABEL: @test_simplify3vn(
89-
; ANY-NEXT: [[MUL:%.*]] = fmul <2 x double> [[X:%.*]], <double 2.000000e+00, double 2.000000e+00>
90-
; ANY-NEXT: [[EXP2:%.*]] = call <2 x double> @llvm.exp2.v2f64(<2 x double> [[MUL]])
91-
; ANY-NEXT: ret <2 x double> [[EXP2]]
89+
; ANY-NEXT: [[RETVAL:%.*]] = call <2 x double> @llvm.pow.v2f64(<2 x double> <double 4.000000e+00, double 4.000000e+00>, <2 x double> [[X:%.*]])
90+
; ANY-NEXT: ret <2 x double> [[RETVAL]]
9291
;
9392
%retval = call <2 x double> @llvm.pow.v2f64(<2 x double> <double 4.0, double 4.0>, <2 x double> %x)
9493
ret <2 x double> %retval
9594
}
9695

9796
define double @test_simplify4(double %x) {
9897
; ANY-LABEL: @test_simplify4(
99-
; ANY-NEXT: [[EXP2:%.*]] = call double @exp2(double [[X:%.*]]) [[NUW_RO]]
98+
; ANY-NEXT: [[EXP2:%.*]] = call double @llvm.exp2.f64(double [[X:%.*]])
10099
; ANY-NEXT: ret double [[EXP2]]
101100
;
102101
%retval = call double @pow(double 2.0, double %x)
103102
ret double %retval
104103
}
105104

105+
; TODO: Should result in exp2f(3.0 * x).
106106
define float @test_simplify4n(float %x) {
107107
; ANY-LABEL: @test_simplify4n(
108-
; ANY-NEXT: [[MUL:%.*]] = fmul float [[X:%.*]], 3.000000e+00
109-
; ANY-NEXT: [[EXP2F:%.*]] = call float @exp2f(float [[MUL]]) [[NUW_RO]]
110-
; ANY-NEXT: ret float [[EXP2F]]
108+
; ANY-NEXT: [[RETVAL:%.*]] = call float @powf(float 8.000000e+00, float [[X:%.*]])
109+
; ANY-NEXT: ret float [[RETVAL]]
111110
;
112111
%retval = call float @powf(float 8.0, float %x)
113112
ret float %retval
@@ -122,11 +121,11 @@ define <2 x double> @test_simplify4v(<2 x double> %x) {
122121
ret <2 x double> %retval
123122
}
124123

124+
; TODO: Should result in exp2f(-x).
125125
define <2 x float> @test_simplify4vn(<2 x float> %x) {
126126
; ANY-LABEL: @test_simplify4vn(
127-
; ANY-NEXT: [[MUL:%.*]] = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[X:%.*]]
128-
; ANY-NEXT: [[EXP2:%.*]] = call <2 x float> @llvm.exp2.v2f32(<2 x float> [[MUL]])
129-
; ANY-NEXT: ret <2 x float> [[EXP2]]
127+
; ANY-NEXT: [[RETVAL:%.*]] = call <2 x float> @llvm.pow.v2f32(<2 x float> <float 5.000000e-01, float 5.000000e-01>, <2 x float> [[X:%.*]])
128+
; ANY-NEXT: ret <2 x float> [[RETVAL]]
130129
;
131130
%retval = call <2 x float> @llvm.pow.v2f32(<2 x float> <float 0.5, float 0.5>, <2 x float> %x)
132131
ret <2 x float> %retval
@@ -170,7 +169,7 @@ define <2 x double> @test_simplify6v(<2 x double> %x) {
170169

171170
define float @test_simplify7(float %x) {
172171
; ANY-LABEL: @test_simplify7(
173-
; ANY-NEXT: [[SQRTF:%.*]] = call float @sqrtf(float [[X:%.*]]) [[NUW_RO]]
172+
; ANY-NEXT: [[SQRTF:%.*]] = call float @sqrtf(float [[X:%.*]]) [[NUW_RO:#[0-9]+]]
174173
; ANY-NEXT: [[ABS:%.*]] = call float @llvm.fabs.f32(float [[SQRTF]])
175174
; ANY-NEXT: [[ISINF:%.*]] = fcmp oeq float [[X]], 0xFFF0000000000000
176175
; ANY-NEXT: [[TMP1:%.*]] = select i1 [[ISINF]], float 0x7FF0000000000000, float [[ABS]]
@@ -331,6 +330,7 @@ define <2 x double> @pow_neg1_double_fastv(<2 x double> %x) {
331330
ret <2 x double> %r
332331
}
333332

333+
declare double @llvm.pow.f64(double %Val, double %Power)
334334
define double @test_simplify17(double %x) {
335335
; ANY-LABEL: @test_simplify17(
336336
; ANY-NEXT: [[SQRT:%.*]] = call double @llvm.sqrt.f64(double [[X:%.*]])

0 commit comments

Comments
 (0)