diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index e211b42747dd..ece98ffe39f4 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -2310,8 +2310,7 @@ Instruction *InstCombinerImpl::visitCallBase(CallBase &Call) { if (IntrinsicInst *II = findInitTrampoline(Callee)) return transformCallThroughTrampoline(Call, *II); - PointerType *PTy = cast(Callee->getType()); - FunctionType *FTy = cast(PTy->getElementType()); + FunctionType *FTy = Call.getFunctionType(); if (FTy->isVarArg()) { int ix = FTy->getNumParams(); // See if we can optimize any arguments passed through the varargs area of diff --git a/llvm/test/Transforms/InstCombine/opaque-ptr.ll b/llvm/test/Transforms/InstCombine/opaque-ptr.ll index 0249b9686cf2..45b699855dd7 100644 --- a/llvm/test/Transforms/InstCombine/opaque-ptr.ll +++ b/llvm/test/Transforms/InstCombine/opaque-ptr.ll @@ -108,3 +108,12 @@ define ptr @load_bitcast_2(ptr %a) { %d = bitcast i8* %c to ptr ret ptr %d } + +define void @call(ptr %a) { +; CHECK-LABEL: @call( +; CHECK-NEXT: call void [[A:%.*]]() +; CHECK-NEXT: ret void +; + call void %a() + ret void +}