[PATCH] D18124: ConstantFoldInstruction: avoid wasted calls to ConstantFoldConstantExpression

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 12 16:26:28 PST 2016


On Saturday, March 12, 2016, escha via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> escha created this revision.
> escha added a reviewer: resistor.
> escha added a subscriber: llvm-commits.
> escha set the repository for this revision to rL LLVM.
>
> The loop here calls ConstantFoldConstantExpression before knowing if all
> the operands are constant, which can waste a lot of time. Cuts time spent
> in ConstantFoldInstruction (and callees) by ~20% in our tests. Should be
> NFC.
>
> Repository:
>   rL LLVM
>
> http://reviews.llvm.org/D18124
>
> Files:
>   lib/Analysis/ConstantFolding.cpp
>
> Index: lib/Analysis/ConstantFolding.cpp
> ===================================================================
> --- lib/Analysis/ConstantFolding.cpp
> +++ lib/Analysis/ConstantFolding.cpp
> @@ -983,12 +983,14 @@
>
>    // Scan the operand list, checking to see if they are all constants, if
> so,
>    // hand off to ConstantFoldInstOperandsImpl.
> +  if (!std::all_of(I->op_begin(), I->op_end(), [] (Use &U) {
> +        return isa<Constant>(U);
> +      }))
> +    return nullptr;


Can you use llvm::all_of here?


> +
>    SmallVector<Constant*, 8> Ops;
>    for (User::op_iterator i = I->op_begin(), e = I->op_end(); i != e; ++i)
> {
> -    Constant *Op = dyn_cast<Constant>(*i);
> -    if (!Op)
> -      return nullptr;  // All operands not constant!
> -
> +    Constant *Op = cast<Constant>(*i);
>      // Fold the Instruction's operands.
>      if (ConstantExpr *NewCE = dyn_cast<ConstantExpr>(Op))
>        Op = ConstantFoldConstantExpression(NewCE, DL, TLI);
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160312/d7a2f594/attachment.html>


More information about the llvm-commits mailing list