diff options
author | Davide Italiano <davide@freebsd.org> | 2017-01-19 18:51:56 +0000 |
---|---|---|
committer | Davide Italiano <davide@freebsd.org> | 2017-01-19 18:51:56 +0000 |
commit | 2ef8c4e708f189e5bc80af63e9ecb36fa68acff2 (patch) | |
tree | dba202c45ca87440d09c15ea14a3ec24abd13a80 /llvm/lib | |
parent | 93b558a486cc4ca2acedef5904f75746dc606139 (diff) | |
download | bcm5719-llvm-2ef8c4e708f189e5bc80af63e9ecb36fa68acff2.tar.gz bcm5719-llvm-2ef8c4e708f189e5bc80af63e9ecb36fa68acff2.zip |
[InstCombine] Simplify gep (gep p, a), (b-a)
Patch by Andrea Canciani.
Differential Revision: https://reviews.llvm.org/D27413
llvm-svn: 292506
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index f6d1a1e9664..24517a848ba 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1559,27 +1559,21 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { // Replace: gep (gep %P, long B), long A, ... // With: T = long A+B; gep %P, T, ... // - Value *Sum; Value *SO1 = Src->getOperand(Src->getNumOperands()-1); Value *GO1 = GEP.getOperand(1); - if (SO1 == Constant::getNullValue(SO1->getType())) { - Sum = GO1; - } else if (GO1 == Constant::getNullValue(GO1->getType())) { - Sum = SO1; - } else { - // If they aren't the same type, then the input hasn't been processed - // by the loop above yet (which canonicalizes sequential index types to - // intptr_t). Just avoid transforming this until the input has been - // normalized. - if (SO1->getType() != GO1->getType()) - return nullptr; - // Only do the combine when GO1 and SO1 are both constants. Only in - // this case, we are sure the cost after the merge is never more than - // that before the merge. - if (!isa<Constant>(GO1) || !isa<Constant>(SO1)) - return nullptr; - Sum = Builder->CreateAdd(SO1, GO1, PtrOp->getName()+".sum"); - } + + // If they aren't the same type, then the input hasn't been processed + // by the loop above yet (which canonicalizes sequential index types to + // intptr_t). Just avoid transforming this until the input has been + // normalized. + if (SO1->getType() != GO1->getType()) + return nullptr; + + Value* Sum = SimplifyAddInst(GO1, SO1, false, false, DL, &TLI, &DT, &AC); + // Only do the combine when we are sure the cost after the + // merge is never more than that before the merge. + if (Sum == nullptr) + return nullptr; // Update the GEP in place if possible. if (Src->getNumOperands() == 2) { |