Currently CallAnalyzer::isGEPFree uses TTI::getGEPCost to check if GEP is free. TTI::getGEPCost cannot handle cases when GEPs participate in Def-Use dependencies (see https://reviews.llvm.org/D31186 for example). There is TTI::getUserCost which can calculate the cost:
int TargetTransformInfo::getUserCost (const User * U) const
Estimate the cost of a given IR user when lowered.This can estimate the cost of either a ConstantExpr or Instruction when lowered. It has two primary advantages over the getOperationCost and getGEPCost above, and one significant disadvantage: it can only be used when the IR construct has already been formed.
The advantages are that it can inspect the SSA use graph to reason more accurately about the cost. For example, all-constant-GEPs can often be folded into a load or other instruction, but if they are used in some other context they may not be folded. This routine can distinguish such cases.
The returned cost is defined in terms of TargetCostConstants, see its comments for a detailed explanation of the cost values.
This patch gets CallAnalyzer::isGEPFree to use TTI::getUserCost instead of TTI::getGEPCost.