From 784e8d9177a692bf627695476e32c000fdb6eb73 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 30 Aug 2009 20:06:40 +0000 Subject: [PATCH] add getPointerAddressSpace() to GEP instruction, use the method in a few scalar xforms to simplify things. llvm-svn: 80506 --- include/llvm/Instructions.h | 4 ++++ lib/Transforms/Scalar/InstructionCombining.cpp | 10 ++++------ lib/Transforms/Scalar/SCCP.cpp | 3 +-- lib/Transforms/Scalar/SimplifyCFGPass.cpp | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index ee9657dbba9..4460f8890a5 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -570,6 +570,10 @@ public: static unsigned getPointerOperandIndex() { return 0U; // get index for modifying correct operand } + + unsigned getPointerAddressSpace() const { + return cast(getType())->getAddressSpace(); + } /// getPointerOperandType - Method to return the pointer operand as a /// PointerType. diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 47e6f4d5582..478068c95b5 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -11289,8 +11289,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { if (GetElementPtrInst *GEPI = dyn_cast(Op)) { const Value *GEPI0 = GEPI->getOperand(0); // TODO: Consider a target hook for valid address spaces for this xform. - if (isa(GEPI0) && - cast(GEPI0->getType())->getAddressSpace() == 0) { + if (isa(GEPI0) && GEPI->getPointerAddressSpace() == 0){ // Insert a new store to null instruction before the load to indicate // that this code is not reachable. We do this instead of inserting // an unreachable instruction directly because we cannot modify the @@ -11304,8 +11303,8 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { if (Constant *C = dyn_cast(Op)) { // load null/undef -> undef // TODO: Consider a target hook for valid address spaces for this xform. - if (isa(C) || (C->isNullValue() && - cast(Op->getType())->getAddressSpace() == 0)) { + if (isa(C) || + (C->isNullValue() && LI.getPointerAddressSpace() == 0)) { // Insert a new store to null instruction before the load to indicate that // this code is not reachable. We do this instead of inserting an // unreachable instruction directly because we cannot modify the CFG. @@ -11640,8 +11639,7 @@ Instruction *InstCombiner::visitStoreInst(StoreInst &SI) { if (SI.isVolatile()) return 0; // Don't hack volatile stores. // store X, null -> turns into 'unreachable' in SimplifyCFG - if (isa(Ptr) && - cast(Ptr->getType())->getAddressSpace() == 0) { + if (isa(Ptr) && SI.getPointerAddressSpace() == 0) { if (!isa(Val)) { SI.setOperand(0, UndefValue::get(Val->getType())); if (Instruction *U = dyn_cast(Val)) diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 3c6dcadaa76..155e91ec7b4 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -1131,8 +1131,7 @@ void SCCPSolver::visitLoadInst(LoadInst &I) { if (PtrVal.isConstant() && !I.isVolatile()) { Value *Ptr = PtrVal.getConstant(); // TODO: Consider a target hook for valid address spaces for this xform. - if (isa(Ptr) && - cast(Ptr->getType())->getAddressSpace() == 0) { + if (isa(Ptr) && I.getPointerAddressSpace() == 0) { // load null -> null markConstant(IV, &I, Constant::getNullValue(I.getType())); return; diff --git a/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/lib/Transforms/Scalar/SimplifyCFGPass.cpp index 5de79c49cfb..ca4292bcaa1 100644 --- a/lib/Transforms/Scalar/SimplifyCFGPass.cpp +++ b/lib/Transforms/Scalar/SimplifyCFGPass.cpp @@ -132,7 +132,7 @@ static bool MarkAliveBlocks(BasicBlock *BB, if (isa(Ptr) || (isa(Ptr) && - cast(Ptr->getType())->getAddressSpace() == 0)) { + SI->getPointerAddressSpace() == 0)) { ChangeToUnreachable(SI, Context); Changed = true; break;