diff options
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/IPO/DeadTypeElimination.cpp | 7 | ||||
-rw-r--r-- | lib/Transforms/IPO/SimplifyLibCalls.cpp | 18 | ||||
-rw-r--r-- | lib/Transforms/Scalar/IndVarSimplify.cpp | 20 | ||||
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 33 | ||||
-rw-r--r-- | lib/Transforms/Scalar/SCCP.cpp | 2 | ||||
-rw-r--r-- | lib/Transforms/Scalar/ScalarReplAggregates.cpp | 7 |
6 files changed, 50 insertions, 37 deletions
diff --git a/lib/Transforms/IPO/DeadTypeElimination.cpp b/lib/Transforms/IPO/DeadTypeElimination.cpp index 871bcff..b599e5a 100644 --- a/lib/Transforms/IPO/DeadTypeElimination.cpp +++ b/lib/Transforms/IPO/DeadTypeElimination.cpp @@ -52,11 +52,14 @@ ModulePass *llvm::createDeadTypeEliminationPass() { // static inline bool ShouldNukeSymtabEntry(const Type *Ty){ // Nuke all names for primitive types! - if (Ty->isPrimitiveType()) return true; + if (Ty->isPrimitiveType() || Ty->isIntegral()) + return true; // Nuke all pointers to primitive types as well... if (const PointerType *PT = dyn_cast<PointerType>(Ty)) - if (PT->getElementType()->isPrimitiveType()) return true; + if (PT->getElementType()->isPrimitiveType() || + PT->getElementType()->isIntegral()) + return true; return false; } diff --git a/lib/Transforms/IPO/SimplifyLibCalls.cpp b/lib/Transforms/IPO/SimplifyLibCalls.cpp index d2ab638..70821f8 100644 --- a/lib/Transforms/IPO/SimplifyLibCalls.cpp +++ b/lib/Transforms/IPO/SimplifyLibCalls.cpp @@ -1820,13 +1820,17 @@ public: // ffsll(x) -> x == 0 ? 0 : llvm.cttz(x)+1 const Type *ArgType = TheCall->getOperand(1)->getType(); const char *CTTZName; - switch (ArgType->getTypeID()) { - default: assert(0 && "Unknown unsigned type!"); - case Type::Int8TyID : CTTZName = "llvm.cttz.i8" ; break; - case Type::Int16TyID: CTTZName = "llvm.cttz.i16"; break; - case Type::Int32TyID : CTTZName = "llvm.cttz.i32"; break; - case Type::Int64TyID : CTTZName = "llvm.cttz.i64"; break; - } + assert(ArgType->getTypeID() == Type::IntegerTyID && + "llvm.cttz argument is not an integer?"); + unsigned BitWidth = cast<IntegerType>(ArgType)->getBitWidth(); + if (BitWidth <= 8) + CTTZName = "llvm.cttz.i8"; + else if (BitWidth <= 16) + CTTZName = "llvm.cttz.i16"; + else if (BitWidth <= 32) + CTTZName = "llvm.cttz.i32"; + else + CTTZName = "llvm.cttz.i64"; Constant *F = SLC.getModule()->getOrInsertFunction(CTTZName, ArgType, ArgType, NULL); diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index a5a9f69..0643e75 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -50,6 +50,7 @@ #include "llvm/Support/GetElementPtrTypeIterator.h" #include "llvm/Transforms/Utils/Local.h" #include "llvm/Support/CommandLine.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" using namespace llvm; @@ -528,18 +529,27 @@ void IndVarSimplify::runOnLoop(Loop *L) { // induction variable to the right size for them, avoiding the need for the // code evaluation methods to insert induction variables of different sizes. if (DifferingSizes) { - bool InsertedSizes[17] = { false }; - InsertedSizes[LargestType->getPrimitiveSize()] = true; - for (unsigned i = 0, e = IndVars.size(); i != e; ++i) - if (!InsertedSizes[IndVars[i].first->getType()->getPrimitiveSize()]) { + SmallVector<unsigned,4> InsertedSizes; + InsertedSizes.push_back(LargestType->getPrimitiveSizeInBits()); + for (unsigned i = 0, e = IndVars.size(); i != e; ++i) { + unsigned ithSize = IndVars[i].first->getType()->getPrimitiveSizeInBits(); + bool alreadyInsertedSize = false; + for (SmallVector<unsigned,4>::iterator I = InsertedSizes.begin(), + E = InsertedSizes.end(); I != E; ++I) + if (*I == ithSize) { + alreadyInsertedSize = true; + break; + } + if (!alreadyInsertedSize) { PHINode *PN = IndVars[i].first; - InsertedSizes[PN->getType()->getPrimitiveSize()] = true; + InsertedSizes.push_back(ithSize); Instruction *New = new TruncInst(IndVar, PN->getType(), "indvar", InsertPt); Rewriter.addInsertedValue(New, SE->getSCEV(New)); DOUT << "INDVARS: Made trunc IV for " << *PN << " NewVal = " << *New << "\n"; } + } } // Rewrite all induction variables in terms of the canonical induction diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index c039b39..aecc9a9 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -339,12 +339,12 @@ static bool isOnlyUse(Value *V) { // getPromotedType - Return the specified type promoted as it would be to pass // though a va_arg area... static const Type *getPromotedType(const Type *Ty) { - switch (Ty->getTypeID()) { - case Type::Int8TyID: - case Type::Int16TyID: return Type::Int32Ty; - case Type::FloatTyID: return Type::DoubleTy; - default: return Ty; - } + if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty)) { + if (ITy->getBitWidth() < 32) + return Type::Int32Ty; + } else if (Ty == Type::FloatTy) + return Type::DoubleTy; + return Ty; } /// getBitCastOperand - If the specified operand is a CastInst or a constant @@ -531,7 +531,6 @@ static ConstantInt *SubOne(ConstantInt *C) { ConstantInt::get(C->getType(), 1))); } - /// ComputeMaskedBits - Determine which of the bits specified in Mask are /// known to be either zero or one and return them in the KnownZero/KnownOne /// bitsets. This code only analyzes bits in Mask, in order to short-circuit @@ -3516,7 +3515,7 @@ Instruction *InstCombiner::MatchBSwap(BinaryOperator &I) { /// ByteValues - For each byte of the result, we keep track of which value /// defines each byte. std::vector<Value*> ByteValues; - ByteValues.resize(I.getType()->getPrimitiveSize()); + ByteValues.resize(TD->getTypeSize(I.getType())); // Try to find all the pieces corresponding to the bswap. if (CollectBSwapParts(I.getOperand(0), ByteValues) || @@ -6580,9 +6579,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) { } if (SI.getType() == Type::Int1Ty) { - ConstantInt *C; - if ((C = dyn_cast<ConstantInt>(TrueVal)) && - C->getType() == Type::Int1Ty) { + if (ConstantInt *C = dyn_cast<ConstantInt>(TrueVal)) { if (C->getZExtValue()) { // Change: A = select B, true, C --> A = or B, C return BinaryOperator::createOr(CondVal, FalseVal); @@ -6593,8 +6590,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) { "not."+CondVal->getName()), SI); return BinaryOperator::createAnd(NotCond, FalseVal); } - } else if ((C = dyn_cast<ConstantInt>(FalseVal)) && - C->getType() == Type::Int1Ty) { + } else if (ConstantInt *C = dyn_cast<ConstantInt>(FalseVal)) { if (C->getZExtValue() == false) { // Change: A = select B, C, false --> A = and B, C return BinaryOperator::createAnd(CondVal, TrueVal); @@ -7649,7 +7645,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { } } else if (SrcTy->getPrimitiveSizeInBits() < DestTy->getPrimitiveSizeInBits() && - SrcTy->getPrimitiveSize() == 4) { + SrcTy->getPrimitiveSizeInBits() == 32) { // We can eliminate a cast from [u]int to [u]long iff the target // is a 32-bit pointer target. if (SrcTy->getPrimitiveSizeInBits() >= TD->getPointerSizeInBits()) { @@ -7664,7 +7660,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { // insert it. This explicit cast can make subsequent optimizations more // obvious. Value *Op = GEP.getOperand(i); - if (Op->getType()->getPrimitiveSize() > TD->getPointerSize()) + if (TD->getTypeSize(Op->getType()) > TD->getPointerSize()) if (Constant *C = dyn_cast<Constant>(Op)) { GEP.setOperand(i, ConstantExpr::getTrunc(C, TD->getIntPtrType())); MadeChange = true; @@ -7722,11 +7718,11 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { GO1 = ConstantExpr::getIntegerCast(GO1C, SO1->getType(), true); } else { unsigned PS = TD->getPointerSize(); - if (SO1->getType()->getPrimitiveSize() == PS) { + if (TD->getTypeSize(SO1->getType()) == PS) { // Convert GO1 to SO1's type. GO1 = InsertCastToIntPtrTy(GO1, SO1->getType(), &GEP, this); - } else if (GO1->getType()->getPrimitiveSize() == PS) { + } else if (TD->getTypeSize(GO1->getType()) == PS) { // Convert SO1 to GO1's type. SO1 = InsertCastToIntPtrTy(SO1, GO1->getType(), &GEP, this); } else { @@ -9056,8 +9052,7 @@ static void AddReachableCodeToWorklist(BasicBlock *BB, // only visit the reachable successor. TerminatorInst *TI = BB->getTerminator(); if (BranchInst *BI = dyn_cast<BranchInst>(TI)) { - if (BI->isConditional() && isa<ConstantInt>(BI->getCondition()) && - BI->getCondition()->getType() == Type::Int1Ty) { + if (BI->isConditional() && isa<ConstantInt>(BI->getCondition())) { bool CondVal = cast<ConstantInt>(BI->getCondition())->getZExtValue(); AddReachableCodeToWorklist(BI->getSuccessor(!CondVal), Visited, WorkList, TD); diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 2bc0004..1ebc1cf 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -1611,7 +1611,7 @@ bool IPSCCP::runOnModule(Module &M) { Instruction *I = cast<Instruction>(DeadBB->use_back()); bool Folded = ConstantFoldTerminator(I->getParent()); if (!Folded) { - // The constant folder may not have been able to fold the termiantor + // The constant folder may not have been able to fold the terminator // if this is a branch or switch on undef. Fold it manually as a // branch to the first successor. if (BranchInst *BI = dyn_cast<BranchInst>(I)) { diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp index 00e5818..a92459b 100644 --- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp +++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp @@ -444,7 +444,8 @@ static bool MergeInType(const Type *In, const Type *&Accum, // Noop. } else if (In->isIntegral() && Accum->isIntegral()) { // integer union. // Otherwise pick whichever type is larger. - if (In->getTypeID() > Accum->getTypeID()) + if (cast<IntegerType>(In)->getBitWidth() > + cast<IntegerType>(Accum)->getBitWidth()) Accum = In; } else if (isa<PointerType>(In) && isa<PointerType>(Accum)) { // Pointer unions just stay as one of the pointers. @@ -643,8 +644,8 @@ void SROA::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI, unsigned Offset) { } else { // Must be an element access. unsigned Elt = Offset/(TD.getTypeSize(PTy->getElementType())*8); - NV = new ExtractElementInst(NV, ConstantInt::get(Type::Int32Ty, Elt), - "tmp", LI); + NV = new ExtractElementInst( + NV, ConstantInt::get(Type::Int32Ty, Elt), "tmp", LI); } } else if (isa<PointerType>(NV->getType())) { assert(isa<PointerType>(LI->getType())); |