Skip to content

Commit b93c39d

Browse files
committed
Use IRBuilder functions for creating Ldexp, FMA intrinsic call
1 parent 60956c0 commit b93c39d

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

llvm/lib/CodeGen/ExpandFp.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@ class FRemExpander {
101101
ExTy(B.getInt32Ty()), Bits(ConstantInt::get(ExTy, Bits)),
102102
One(ConstantInt::get(ExTy, 1)), Signbit(Signbit) {};
103103

104-
Value *createLdexp(Value *Base, Value *Exp, const Twine &Name) const {
105-
return B.CreateIntrinsic(Intrinsic::ldexp, {ComputeFpTy, B.getInt32Ty()},
106-
{Base, Exp}, {}, Name);
107-
}
108-
109104
Value *createRcp(Value *V, const Twine &Name) const {
110105
return B.CreateFDiv(ConstantFP::get(ComputeFpTy, 1.0), V, Name);
111106
}
@@ -121,8 +116,7 @@ class FRemExpander {
121116
// ax = clt ? axp : ax;
122117
Value *Q = B.CreateUnaryIntrinsic(Intrinsic::rint, B.CreateFMul(Ax, Ayinv),
123118
{}, "q");
124-
Value *AxUpdate = B.CreateIntrinsic(Intrinsic::fma, {ComputeFpTy},
125-
{B.CreateFNeg(Q), Ay, Ax}, {}, "ax");
119+
Value *AxUpdate = B.CreateFMA(B.CreateFNeg(Q), Ay, Ax, {}, "ax");
126120
Value *Clt = B.CreateFCmp(CmpInst::FCMP_OLT, AxUpdate,
127121
ConstantFP::get(ComputeFpTy, 0.0), "clt");
128122
Value *Axp = B.CreateFAdd(AxUpdate, Ay, "axp");
@@ -148,7 +142,7 @@ class FRemExpander {
148142
Value *Exp = B.CreateExtractValue(Frexp, {1});
149143

150144
Exp = B.CreateSub(Exp, One, ExName);
151-
Value *Pow = createLdexp(Mant, NewExp, PowName);
145+
Value *Pow = B.CreateLdexp(Mant, NewExp, {}, PowName);
152146

153147
return {Pow, Exp};
154148
}
@@ -197,7 +191,7 @@ class FRemExpander {
197191
AxPhi->addIncoming(Ax, PreheaderBB);
198192

199193
Value *AxPhiUpdate = buildUpdateAx(AxPhi, Ay, Ayinv);
200-
AxPhiUpdate = createLdexp(AxPhiUpdate, Bits, "ax_update");
194+
AxPhiUpdate = B.CreateLdexp(AxPhiUpdate, Bits, {}, "ax_update");
201195
AxPhi->addIncoming(AxPhiUpdate, LoopBB);
202196
NbIv->addIncoming(B.CreateSub(NbIv, Bits, "nb_update"), LoopBB);
203197

@@ -215,14 +209,14 @@ class FRemExpander {
215209
NbExitPhi->addIncoming(NbIv, LoopBB);
216210
NbExitPhi->addIncoming(Nb, PreheaderBB);
217211

218-
Value *AxFinal = createLdexp(
219-
AxPhiExit, B.CreateAdd(B.CreateSub(NbExitPhi, Bits), One), "ax");
212+
Value *AxFinal = B.CreateLdexp(
213+
AxPhiExit, B.CreateAdd(B.CreateSub(NbExitPhi, Bits), One), {}, "ax");
220214
AxFinal = buildUpdateAx(AxFinal, Ay, Ayinv);
221215

222216
// Build:
223217
// ax = BUILTIN_FLDEXP_ComputeFpTy(ax, ey);
224218
// ret = AS_FLOAT((AS_INT(x) & SIGNBIT_SP32) ^ AS_INT(ax));
225-
AxFinal = createLdexp(AxFinal, Ey, "ax");
219+
AxFinal = B.CreateLdexp(AxFinal, Ey, {}, "ax");
226220

227221
Value *XAsInt = B.CreateBitCast(X, IntTy, "x_as_int");
228222
if (ComputeFpTy != X->getType())

0 commit comments

Comments
 (0)