[llvm-commits] [llvm] r126452 - in /llvm/trunk: lib/Transforms/Utils/SimplifyCFG.cpp test/Transforms/SimplifyCFG/select-gep.ll
Chris Lattner
clattner at apple.com
Thu Feb 24 17:24:20 PST 2011
On Feb 24, 2011, at 3:26 PM, Benjamin Kramer wrote:
> +++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Thu Feb 24 17:26:09 2011
> @@ -247,11 +247,13 @@
> if (PBB->getFirstNonPHIOrDbg() != I)
> return false;
> break;
> - case Instruction::GetElementPtr:
> - // GEPs are cheap if all indices are constant.
> - if (!cast<GetElementPtrInst>(I)->hasAllConstantIndices())
> + case Instruction::GetElementPtr: {
> + // GEPs are cheap if all indices are constant or if there's only one index.
> + GetElementPtrInst *GEP = cast<GetElementPtrInst>(I);
> + if (!GEP->hasAllConstantIndices() && GEP->getNumIndices() > 1)
> return false;
> break;
> + }
FYI getNumIndices() will return 2 for "gep x, 0, i". I tend to agree with Dan that we should only allow a variable index if the scale is 1.
-Chris
More information about the llvm-commits
mailing list