diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp --- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp +++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp @@ -769,7 +769,8 @@ Use &U, OMPInformationCache::RuntimeFunctionInfo *RFI = nullptr) { CallInst *CI = dyn_cast(U.getUser()); if (CI && CI->isCallee(&U) && !CI->hasOperandBundles() && - (!RFI || CI->getCalledFunction() == RFI->Declaration)) + (!RFI || + (RFI->Declaration && CI->getCalledFunction() == RFI->Declaration))) return CI; return nullptr; } @@ -780,7 +781,8 @@ Value &V, OMPInformationCache::RuntimeFunctionInfo *RFI = nullptr) { CallInst *CI = dyn_cast(&V); if (CI && !CI->hasOperandBundles() && - (!RFI || CI->getCalledFunction() == RFI->Declaration)) + (!RFI || + (RFI->Declaration && CI->getCalledFunction() == RFI->Declaration))) return CI; return nullptr; } @@ -2494,7 +2496,8 @@ // Match: -1 == __kmpc_target_init (for non-SPMD kernels only!) if (C->isAllOnesValue()) { auto *CB = dyn_cast(Cmp->getOperand(0)); - if (!CB || CB->getCalledFunction() != RFI.Declaration) + CB = CB ? OpenMPOpt::getCallIfRegularCall(*CB, &RFI) : nullptr; + if (!CB) return false; const int InitIsSPMDArgNo = 1; auto *IsSPMDModeCI =