From: Anton Korobeynikov Date: Wed, 20 Feb 2008 11:26:25 +0000 (+0000) Subject: Make Transforms to be 4.3 warnings-clean X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=07e6e56f57e8781a8d7bc601cc9034a3741d84c2;p=oota-llvm.git Make Transforms to be 4.3 warnings-clean git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47371 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index ef76a6e42d4..452fa9c741f 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -178,7 +178,7 @@ static bool AnalyzeGlobal(Value *V, GlobalStatus &GS, // If this is a direct store to the global (i.e., the global is a scalar // value, not an aggregate), keep more specific information about // stores. - if (GS.StoredType != GlobalStatus::isStored) + if (GS.StoredType != GlobalStatus::isStored) { if (GlobalVariable *GV = dyn_cast(SI->getOperand(1))){ Value *StoredVal = SI->getOperand(0); if (StoredVal == GV->getInitializer()) { @@ -201,6 +201,7 @@ static bool AnalyzeGlobal(Value *V, GlobalStatus &GS, } else { GS.StoredType = GlobalStatus::isStored; } + } } else if (isa(I)) { if (AnalyzeGlobal(I, GS, PHIUsers)) return true; } else if (isa(I)) { @@ -531,7 +532,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV) { Value *NewPtr = NewGlobals[Val]; // Form a shorter GEP if needed. - if (GEP->getNumOperands() > 3) + if (GEP->getNumOperands() > 3) { if (ConstantExpr *CE = dyn_cast(GEP)) { SmallVector Idxs; Idxs.push_back(NullInt); @@ -548,6 +549,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV) { NewPtr = new GetElementPtrInst(NewPtr, Idxs.begin(), Idxs.end(), GEPI->getName()+"."+utostr(Val), GEPI); } + } GEP->replaceAllUsesWith(NewPtr); if (GetElementPtrInst *GEPI = dyn_cast(GEP)) diff --git a/lib/Transforms/IPO/IPConstantPropagation.cpp b/lib/Transforms/IPO/IPConstantPropagation.cpp index 2fb22dfd76c..88cdbd0d71b 100644 --- a/lib/Transforms/IPO/IPConstantPropagation.cpp +++ b/lib/Transforms/IPO/IPConstantPropagation.cpp @@ -144,7 +144,7 @@ bool IPCP::PropagateConstantReturn(Function &F) { // Check to see if this function returns a constant. Value *RetVal = 0; for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) - if (ReturnInst *RI = dyn_cast(BB->getTerminator())) + if (ReturnInst *RI = dyn_cast(BB->getTerminator())) { if (isa(RI->getOperand(0))) { // Ignore. } else if (Constant *C = dyn_cast(RI->getOperand(0))) { @@ -155,6 +155,7 @@ bool IPCP::PropagateConstantReturn(Function &F) { } else { return false; // Does not return a constant. } + } if (RetVal == 0) RetVal = UndefValue::get(F.getReturnType()); diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index 481956f6b4c..5ad9cbbb2f1 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -174,17 +174,17 @@ template <> struct DenseMapInfo { hash = e.secondVN + hash * 37; hash = e.thirdVN + hash * 37; - hash = (unsigned)((uintptr_t)e.type >> 4) ^ - (unsigned)((uintptr_t)e.type >> 9) + - hash * 37; + hash = ((unsigned)((uintptr_t)e.type >> 4) ^ + (unsigned)((uintptr_t)e.type >> 9)) + + hash * 37; for (SmallVector::const_iterator I = e.varargs.begin(), E = e.varargs.end(); I != E; ++I) hash = *I + hash * 37; - hash = (unsigned)((uintptr_t)e.function >> 4) ^ - (unsigned)((uintptr_t)e.function >> 9) + - hash * 37; + hash = ((unsigned)((uintptr_t)e.function >> 4) ^ + (unsigned)((uintptr_t)e.function >> 9)) + + hash * 37; return hash; } diff --git a/lib/Transforms/Scalar/GVNPRE.cpp b/lib/Transforms/Scalar/GVNPRE.cpp index a2a221a405b..7d38dc75a1e 100644 --- a/lib/Transforms/Scalar/GVNPRE.cpp +++ b/lib/Transforms/Scalar/GVNPRE.cpp @@ -171,9 +171,9 @@ template <> struct DenseMapInfo { hash = e.secondVN + hash * 37; hash = e.thirdVN + hash * 37; - hash = (unsigned)((uintptr_t)e.type >> 4) ^ - (unsigned)((uintptr_t)e.type >> 9) + - hash * 37; + hash = ((unsigned)((uintptr_t)e.type >> 4) ^ + (unsigned)((uintptr_t)e.type >> 9)) + + hash * 37; for (SmallVector::const_iterator I = e.varargs.begin(), E = e.varargs.end(); I != E; ++I) @@ -1599,7 +1599,7 @@ void GVNPRE::insertion_pre(Value* e, BasicBlock* BB, isa(U) || isa(U) || isa(U) || - isa(U)) + isa(U)) { if (isa(U->getOperand(1)) || isa(U->getOperand(1)) || isa(U->getOperand(1)) || @@ -1612,12 +1612,13 @@ void GVNPRE::insertion_pre(Value* e, BasicBlock* BB, } else { s2 = U->getOperand(1); } + } // Ternary Operators Value* s3 = 0; if (isa(U) || isa(U) || - isa(U)) + isa(U)) { if (isa(U->getOperand(2)) || isa(U->getOperand(2)) || isa(U->getOperand(2)) || @@ -1630,6 +1631,7 @@ void GVNPRE::insertion_pre(Value* e, BasicBlock* BB, } else { s3 = U->getOperand(2); } + } // Vararg operators SmallVector sVarargs; diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index ba9ce568f33..12008956153 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2303,7 +2303,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) { // -(X >>u 31) -> (X >>s 31) // -(X >>s 31) -> (X >>u 31) if (C->isZero()) { - if (BinaryOperator *SI = dyn_cast(Op1)) + if (BinaryOperator *SI = dyn_cast(Op1)) { if (SI->getOpcode() == Instruction::LShr) { if (ConstantInt *CU = dyn_cast(SI->getOperand(1))) { // Check to see if we are shifting out everything but the sign bit. @@ -2325,7 +2325,8 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) { SI->getOperand(0), CU, SI->getName()); } } - } + } + } } // Try to fold constant sub into select arguments. @@ -2408,7 +2409,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) { } if (!Op0->getType()->isFPOrFPVector()) - if (BinaryOperator *Op0I = dyn_cast(Op0)) + if (BinaryOperator *Op0I = dyn_cast(Op0)) { if (Op0I->getOpcode() == Instruction::Add) { if (Op0I->getOperand(0) == Op1) // (Y+X)-Y == X return ReplaceInstUsesWith(I, Op0I->getOperand(1)); @@ -2418,6 +2419,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) { if (Op0I->getOperand(0) == Op1) // (X-Y)-X == -Y return BinaryOperator::createNeg(Op0I->getOperand(1), I.getName()); } + } ConstantInt *C1; if (Value *X = dyn_castFoldableMul(Op0, C1)) { @@ -3116,8 +3118,8 @@ struct FoldICmpLogical { bool shouldApply(Value *V) const { if (ICmpInst *ICI = dyn_cast(V)) if (PredicatesFoldable(pred, ICI->getPredicate())) - return (ICI->getOperand(0) == LHS && ICI->getOperand(1) == RHS || - ICI->getOperand(0) == RHS && ICI->getOperand(1) == LHS); + return ((ICI->getOperand(0) == LHS && ICI->getOperand(1) == RHS) || + (ICI->getOperand(0) == RHS && ICI->getOperand(1) == LHS)); return false; } Instruction *apply(Instruction &Log) const { @@ -3499,7 +3501,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) { if (Instruction *CastOp = dyn_cast(CI->getOperand(0))) { if ((isa(CI) || isa(CI)) && CastOp->getNumOperands() == 2) - if (ConstantInt *AndCI = dyn_cast(CastOp->getOperand(1))) + if (ConstantInt *AndCI = dyn_cast(CastOp->getOperand(1))) { if (CastOp->getOpcode() == Instruction::And) { // Change: and (cast (and X, C1) to T), C2 // into : and (cast X to T), trunc_or_bitcast(C1)&C2 @@ -3520,6 +3522,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) { if (ConstantExpr::getAnd(C3, AndRHS) == AndRHS) // trunc(C1)&C2 return ReplaceInstUsesWith(I, AndRHS); } + } } } @@ -4384,7 +4387,7 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { return BinaryOperator::createAdd(Op0I->getOperand(1), ConstantRHS); } - if (ConstantInt *Op0CI = dyn_cast(Op0I->getOperand(1))) + if (ConstantInt *Op0CI = dyn_cast(Op0I->getOperand(1))) { if (Op0I->getOpcode() == Instruction::Add) { // ~(X-c) --> (-c-1)-X if (RHS->isAllOnesValue()) { @@ -4414,6 +4417,7 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { return &I; } } + } } // Try to fold constant and into select arguments. @@ -5184,13 +5188,14 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { Op1 = CI2->getOperand(0); // If Op1 is a constant, we can fold the cast into the constant. - if (Op0->getType() != Op1->getType()) + if (Op0->getType() != Op1->getType()) { if (Constant *Op1C = dyn_cast(Op1)) { Op1 = ConstantExpr::getBitCast(Op1C, Op0->getType()); } else { // Otherwise, cast the RHS right before the icmp Op1 = InsertBitCastBefore(Op1, Op0->getType(), I); } + } return new ICmpInst(I.getPredicate(), Op0, Op1); } } @@ -5437,8 +5442,8 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, if (ConstantInt *XorCST = dyn_cast(LHSI->getOperand(1))) { // If this is a comparison that tests the signbit (X < 0) or (x > -1), // fold the xor. - if (ICI.getPredicate() == ICmpInst::ICMP_SLT && RHSV == 0 || - ICI.getPredicate() == ICmpInst::ICMP_SGT && RHSV.isAllOnesValue()) { + if ((ICI.getPredicate() == ICmpInst::ICMP_SLT && RHSV == 0) || + (ICI.getPredicate() == ICmpInst::ICMP_SGT && RHSV.isAllOnesValue())) { Value *CompareVal = LHSI->getOperand(0); // If the sign bit of the XorCST is not set, there is no change to @@ -8492,7 +8497,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { Args.push_back(Constant::getNullValue(FT->getParamType(i))); // If we are removing arguments to the function, emit an obnoxious warning... - if (FT->getNumParams() < NumActualArgs) + if (FT->getNumParams() < NumActualArgs) { if (!FT->isVarArg()) { cerr << "WARNING: While resolving call to function '" << Callee->getName() << "' arguments were dropped!\n"; @@ -8519,6 +8524,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { attrVec.push_back(ParamAttrsWithIndex::get(i + 1, PAttrs)); } } + } if (FT->getReturnType() == Type::VoidTy) Caller->setName(""); // Void type should not have a name. @@ -9131,7 +9137,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { // insert it. This explicit cast can make subsequent optimizations more // obvious. Value *Op = GEP.getOperand(i); - if (TD->getTypeSizeInBits(Op->getType()) > TD->getPointerSizeInBits()) + if (TD->getTypeSizeInBits(Op->getType()) > TD->getPointerSizeInBits()) { if (Constant *C = dyn_cast(Op)) { GEP.setOperand(i, ConstantExpr::getTrunc(C, TD->getIntPtrType())); MadeChange = true; @@ -9141,6 +9147,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { GEP.setOperand(i, Op); MadeChange = true; } + } } } if (MadeChange) return &GEP; @@ -9383,7 +9390,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) { // Convert: malloc Ty, C - where C is a constant != 1 into: malloc [C x Ty], 1 - if (AI.isArrayAllocation()) // Check C != 1 + if (AI.isArrayAllocation()) { // Check C != 1 if (const ConstantInt *C = dyn_cast(AI.getArraySize())) { const Type *NewTy = ArrayType::get(AI.getAllocatedType(), C->getZExtValue()); @@ -9421,6 +9428,7 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) { } else if (isa(AI.getArraySize())) { return ReplaceInstUsesWith(AI, Constant::getNullValue(AI.getType())); } + } // If alloca'ing a zero byte object, replace the alloca with a null pointer. // Note that we only do this for alloca's, because malloc should allocate and @@ -9669,7 +9677,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { return ReplaceInstUsesWith(LI, GV->getInitializer()); // Instcombine load (constantexpr_GEP global, 0, ...) into the value loaded. - if (ConstantExpr *CE = dyn_cast(Op)) + if (ConstantExpr *CE = dyn_cast(Op)) { if (CE->getOpcode() == Instruction::GetElementPtr) { if (GlobalVariable *GV = dyn_cast(CE->getOperand(0))) if (GV->isConstant() && !GV->isDeclaration()) @@ -9690,6 +9698,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { if (Instruction *Res = InstCombineLoadCast(*this, LI, TD)) return Res; } + } } // If this load comes from anywhere in a constant global, and if the global diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 07e70099769..561cdb1fbb4 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -1608,8 +1608,8 @@ bool IPSCCP::runOnModule(Module &M) { Instruction *Inst = BI++; if (Inst->getType() != Type::VoidTy) { LatticeVal &IV = Values[Inst]; - if (IV.isConstant() || IV.isUndefined() && - !isa(Inst)) { + if (IV.isConstant() || + (IV.isUndefined() && !isa(Inst))) { Constant *Const = IV.isConstant() ? IV.getConstant() : UndefValue::get(Inst->getType()); DOUT << " Constant: " << *Const << " = " << *Inst; diff --git a/lib/Transforms/Scalar/TailRecursionElimination.cpp b/lib/Transforms/Scalar/TailRecursionElimination.cpp index 5849254374d..0623abe5dd1 100644 --- a/lib/Transforms/Scalar/TailRecursionElimination.cpp +++ b/lib/Transforms/Scalar/TailRecursionElimination.cpp @@ -279,8 +279,8 @@ Value *TailCallElim::CanTransformAccumulatorRecursion(Instruction *I, "Associative operations should have 2 args!"); // Exactly one operand should be the result of the call instruction... - if (I->getOperand(0) == CI && I->getOperand(1) == CI || - I->getOperand(0) != CI && I->getOperand(1) != CI) + if ((I->getOperand(0) == CI && I->getOperand(1) == CI) || + (I->getOperand(0) != CI && I->getOperand(1) != CI)) return 0; // The only user of this instruction we allow is a single return instruction. diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp index 6b66e743fb1..1be1c729c04 100644 --- a/lib/Transforms/Utils/CodeExtractor.cpp +++ b/lib/Transforms/Utils/CodeExtractor.cpp @@ -680,7 +680,7 @@ ExtractCodeRegion(const std::vector &code) { PHINode *PN = cast(I); std::set ProcessedPreds; for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) - if (BlocksToExtract.count(PN->getIncomingBlock(i))) + if (BlocksToExtract.count(PN->getIncomingBlock(i))) { if (ProcessedPreds.insert(PN->getIncomingBlock(i)).second) PN->setIncomingBlock(i, codeReplacer); else { @@ -689,6 +689,7 @@ ExtractCodeRegion(const std::vector &code) { PN->removeIncomingValue(i, false); --i; --e; } + } } //cerr << "NEW FUNCTION: " << *newFunction; diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index c89ec60d695..2092c8b58a8 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -391,7 +391,7 @@ static bool DominatesMergePoint(Value *V, BasicBlock *BB, // icmp_eq instructions that compare a value against a constant, return the // value being compared, and stick the constant into the Values vector. static Value *GatherConstantSetEQs(Value *V, std::vector &Values){ - if (Instruction *Inst = dyn_cast(V)) + if (Instruction *Inst = dyn_cast(V)) { if (Inst->getOpcode() == Instruction::ICmp && cast(Inst)->getPredicate() == ICmpInst::ICMP_EQ) { if (ConstantInt *C = dyn_cast(Inst->getOperand(1))) { @@ -407,6 +407,7 @@ static Value *GatherConstantSetEQs(Value *V, std::vector &Values){ if (LHS == RHS) return LHS; } + } return 0; } @@ -414,7 +415,7 @@ static Value *GatherConstantSetEQs(Value *V, std::vector &Values){ // setne instructions that compare a value against a constant, return the value // being compared, and stick the constant into the Values vector. static Value *GatherConstantSetNEs(Value *V, std::vector &Values){ - if (Instruction *Inst = dyn_cast(V)) + if (Instruction *Inst = dyn_cast(V)) { if (Inst->getOpcode() == Instruction::ICmp && cast(Inst)->getPredicate() == ICmpInst::ICMP_NE) { if (ConstantInt *C = dyn_cast(Inst->getOperand(1))) { @@ -430,6 +431,7 @@ static Value *GatherConstantSetNEs(Value *V, std::vector &Values){ if (LHS == RHS) return LHS; } + } return 0; } @@ -658,11 +660,12 @@ static bool SimplifyEqualityComparisonWithOnlyPredecessor(TerminatorInst *TI, ConstantInt *TIV = 0; BasicBlock *TIBB = TI->getParent(); for (unsigned i = 0, e = PredCases.size(); i != e; ++i) - if (PredCases[i].second == TIBB) + if (PredCases[i].second == TIBB) { if (TIV == 0) TIV = PredCases[i].first; else return false; // Cannot handle multiple values coming to this block. + } assert(TIV && "No edge from pred to succ?"); // Okay, we found the one constant that our value can be if we get into TI's @@ -1190,8 +1193,8 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { "Can't Simplify entry block!"); // Remove basic blocks that have no predecessors... which are unreachable. - if (pred_begin(BB) == pred_end(BB) || - *pred_begin(BB) == BB && ++pred_begin(BB) == pred_end(BB)) { + if ((pred_begin(BB) == pred_end(BB)) || + (*pred_begin(BB) == BB && ++pred_begin(BB) == pred_end(BB))) { DOUT << "Removing BB: \n" << *BB; // Loop through all of our successors and make sure they know that one @@ -1235,11 +1238,12 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { SmallVector CondBranchPreds; for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { TerminatorInst *PTI = (*PI)->getTerminator(); - if (BranchInst *BI = dyn_cast(PTI)) + if (BranchInst *BI = dyn_cast(PTI)) { if (BI->isUnconditional()) UncondBranchPreds.push_back(*PI); else CondBranchPreds.push_back(BI); + } } // If we found some, do the transformation!