Eliminate calls to isInteger, generalizing code and tightening checks as needed.
authorChris Lattner <sabre@nondot.org>
Mon, 15 Jan 2007 01:55:30 +0000 (01:55 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 15 Jan 2007 01:55:30 +0000 (01:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33218 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/ExprTypeConvert.cpp
lib/Transforms/IPO/SimplifyLibCalls.cpp
lib/Transforms/Scalar/IndVarSimplify.cpp
lib/Transforms/Scalar/InstructionCombining.cpp
lib/Transforms/Scalar/LoopStrengthReduce.cpp
lib/Transforms/Scalar/ScalarReplAggregates.cpp
lib/Transforms/Utils/SimplifyCFG.cpp

index 9f99f956423ba68997b1ac8917f9a12800fa2524..63f3209401eba5f02fc221de36031a0b8e0527a2 100644 (file)
@@ -69,19 +69,19 @@ bool llvm::ExpressionConvertibleToType(Value *V, const Type *Ty,
 
   case Instruction::Add:
   case Instruction::Sub:
-    if (!Ty->isInteger() && !Ty->isFloatingPoint()) return false;
+    if (!Ty->isIntegral() && !Ty->isFloatingPoint()) return false;
     if (!ExpressionConvertibleToType(I->getOperand(0), Ty, CTMap, TD) ||
         !ExpressionConvertibleToType(I->getOperand(1), Ty, CTMap, TD))
       return false;
     break;
   case Instruction::LShr:
   case Instruction::AShr:
-    if (!Ty->isInteger()) return false;
+    if (!Ty->isIntegral()) return false;
     if (!ExpressionConvertibleToType(I->getOperand(0), Ty, CTMap, TD))
       return false;
     break;
   case Instruction::Shl:
-    if (!Ty->isInteger()) return false;
+    if (!Ty->isIntegral()) return false;
     if (!ExpressionConvertibleToType(I->getOperand(0), Ty, CTMap, TD))
       return false;
     break;
@@ -458,7 +458,7 @@ static bool OperandConvertibleToType(User *U, Value *V, const Type *Ty,
 
   case Instruction::Add:
   case Instruction::Sub: {
-    if (!Ty->isInteger() && !Ty->isFloatingPoint()) return false;
+    if (!Ty->isIntegral() && !Ty->isFloatingPoint()) return false;
 
     Value *OtherOp = I->getOperand((V == I->getOperand(0)) ? 1 : 0);
     return ValueConvertibleToType(I, Ty, CTMap, TD) &&
@@ -476,7 +476,7 @@ static bool OperandConvertibleToType(User *U, Value *V, const Type *Ty,
   case Instruction::AShr:
   case Instruction::Shl:
     if (I->getOperand(1) == V) return false;  // Cannot change shift amount type
-    if (!Ty->isInteger()) return false;
+    if (!Ty->isIntegral()) return false;
     return ValueConvertibleToType(I, Ty, CTMap, TD);
 
   case Instruction::Free:
@@ -634,8 +634,7 @@ static bool OperandConvertibleToType(User *U, Value *V, const Type *Ty,
       // arguments if possible.
       //
       for (unsigned i = 0, NA = FTy->getNumParams(); i < NA; ++i)
-        if (!FTy->getParamType(i)->canLosslesslyBitCastTo(
-              I->getOperand(i+1)->getType()))
+        if (FTy->getParamType(i) != I->getOperand(i+1)->getType())
           return false;   // Operands must have compatible types!
 
       // Okay, at this point, we know that all of the arguments can be
@@ -655,7 +654,7 @@ static bool OperandConvertibleToType(User *U, Value *V, const Type *Ty,
     // If we get this far, we know the value is in the varargs section of the
     // function!  We can convert if we don't reinterpret the value...
     //
-    return Ty->canLosslesslyBitCastTo(V->getType());
+    return isa<PointerType>(Ty) && isa<PointerType>(V->getType());
   }
   }
   return false;
index db0c492f7239f63a8a9c22fe9382c7b8422570d1..ea57ab0a21f1531e8015335793b7a7134a17c3c8 100644 (file)
@@ -398,7 +398,7 @@ struct ExitInMainOptimization : public LibCallOptimization {
   // Make sure the called function looks like exit (int argument, int return
   // type, external linkage, not varargs).
   virtual bool ValidateCalledFunction(const Function *F, SimplifyLibCalls &SLC){
-    return F->arg_size() >= 1 && F->arg_begin()->getType()->isInteger();
+    return F->arg_size() >= 1 && F->arg_begin()->getType()->isIntegral();
   }
 
   virtual bool OptimizeCall(CallInst* ci, SimplifyLibCalls& SLC) {
@@ -960,8 +960,8 @@ struct memcmpOptimization : public LibCallOptimization {
     Function::const_arg_iterator AI = F->arg_begin();
     if (F->arg_size() != 3 || !isa<PointerType>(AI->getType())) return false;
     if (!isa<PointerType>((++AI)->getType())) return false;
-    if (!(++AI)->getType()->isInteger()) return false;
-    if (!F->getReturnType()->isInteger()) return false;
+    if (!(++AI)->getType()->isIntegral()) return false;
+    if (!F->getReturnType()->isIntegral()) return false;
     return true;
   }
   
@@ -1725,8 +1725,8 @@ public:
     : LibCallOptimization("isascii", "Number of 'isascii' calls simplified") {}
   
   virtual bool ValidateCalledFunction(const Function *F, SimplifyLibCalls &SLC){
-    return F->arg_size() == 1 && F->arg_begin()->getType()->isInteger() && 
-           F->getReturnType()->isInteger();
+    return F->arg_size() == 1 && F->arg_begin()->getType()->isIntegral() && 
+           F->getReturnType()->isIntegral();
   }
   
   /// @brief Perform the isascii optimization.
index 5ef886e956c2084059c240a445c6ae7315e951fe..bcd7ed808d1e8fa02d6d5b080346220b85b74cf9 100644 (file)
@@ -325,7 +325,7 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L) {
     if (LI->getLoopFor(L->getBlocks()[i]) == L) {  // Not in a subloop...
       BasicBlock *BB = L->getBlocks()[i];
       for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) {
-        if (I->getType()->isInteger()) {      // Is an integer instruction
+        if (I->getType()->isIntegral()) {      // Is an integer instruction
           SCEVHandle SH = SE->getSCEV(I);
           if (SH->hasComputableLoopEvolution(L) ||    // Varies predictably
               HasConstantItCount) {
@@ -460,7 +460,7 @@ void IndVarSimplify::runOnLoop(Loop *L) {
 
   for (BasicBlock::iterator I = Header->begin(); isa<PHINode>(I); ++I) {
     PHINode *PN = cast<PHINode>(I);
-    if (PN->getType()->isInteger()) {  // FIXME: when we have fast-math, enable!
+    if (PN->getType()->isIntegral()) { // FIXME: when we have fast-math, enable!
       SCEVHandle SCEV = SE->getSCEV(PN);
       if (SCEV->hasComputableLoopEvolution(L))
         // FIXME: It is an extremely bad idea to indvar substitute anything more
@@ -574,7 +574,7 @@ void IndVarSimplify::runOnLoop(Loop *L) {
     if (LI->getLoopFor(L->getBlocks()[i]) == L) {  // Not in a subloop...
       BasicBlock *BB = L->getBlocks()[i];
       for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
-        if (I->getType()->isInteger() &&      // Is an integer instruction
+        if (I->getType()->isIntegral() &&      // Is an integer instruction
             !I->use_empty() &&
             !Rewriter.isInsertedInstruction(I)) {
           SCEVHandle SH = SE->getSCEV(I);
index e4db98ecb69ce4793b922e5185c90f14dac677ce..95b8330318a8e1bb58fefe4754da6e5ba9391679 100644 (file)
@@ -495,7 +495,7 @@ static inline Value *dyn_castNotVal(Value *V) {
 // Otherwise, return null.
 //
 static inline Value *dyn_castFoldableMul(Value *V, ConstantInt *&CST) {
-  if (V->hasOneUse() && V->getType()->isInteger())
+  if (V->hasOneUse() && V->getType()->isIntegral())
     if (Instruction *I = dyn_cast<Instruction>(V)) {
       if (I->getOpcode() == Instruction::Mul)
         if ((CST = dyn_cast<ConstantInt>(I->getOperand(1))))
@@ -1808,7 +1808,7 @@ FoundSExt:
   }
 
   // X + X --> X << 1
-  if (I.getType()->isInteger()) {
+  if (I.getType()->isIntegral() && I.getType() != Type::Int1Ty) {
     if (Instruction *Result = AssociativeOpt(I, AddRHS(RHS))) return Result;
 
     if (Instruction *RHSI = dyn_cast<Instruction>(RHS)) {
@@ -1933,7 +1933,7 @@ static Value *RemoveNoopCast(Value *V) {
   if (CastInst *CI = dyn_cast<CastInst>(V)) {
     const Type *CTy = CI->getType();
     const Type *OpTy = CI->getOperand(0)->getType();
-    if (CTy->isInteger() && OpTy->isInteger()) {
+    if (CTy->isIntegral() && OpTy->isIntegral()) {
       if (CTy->getPrimitiveSizeInBits() == OpTy->getPrimitiveSizeInBits())
         return RemoveNoopCast(CI->getOperand(0));
     } else if (isa<PointerType>(CTy) && isa<PointerType>(OpTy))
@@ -2412,7 +2412,7 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) {
 
   // If the sign bits of both operands are zero (i.e. we can prove they are
   // unsigned inputs), turn this into a udiv.
-  if (I.getType()->isInteger()) {
+  if (I.getType()->isIntegral()) {
     uint64_t Mask = 1ULL << (I.getType()->getPrimitiveSizeInBits()-1);
     if (MaskedValueIsZero(Op1, Mask) && MaskedValueIsZero(Op0, Mask)) {
       return BinaryOperator::createUDiv(Op0, Op1, I.getName());
@@ -5062,7 +5062,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
         Value *CastOp = Cast->getOperand(0);
         const Type *SrcTy = CastOp->getType();
         unsigned SrcTySize = SrcTy->getPrimitiveSizeInBits();
-        if (SrcTy->isInteger() && 
+        if (SrcTy->isIntegral() && 
             SrcTySize == Cast->getType()->getPrimitiveSizeInBits()) {
           // If this is an unsigned comparison, try to make the comparison use
           // smaller constant values.
@@ -6395,7 +6395,7 @@ Instruction *InstCombiner::visitBitCast(CastInst &CI) {
   const Type *SrcTy = Src->getType();
   const Type *DestTy = CI.getType();
 
-  if (SrcTy->isInteger() && DestTy->isInteger()) {
+  if (SrcTy->isIntegral() && DestTy->isIntegral()) {
     if (Instruction *Result = commonIntCastTransforms(CI))
       return Result;
   } else {
@@ -6816,7 +6816,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
       }
 
   // See if we can fold the select into one of our operands.
-  if (SI.getType()->isInteger()) {
+  if (SI.getType()->isIntegral()) {
     // See the comment above GetSelectFoldableOperands for a description of the
     // transformation we are doing here.
     if (Instruction *TVI = dyn_cast<Instruction>(TrueVal))
@@ -7667,7 +7667,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
         Value *Src = CI->getOperand(0);
         const Type *SrcTy = Src->getType();
         const Type *DestTy = CI->getType();
-        if (Src->getType()->isInteger()) {
+        if (Src->getType()->isIntegral()) {
           if (SrcTy->getPrimitiveSizeInBits() ==
                        DestTy->getPrimitiveSizeInBits()) {
             // We can always eliminate a cast from ulong or long to the other.
@@ -7998,7 +7998,7 @@ static Instruction *InstCombineLoadCast(InstCombiner &IC, LoadInst &LI) {
   if (const PointerType *SrcTy = dyn_cast<PointerType>(CastOp->getType())) {
     const Type *SrcPTy = SrcTy->getElementType();
 
-    if (DestPTy->isInteger() || isa<PointerType>(DestPTy) || 
+    if (DestPTy->isIntegral() || isa<PointerType>(DestPTy) || 
         isa<PackedType>(DestPTy)) {
       // If the source is an array, the code below will not succeed.  Check to
       // see if a trivial 'gep P, 0, 0' will help matters.  Only do this for
@@ -8012,7 +8012,7 @@ static Instruction *InstCombineLoadCast(InstCombiner &IC, LoadInst &LI) {
             SrcPTy = SrcTy->getElementType();
           }
 
-      if ((SrcPTy->isInteger() || isa<PointerType>(SrcPTy) || 
+      if ((SrcPTy->isIntegral() || isa<PointerType>(SrcPTy) || 
            isa<PackedType>(SrcPTy)) &&
           // Do not allow turning this into a load of an integer, which is then
           // casted to a pointer, this pessimizes pointer analysis a lot.
@@ -8186,7 +8186,7 @@ static Instruction *InstCombineStoreToCast(InstCombiner &IC, StoreInst &SI) {
   if (const PointerType *SrcTy = dyn_cast<PointerType>(CastOp->getType())) {
     const Type *SrcPTy = SrcTy->getElementType();
 
-    if (DestPTy->isInteger() || isa<PointerType>(DestPTy)) {
+    if (DestPTy->isIntegral() || isa<PointerType>(DestPTy)) {
       // If the source is an array, the code below will not succeed.  Check to
       // see if a trivial 'gep P, 0, 0' will help matters.  Only do this for
       // constants.
@@ -8199,7 +8199,7 @@ static Instruction *InstCombineStoreToCast(InstCombiner &IC, StoreInst &SI) {
             SrcPTy = SrcTy->getElementType();
           }
 
-      if ((SrcPTy->isInteger() || isa<PointerType>(SrcPTy)) &&
+      if ((SrcPTy->isIntegral() || isa<PointerType>(SrcPTy)) &&
           IC.getTargetData().getTypeSize(SrcPTy) ==
                IC.getTargetData().getTypeSize(DestPTy)) {
 
index 798fb81190f4b09a7d376376b2d042fc00d1d841..fcc5630ef86d6f192737fefaa1e66e515a2d4e13 100644 (file)
@@ -398,7 +398,7 @@ static bool IVUseShouldUsePostIncValue(Instruction *User, Instruction *IV,
 /// return true.  Otherwise, return false.
 bool LoopStrengthReduce::AddUsersIfInteresting(Instruction *I, Loop *L,
                                             std::set<Instruction*> &Processed) {
-  if (!I->getType()->isInteger() && !isa<PointerType>(I->getType()))
+  if (!I->getType()->isIntegral() && !isa<PointerType>(I->getType()))
       return false;   // Void and FP expressions cannot be reduced.
   if (!Processed.insert(I).second)
     return true;    // Instruction already handled.
index a92459b8094111462d1cf15c5c76082c4c341f8e..587e0e589b4ba6518b6e6f3c3f187959f559eb64 100644 (file)
@@ -541,7 +541,7 @@ const Type *SROA::CanConvertToScalar(Value *V, bool &IsNotTrivial) {
         IsNotTrivial = true;
         const Type *SubElt = CanConvertToScalar(GEP, IsNotTrivial);
         if (SubElt == 0) return 0;
-        if (SubElt != Type::VoidTy && SubElt->isInteger()) {
+        if (SubElt != Type::VoidTy && SubElt->isIntegral()) {
           const Type *NewTy = 
             getUIntAtLeastAsBitAs(TD.getTypeSize(SubElt)*8+BitOffset);
           if (NewTy == 0 || MergeInType(NewTy, UsedType, TD)) return 0;
@@ -653,7 +653,7 @@ void SROA::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI, unsigned Offset) {
           // an integer.
           NV = new BitCastInst(NV, LI->getType(), LI->getName(), LI);
         } else {
-          assert(NV->getType()->isInteger() && "Unknown promotion!");
+          assert(NV->getType()->isIntegral() && "Unknown promotion!");
           if (Offset && Offset < TD.getTypeSize(NV->getType())*8) {
             NV = new ShiftInst(Instruction::LShr, NV, 
                                ConstantInt::get(Type::Int8Ty, Offset), 
index 25bc16866f37269dbae2f480fe8ec4d3407e3a78..99eef52d1faa2afd36cb1023a170fbbab5370131 100644 (file)
@@ -1852,7 +1852,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
         Value *CompVal = 0;
         std::vector<ConstantInt*> Values;
         bool TrueWhenEqual = GatherValueComparisons(Cond, CompVal, Values);
-        if (CompVal && CompVal->getType()->isInteger()) {
+        if (CompVal && CompVal->getType()->isIntegral()) {
           // There might be duplicate constants in the list, which the switch
           // instruction can't handle, remove them now.
           std::sort(Values.begin(), Values.end(), ConstantIntOrdering());