summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-01-07 06:25:07 +0000
committerChris Lattner <sabre@nondot.org>2009-01-07 06:25:07 +0000
commitd356a7ee0ed7744857dcf497cb20b0128770fb0f (patch)
treed8284ec25154219d590cbd2836b4e39382735791 /lib
parent8f90b6eb2fd0125f5b779de80954944f9071fb87 (diff)
downloadllvm-d356a7ee0ed7744857dcf497cb20b0128770fb0f.tar.gz
llvm-d356a7ee0ed7744857dcf497cb20b0128770fb0f.tar.bz2
llvm-d356a7ee0ed7744857dcf497cb20b0128770fb0f.tar.xz
Use the hasAllZeroIndices predicate to simplify some
code, no functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61849 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/ScalarReplAggregates.cpp34
1 files changed, 6 insertions, 28 deletions
diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
index 309512b15e..3a100647a7 100644
--- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp
+++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
@@ -377,23 +377,8 @@ void SROA::DoScalarReplacement(AllocationInst *AI,
}
// If this GEP is to the start of the aggregate, check for memcpys.
- if (Idx == 0) {
- bool IsStartOfAggregateGEP = true;
- for (unsigned i = 3, e = GEPI->getNumOperands(); i != e; ++i) {
- if (!isa<ConstantInt>(GEPI->getOperand(i))) {
- IsStartOfAggregateGEP = false;
- break;
- }
- if (!cast<ConstantInt>(GEPI->getOperand(i))->isZero()) {
- IsStartOfAggregateGEP = false;
- break;
- }
- }
-
- if (IsStartOfAggregateGEP)
- RewriteBitCastUserOfAlloca(GEPI, AI, ElementAllocas);
- }
-
+ if (Idx == 0 && GEPI->hasAllZeroIndices())
+ RewriteBitCastUserOfAlloca(GEPI, AI, ElementAllocas);
// Move all of the users over to the new GEP.
GEPI->replaceAllUsesWith(RepValue);
@@ -431,15 +416,8 @@ void SROA::isSafeElementUse(Value *Ptr, bool isFirstElt, AllocationInst *AI,
// Using pointer arithmetic to navigate the array.
return MarkUnsafe(Info);
- if (AreAllZeroIndices) {
- for (unsigned i = 2, e = GEP->getNumOperands(); i != e; ++i) {
- if (!isa<ConstantInt>(GEP->getOperand(i)) ||
- !cast<ConstantInt>(GEP->getOperand(i))->isZero()) {
- AreAllZeroIndices = false;
- break;
- }
- }
- }
+ if (AreAllZeroIndices)
+ AreAllZeroIndices = GEP->hasAllZeroIndices();
}
isSafeElementUse(GEP, AreAllZeroIndices, AI, Info);
if (Info.isUnsafe) return;
@@ -662,7 +640,7 @@ void SROA::RewriteBitCastUserOfAlloca(Instruction *BCInst, AllocationInst *AI,
// It is likely that OtherPtr is a bitcast, if so, remove it.
if (BitCastInst *BC = dyn_cast<BitCastInst>(OtherPtr))
OtherPtr = BC->getOperand(0);
- // All zero GEPs are effectively casts
+ // All zero GEPs are effectively bitcasts.
if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(OtherPtr))
if (GEP->hasAllZeroIndices())
OtherPtr = GEP->getOperand(0);
@@ -1062,7 +1040,7 @@ const Type *SROA::CanConvertToScalar(Value *V, bool &IsNotTrivial) {
isa<ConstantInt>(GEP->getOperand(2)) &&
cast<ConstantInt>(GEP->getOperand(1))->isZero()) {
// We are stepping into an element, e.g. a structure or an array:
- // GEP Ptr, int 0, uint C
+ // GEP Ptr, i32 0, i32 Cst
const Type *AggTy = PTy->getElementType();
unsigned Idx = cast<ConstantInt>(GEP->getOperand(2))->getZExtValue();