[SimplifyLibCalls] Don't crash if the function doesn't have a name.
authorDavide Italiano <davide@freebsd.org>
Sun, 29 Nov 2015 21:58:56 +0000 (21:58 +0000)
committerDavide Italiano <davide@freebsd.org>
Sun, 29 Nov 2015 21:58:56 +0000 (21:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254265 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/SimplifyLibCalls.cpp
test/Transforms/InstCombine/log-pow.ll

index e7eb39d6312fa595b9724412cdfd3434116761fc..47e587fab7b6a94f585a36a26d47b909fde4a72d 100644 (file)
@@ -1317,9 +1317,8 @@ Value *LibCallSimplifier::optimizeLog(CallInst *CI, IRBuilder<> &B) {
 
   LibFunc::Func Func;
   Function *F = OpC->getCalledFunction();
-  StringRef FuncName = F->getName();
-  if ((TLI->getLibFunc(FuncName, Func) && TLI->has(Func) &&
-      Func == LibFunc::pow) || F->getIntrinsicID() == Intrinsic::pow)
+  if (F && ((TLI->getLibFunc(F->getName(), Func) && TLI->has(Func) &&
+      Func == LibFunc::pow) || F->getIntrinsicID() == Intrinsic::pow))
     return B.CreateFMul(OpC->getArgOperand(1),
       EmitUnaryFloatFnCall(OpC->getOperand(0), Callee->getName(), B,
                            Callee->getAttributes()), "mul");
index 2cafccabf0a845e509bd13289380a72a83873576..c98a1a5bc6282882b01e99c18a9b8e6de6942b18 100644 (file)
@@ -13,6 +13,15 @@ entry:
 ; CHECK:   ret double %mul
 ; CHECK: }
 
+define double @test2(double ()* %fptr, double %p1) #0 {
+  %call1 = call double %fptr()
+  %pow = call double @log(double %call1)
+  ret double %pow
+}
+
+; CHECK-LABEL: @test2
+; CHECK: log
+
 declare double @log(double) #0
 declare double @llvm.pow.f64(double, double)