@@ -1258,21 +1258,18 @@ static Value *optimizeDoubleFP(CallInst *CI, IRBuilder<> &B,
1258
1258
if (!V[0 ] || (isBinary && !V[1 ]))
1259
1259
return nullptr ;
1260
1260
1261
- StringRef CalleeNm = CalleeFn->getName ();
1262
- AttributeList CalleeAt = CalleeFn->getAttributes ();
1263
- bool CalleeIn = CalleeFn->isIntrinsic ();
1264
-
1265
1261
// If call isn't an intrinsic, check that it isn't within a function with the
1266
1262
// same name as the float version of this call, otherwise the result is an
1267
1263
// infinite loop. For example, from MinGW-w64:
1268
1264
//
1269
1265
// float expf(float val) { return (float) exp((double) val); }
1270
- if (!CalleeIn) {
1271
- const Function *Fn = CI->getFunction ();
1272
- StringRef FnName = Fn->getName ();
1273
- if (FnName.back () == ' f' &&
1274
- FnName.size () == (CalleeNm.size () + 1 ) &&
1275
- FnName.startswith (CalleeNm))
1266
+ StringRef CalleeName = CalleeFn->getName ();
1267
+ bool IsIntrinsic = CalleeFn->isIntrinsic ();
1268
+ if (!IsIntrinsic) {
1269
+ StringRef CallerName = CI->getFunction ()->getName ();
1270
+ if (!CallerName.empty () && CallerName.back () == ' f' &&
1271
+ CallerName.size () == (CalleeName.size () + 1 ) &&
1272
+ CallerName.startswith (CalleeName))
1276
1273
return nullptr ;
1277
1274
}
1278
1275
@@ -1282,16 +1279,16 @@ static Value *optimizeDoubleFP(CallInst *CI, IRBuilder<> &B,
1282
1279
1283
1280
// g((double) float) -> (double) gf(float)
1284
1281
Value *R;
1285
- if (CalleeIn ) {
1282
+ if (IsIntrinsic ) {
1286
1283
Module *M = CI->getModule ();
1287
1284
Intrinsic::ID IID = CalleeFn->getIntrinsicID ();
1288
1285
Function *Fn = Intrinsic::getDeclaration (M, IID, B.getFloatTy ());
1289
1286
R = isBinary ? B.CreateCall (Fn, V) : B.CreateCall (Fn, V[0 ]);
1287
+ } else {
1288
+ AttributeList CalleeAttrs = CalleeFn->getAttributes ();
1289
+ R = isBinary ? emitBinaryFloatFnCall (V[0 ], V[1 ], CalleeName, B, CalleeAttrs)
1290
+ : emitUnaryFloatFnCall (V[0 ], CalleeName, B, CalleeAttrs);
1290
1291
}
1291
- else
1292
- R = isBinary ? emitBinaryFloatFnCall (V[0 ], V[1 ], CalleeNm, B, CalleeAt)
1293
- : emitUnaryFloatFnCall (V[0 ], CalleeNm, B, CalleeAt);
1294
-
1295
1292
return B.CreateFPExt (R, B.getDoubleTy ());
1296
1293
}
1297
1294
0 commit comments