[PATCH] D33619: [InstSimplify] Don't call the heavy ConstantFoldInstruction for loads. Use the lighter ConstantFoldLoadFromConstPtr

Daniel Berlin via llvm-commits llvm-commits at lists.llvm.org
Fri May 26 19:00:26 PDT 2017


The other major one we see in NewGVN is SimplifyCmpInst with pointers.
We spend about 10-20% of NewGVN time in it ;)


On Fri, May 26, 2017 at 5:38 PM, Craig Topper via Phabricator <
reviews at reviews.llvm.org> wrote:

> craig.topper created this revision.
>
> Load instructions go through the default case of SimplifyInstruction and
> use the heavy ConstantFoldInstruction which tries to recursively constant
> fold any constantexpr operands. I believe this is harder than we try for
> other instructions in InstSimplify. We usually use some entry point like
> ConstantFoldBinaryOpOperands or ConstantFoldCompareInstOperands which
> bypass this logic.
>
> This patch calls directly to ConstantFoldLoadFromConstPtr if the load has
> a constant pointer and isn't volatile.
>
> On one benchmark cpp file I ran through callgrind, this showed
> instructions executed in SimplifyInstruction reduce by almost half.
>
>
> https://reviews.llvm.org/D33619
>
> Files:
>   lib/Analysis/InstructionSimplify.cpp
>
>
> Index: lib/Analysis/InstructionSimplify.cpp
> ===================================================================
> --- lib/Analysis/InstructionSimplify.cpp
> +++ lib/Analysis/InstructionSimplify.cpp
> @@ -4542,7 +4542,7 @@
>  Value *llvm::SimplifyInstruction(Instruction *I, const SimplifyQuery &SQ,
>                                   OptimizationRemarkEmitter *ORE) {
>    const SimplifyQuery Q = SQ.CxtI ? SQ : SQ.getWithInstruction(I);
> -  Value *Result;
> +  Value *Result = nullptr;
>
>    switch (I->getOpcode()) {
>    default:
> @@ -4673,9 +4673,15 @@
>      Result =
>          SimplifyCastInst(I->getOpcode(), I->getOperand(0), I->getType(),
> Q);
>      break;
> +  case Instruction::Load: {
> +    auto *LI = cast<LoadInst>(I);
> +    if (!LI->isVolatile())
> +      if (auto *C = dyn_cast<Constant>(LI->getOperand(0)))
> +        Result = ConstantFoldLoadFromConstPtr(C, LI->getType(), Q.DL);
> +    break;
> +  }
>    case Instruction::Alloca:
>      // No simplifications for Alloca and it can't be constant folded.
> -    Result = nullptr;
>      break;
>    }
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170526/9f1d328b/attachment.html>


More information about the llvm-commits mailing list