Skip to content

Commit f5c8242

Browse files
authored
SimplifyLibCalls: Prefer to emit intrinsic in pow(2, x) -> ldexp(1, x) (#92363)
1 parent 371eccd commit f5c8242

File tree

4 files changed

+511
-11
lines changed

4 files changed

+511
-11
lines changed

llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,11 +2092,19 @@ Value *LibCallSimplifier::replacePowWithExp(CallInst *Pow, IRBuilderBase &B) {
20922092
if (!Ty->isVectorTy() && match(Base, m_SpecificFP(2.0)) &&
20932093
(isa<SIToFPInst>(Expo) || isa<UIToFPInst>(Expo)) &&
20942094
hasFloatFn(M, TLI, Ty, LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl)) {
2095-
if (Value *ExpoI = getIntToFPVal(Expo, B, TLI->getIntSize()))
2096-
return copyFlags(*Pow,
2097-
emitBinaryFloatFnCall(ConstantFP::get(Ty, 1.0), ExpoI,
2098-
TLI, LibFunc_ldexp, LibFunc_ldexpf,
2099-
LibFunc_ldexpl, B, NoAttrs));
2095+
if (Value *ExpoI = getIntToFPVal(Expo, B, TLI->getIntSize())) {
2096+
Constant *One = ConstantFP::get(Ty, 1.0);
2097+
2098+
if (Pow->doesNotAccessMemory()) {
2099+
return copyFlags(*Pow, B.CreateIntrinsic(Intrinsic::ldexp,
2100+
{Ty, ExpoI->getType()},
2101+
{One, ExpoI}, Pow, "exp2"));
2102+
}
2103+
2104+
return copyFlags(*Pow, emitBinaryFloatFnCall(
2105+
One, ExpoI, TLI, LibFunc_ldexp, LibFunc_ldexpf,
2106+
LibFunc_ldexpl, B, NoAttrs));
2107+
}
21002108
}
21012109

21022110
// pow(2.0 ** n, x) -> exp2(n * x)

0 commit comments

Comments
 (0)