@@ -1258,21 +1258,18 @@ static Value *optimizeDoubleFP(CallInst *CI, IRBuilder<> &B,
12581258 if (!V[0 ] || (isBinary && !V[1 ]))
12591259 return nullptr ;
12601260
1261- StringRef CalleeNm = CalleeFn->getName ();
1262- AttributeList CalleeAt = CalleeFn->getAttributes ();
1263- bool CalleeIn = CalleeFn->isIntrinsic ();
1264-
12651261 // If call isn't an intrinsic, check that it isn't within a function with the
12661262 // same name as the float version of this call, otherwise the result is an
12671263 // infinite loop. For example, from MinGW-w64:
12681264 //
12691265 // 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))
12761273 return nullptr ;
12771274 }
12781275
@@ -1282,16 +1279,16 @@ static Value *optimizeDoubleFP(CallInst *CI, IRBuilder<> &B,
12821279
12831280 // g((double) float) -> (double) gf(float)
12841281 Value *R;
1285- if (CalleeIn ) {
1282+ if (IsIntrinsic ) {
12861283 Module *M = CI->getModule ();
12871284 Intrinsic::ID IID = CalleeFn->getIntrinsicID ();
12881285 Function *Fn = Intrinsic::getDeclaration (M, IID, B.getFloatTy ());
12891286 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);
12901291 }
1291- else
1292- R = isBinary ? emitBinaryFloatFnCall (V[0 ], V[1 ], CalleeNm, B, CalleeAt)
1293- : emitUnaryFloatFnCall (V[0 ], CalleeNm, B, CalleeAt);
1294-
12951292 return B.CreateFPExt (R, B.getDoubleTy ());
12961293}
12971294
0 commit comments