From e1019db65836e2dd1cd9521435e21be5deeaeaa2 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 17 Jul 2009 23:55:56 +0000 Subject: Convert more code to use Operator instead of explicitly handling both ConstantExpr and Instruction. This involves duplicating some code between GetElementPtrInst and GEPOperator, but it's not a lot. llvm-svn: 76265 --- .../lib/Transforms/Scalar/InstructionCombining.cpp | 29 +++++----------------- 1 file changed, 6 insertions(+), 23 deletions(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index dbdf449f60f..060abc5ad08 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -441,29 +441,12 @@ static const Type *getPromotedType(const Type *Ty) { /// 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(V)) - // BitCastInst? - return I->getOperand(0); - else if (GetElementPtrInst *GEP = dyn_cast(V)) { - // GetElementPtrInst? - if (GEP->hasAllZeroIndices()) - return GEP->getOperand(0); - } else if (ConstantExpr *CE = dyn_cast(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(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); - } + if (Operator *O = dyn_cast(V)) { + if (O->getOpcode() == Instruction::BitCast) + return O->getOperand(0); + if (GEPOperator *GEP = dyn_cast(V)) + if (GEP->hasAllZeroIndices()) + return GEP->getPointerOperand(); } return 0; } -- cgit v1.2.3