diff --git a/lib/Transforms/IPO/FunctionAttrs.cpp b/lib/Transforms/IPO/FunctionAttrs.cpp index 13fb75619d4..aea4cb4cf26 100644 --- a/lib/Transforms/IPO/FunctionAttrs.cpp +++ b/lib/Transforms/IPO/FunctionAttrs.cpp @@ -198,6 +198,7 @@ bool FunctionAttrs::isCaptured(Function &F, Value *V) { UseWithDepth UD = Worklist.pop_back_val(); Use *U = UD.getPointer(); Instruction *I = cast(U->getUser()); + // The value V may have any type if it comes from tracking a load. V = U->get(); // The depth represents the number of loads that need to be performed to // get back the original pointer (or a bitcast etc of it). For example, @@ -253,7 +254,10 @@ bool FunctionAttrs::isCaptured(Function &F, Value *V) { // Only passed via 'nocapture' arguments, or is the called function - not // captured. } else if (isa(I) || isa(I) || isa(I) || - isa(I) || isa(I)) { + // Play safe and exclude GEP indices. + (isa(I) && V == I->getOperand(0)) || + // Play safe and exclude the select condition. + (isa(I) && V != I->getOperand(0))) { // Usually loads can be ignored because they dereference the original // pointer. However the loaded value needs to be tracked if loading @@ -267,7 +271,9 @@ bool FunctionAttrs::isCaptured(Function &F, Value *V) { continue; // Loading a pointer to (a pointer to...) the original pointer or a // variation of it. Track uses of the loaded value, noting that one - // dereference was performed. + // dereference was performed. Note that the loaded value need not be + // of pointer type. For example, an alloca may have been bitcast to + // a pointer to another type, which was then loaded. --Depth; }