diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 0b471639970..fb7dc984923 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2163,6 +2163,14 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { // Replace: gep (gep %P, long B), long A, ... // With: T = long A+B; gep %P, T, ... // + // Note that if our source is a gep chain itself that we wait for that + // chain to be resolved before we perform this transformation. This + // avoids us creating a TON of code in some cases. + // + if (isa(Src->getOperand(0)) && + cast(Src->getOperand(0))->getNumOperands() == 2) + return 0; // Wait until our source is folded to completion. + Value *Sum = BinaryOperator::create(Instruction::Add, Src->getOperand(1), GEP.getOperand(1), Src->getName()+".sum", &GEP);