[llvm-commits] [llvm] r148941 - in /llvm/trunk: lib/Analysis/InlineCost.cpp test/Transforms/Inline/alloca-bonus.ll

Eli Friedman eli.friedman at gmail.com
Wed Jan 25 01:04:07 PST 2012


On Wed, Jan 25, 2012 at 12:27 AM, Nick Lewycky <nicholas at mxc.ca> wrote:
> Author: nicholas
> Date: Wed Jan 25 02:27:40 2012
> New Revision: 148941
>
> URL: http://llvm.org/viewvc/llvm-project?rev=148941&view=rev
> Log:
> Support pointer comparisons against constants, when looking at the inline-cost
> savings from a pointer argument becoming an alloca. Sometimes callees will even
> compare a pointer to null and then branch to an otherwise unreachable block!
> Detect these cases and compute the number of saved instructions, instead of
> bailing out and reporting no savings.

[Comments inlined.]

> +      } else if (ICmpInst *ICI = dyn_cast<ICmpInst>(I)) {
> +        if (!isa<Constant>(ICI->getOperand(1)))
> +          return 0;
> +        ICmpInsts.push_back(ICI);

You probably want to restrict this to equality comparisons; I don't
think we fold relational comparisons between an alloca and a constant
in general.

> +        if (BranchInst *BI = dyn_cast<BranchInst>(I)) {
> +          BasicBlock *BB = BI->getSuccessor(Result ? 0 : 1);
> +          if (BB->getSinglePredecessor())
> +            Reduction += InlineConstants::InstrCost * BB->size();

Shouldn't you use NumBBInsts[BB] rather than BB->size()?

-Eli




More information about the llvm-commits mailing list