aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorMatthijs Kooijman <matthijs@stdin.nl>2008-10-13 15:17:01 +0000
committerMatthijs Kooijman <matthijs@stdin.nl>2008-10-13 15:17:01 +0000
commit7e6d9b96ad2c63e3a503c74bed14783eacb8123d (patch)
treea59ba034332b6bed689040cdebab1dd73b646bfd /lib/Transforms
parente49d0bc946a3f658da0e82e207bc87f59a2aa587 (diff)
Make InstructionCombining::getBitCastOperand() recognize GEP instructions and
constant expression with all zero indices as being the same as a bitcast. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57442 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 162e1bf3a9..b85f77dab1 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -436,14 +436,34 @@ static const Type *getPromotedType(const Type *Ty) {
return Ty;
}
-/// getBitCastOperand - If the specified operand is a CastInst or a constant
-/// expression bitcast, return the operand value, otherwise return null.
+/// getBitCastOperand - If the specified operand is a CastInst, a constant
+/// expression bitcast, or a GetElementPtrInst with all zero indices, return the
+/// operand value, otherwise return null.
static Value *getBitCastOperand(Value *V) {
if (BitCastInst *I = dyn_cast<BitCastInst>(V))
+ // BitCastInst?
return I->getOperand(0);
- else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
+ else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(V)) {
+ // GetElementPtrInst?
+ if (GEP->hasAllZeroIndices())
+ return GEP->getOperand(0);
+ } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
if (CE->getOpcode() == Instruction::BitCast)
+ // BitCast ConstantExp?
return CE->getOperand(0);
+ else if (CE->getOpcode() == Instruction::GetElementPtr) {
+ // GetElementPtr ConstantExp?
+ for (User::op_iterator I = CE->op_begin() + 1, E = CE->op_end();
+ I != E; ++I) {
+ ConstantInt *CI = dyn_cast<ConstantInt>(I);
+ if (!CI || !CI->isZero())
+ // Any non-zero indices? Not cast-like.
+ return 0;
+ }
+ // All-zero indices? This is just like casting.
+ return CE->getOperand(0);
+ }
+ }
return 0;
}