aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-08-30 05:00:50 +0000
committerChris Lattner <sabre@nondot.org>2009-08-30 05:00:50 +0000
commit95ba1ec4cbb14614f9ac26c9aabe5cac6640c4b0 (patch)
treee2364a1fbb208121e0d5410a237b1760a2e5f0d6 /lib/Transforms
parentc0f553e874121b6a0feb35e580040c02da05ac3c (diff)
downloadexternal_llvm-95ba1ec4cbb14614f9ac26c9aabe5cac6640c4b0.zip
external_llvm-95ba1ec4cbb14614f9ac26c9aabe5cac6640c4b0.tar.gz
external_llvm-95ba1ec4cbb14614f9ac26c9aabe5cac6640c4b0.tar.bz2
simplify/detangle some control flow.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80476 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp35
1 files changed, 15 insertions, 20 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 68a21ea..e155e7c 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -11044,21 +11044,18 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
// is a getelementptr instruction, combine the indices of the two
// getelementptr instructions into a single instruction.
//
- SmallVector<Value*, 8> SrcGEPOperands;
- bool BothInBounds = cast<GEPOperator>(&GEP)->isInBounds();
if (GEPOperator *Src = dyn_cast<GEPOperator>(PtrOp)) {
+ SmallVector<Value*, 8> SrcGEPOperands;
+
SrcGEPOperands.append(Src->op_begin(), Src->op_end());
- if (!Src->isInBounds())
- BothInBounds = false;
- }
-
- if (!SrcGEPOperands.empty()) {
+
// 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<GetElementPtrInst>(SrcGEPOperands[0]) &&
- cast<Instruction>(SrcGEPOperands[0])->getNumOperands() == 2)
+ if (SrcGEPOperands.empty() ||
+ (isa<GetElementPtrInst>(SrcGEPOperands[0]) &&
+ cast<Instruction>(SrcGEPOperands[0])->getNumOperands() == 2))
return 0; // Wait until our source is folded to completion.
SmallVector<Value*, 8> Indices;
@@ -11084,17 +11081,14 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
// target's pointer size.
if (SO1->getType() != GO1->getType()) {
if (Constant *SO1C = dyn_cast<Constant>(SO1)) {
- SO1 =
- ConstantExpr::getIntegerCast(SO1C, GO1->getType(), true);
+ SO1 = ConstantExpr::getIntegerCast(SO1C, GO1->getType(), true);
} else if (Constant *GO1C = dyn_cast<Constant>(GO1)) {
- GO1 =
- ConstantExpr::getIntegerCast(GO1C, SO1->getType(), true);
+ GO1 = ConstantExpr::getIntegerCast(GO1C, SO1->getType(), true);
} else if (TD) {
unsigned PS = TD->getPointerSizeInBits();
if (TD->getTypeSizeInBits(SO1->getType()) == PS) {
// Convert GO1 to SO1's type.
GO1 = InsertCastToIntPtrTy(GO1, SO1->getType(), &GEP, this);
-
} else if (TD->getTypeSizeInBits(GO1->getType()) == PS) {
// Convert SO1 to GO1's type.
SO1 = InsertCastToIntPtrTy(SO1, GO1->getType(), &GEP, this);
@@ -11136,15 +11130,16 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
GetElementPtrInst *NewGEP =
GetElementPtrInst::Create(SrcGEPOperands[0], Indices.begin(),
Indices.end(), GEP.getName());
- if (BothInBounds)
+ if (cast<GEPOperator>(&GEP)->isInBounds() && Src->isInBounds())
cast<GEPOperator>(NewGEP)->setIsInBounds(true);
return NewGEP;
}
-
- } else if (Value *X = getBitCastOperand(PtrOp)) { // Is the operand a cast?
- if (!isa<PointerType>(X->getType())) {
- // Not interesting. Source pointer must be a cast from pointer.
- } else if (HasZeroPointerIndex) {
+ }
+
+ if (Value *X = getBitCastOperand(PtrOp)) { // Is the operand a cast?
+ assert(isa<PointerType>(X->getType()) && "Must be cast from pointer");
+
+ if (HasZeroPointerIndex) {
// transform: GEP (bitcast [10 x i8]* X to [0 x i8]*), i32 0, ...
// into : GEP [10 x i8]* X, i32 0, ...
//