From: David Majnemer Date: Wed, 6 Jan 2016 05:01:34 +0000 (+0000) Subject: [SimplifyLibCalls] Teach SimplifyLibCalls about operand bundles X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=4cb9f9dcb1839ebe4a09c1c254f1ee1f598d98c8;ds=sidebyside [SimplifyLibCalls] Teach SimplifyLibCalls about operand bundles If we replace one call-site with another, be sure to move over any operand bundles that lingered on the old call-site. This fixes PR26036. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256912 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/IR/IRBuilder.h b/include/llvm/IR/IRBuilder.h index e133e6d8093..a30505471aa 100644 --- a/include/llvm/IR/IRBuilder.h +++ b/include/llvm/IR/IRBuilder.h @@ -61,9 +61,13 @@ protected: MDNode *DefaultFPMathTag; FastMathFlags FMF; + ArrayRef DefaultOperandBundles; + public: - IRBuilderBase(LLVMContext &context, MDNode *FPMathTag = nullptr) - : Context(context), DefaultFPMathTag(FPMathTag), FMF() { + IRBuilderBase(LLVMContext &context, MDNode *FPMathTag = nullptr, + ArrayRef OpBundles = None) + : Context(context), DefaultFPMathTag(FPMathTag), FMF(), + DefaultOperandBundles(OpBundles) { ClearInsertionPoint(); } @@ -538,37 +542,44 @@ class IRBuilder : public IRBuilderBase, public Inserter { public: IRBuilder(LLVMContext &C, const T &F, Inserter I = Inserter(), - MDNode *FPMathTag = nullptr) - : IRBuilderBase(C, FPMathTag), Inserter(std::move(I)), Folder(F) {} - - explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr) - : IRBuilderBase(C, FPMathTag), Folder() { - } - - explicit IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag = nullptr) - : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder(F) { + MDNode *FPMathTag = nullptr, + ArrayRef OpBundles = None) + : IRBuilderBase(C, FPMathTag, OpBundles), Inserter(std::move(I)), + Folder(F) {} + + explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr, + ArrayRef OpBundles = None) + : IRBuilderBase(C, FPMathTag, OpBundles), Folder() {} + + explicit IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag = nullptr, + ArrayRef OpBundles = None) + : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder(F) { SetInsertPoint(TheBB); } - explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr) - : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder() { + explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr, + ArrayRef OpBundles = None) + : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder() { SetInsertPoint(TheBB); } - explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr) - : IRBuilderBase(IP->getContext(), FPMathTag), Folder() { + explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr, + ArrayRef OpBundles = None) + : IRBuilderBase(IP->getContext(), FPMathTag, OpBundles), Folder() { SetInsertPoint(IP); } - IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F, - MDNode *FPMathTag = nullptr) - : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder(F) { + IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T &F, + MDNode *FPMathTag = nullptr, + ArrayRef OpBundles = None) + : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder(F) { SetInsertPoint(TheBB, IP); } IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, - MDNode *FPMathTag = nullptr) - : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder() { + MDNode *FPMathTag = nullptr, + ArrayRef OpBundles = None) + : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder() { SetInsertPoint(TheBB, IP); } @@ -1546,7 +1557,7 @@ public: CallInst *CreateCall(llvm::FunctionType *FTy, Value *Callee, ArrayRef Args, const Twine &Name = "", MDNode *FPMathTag = nullptr) { - CallInst *CI = CallInst::Create(FTy, Callee, Args); + CallInst *CI = CallInst::Create(FTy, Callee, Args, DefaultOperandBundles); if (isa(CI)) CI = cast(AddFPMathAttributes(CI, FPMathTag, FMF)); return Insert(CI, Name); diff --git a/lib/Transforms/Utils/SimplifyLibCalls.cpp b/lib/Transforms/Utils/SimplifyLibCalls.cpp index 1821fa99ab0..dc5fee523d4 100644 --- a/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -2174,7 +2174,10 @@ Value *LibCallSimplifier::optimizeCall(CallInst *CI) { LibFunc::Func Func; Function *Callee = CI->getCalledFunction(); StringRef FuncName = Callee->getName(); - IRBuilder<> Builder(CI); + + SmallVector OpBundles; + CI->getOperandBundlesAsDefs(OpBundles); + IRBuilder<> Builder(CI, /*FPMathTag=*/nullptr, OpBundles); bool isCallingConvC = CI->getCallingConv() == llvm::CallingConv::C; // Command-line parameter overrides function attribute. @@ -2547,7 +2550,10 @@ Value *FortifiedLibCallSimplifier::optimizeCall(CallInst *CI) { LibFunc::Func Func; Function *Callee = CI->getCalledFunction(); StringRef FuncName = Callee->getName(); - IRBuilder<> Builder(CI); + + SmallVector OpBundles; + CI->getOperandBundlesAsDefs(OpBundles); + IRBuilder<> Builder(CI, /*FPMathTag=*/nullptr, OpBundles); bool isCallingConvC = CI->getCallingConv() == llvm::CallingConv::C; // First, check that this is a known library functions.