[PATCH] D33619: [InstSimplify] Don't call the heavy ConstantFoldInstruction for loads. Use the lighter ConstantFoldLoadFromConstPtr
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 26 17:38:20 PDT 2017
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 --------------
A non-text attachment was scrubbed...
Name: D33619.100507.patch
Type: text/x-patch
Size: 1026 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170527/7834834a/attachment.bin>
More information about the llvm-commits
mailing list