Changes in directory llvm/lib/Transforms/IPO:
ArgumentPromotion.cpp updated: 1.27 -> 1.27.2.1 GlobalOpt.cpp updated: 1.68.2.1 -> 1.68.2.2 SimplifyLibCalls.cpp updated: 1.69.2.1 -> 1.69.2.2 --- Log message: Make some simplifications for ConstantInt: 1. Get rid of getRawValue, replace with getZExtValue 2. Single constructor (uint64_t) and get method (int64_t) 3. Canonicalize the constant to a zero extended unsigned 64-bit integer when it is created. 4. Adjust getZExtValue() to be a do-nothing (just returns the already canonicalized value). 5. Compensate for above changes everywhere else. --- Diffs of the changes: (+32 -33) ArgumentPromotion.cpp | 6 +++--- GlobalOpt.cpp | 21 ++++++++++----------- SimplifyLibCalls.cpp | 38 +++++++++++++++++++------------------- 3 files changed, 32 insertions(+), 33 deletions(-) Index: llvm/lib/Transforms/IPO/ArgumentPromotion.cpp diff -u llvm/lib/Transforms/IPO/ArgumentPromotion.cpp:1.27 llvm/lib/Transforms/IPO/ArgumentPromotion.cpp:1.27.2.1 --- llvm/lib/Transforms/IPO/ArgumentPromotion.cpp:1.27 Tue Oct 3 02:26:07 2006 +++ llvm/lib/Transforms/IPO/ArgumentPromotion.cpp Thu Oct 19 19:34:44 2006 @@ -307,8 +307,8 @@ unsigned idx = 0; for (; idx < LHS.size() && idx < RHS.size(); ++idx) { if (LHS[idx] != RHS[idx]) { - return cast<ConstantInt>(LHS[idx])->getRawValue() < - cast<ConstantInt>(RHS[idx])->getRawValue(); + return cast<ConstantInt>(LHS[idx])->getZExtValue() < + cast<ConstantInt>(RHS[idx])->getZExtValue(); } } @@ -518,7 +518,7 @@ std::string NewName = I->getName(); for (unsigned i = 0, e = Operands.size(); i != e; ++i) if (ConstantInt *CI = dyn_cast<ConstantInt>(Operands[i])) - NewName += "."+itostr((int64_t)CI->getRawValue()); + NewName += "."+itostr((int64_t)CI->getZExtValue()); else NewName += ".x"; TheArg->setName(NewName+".val"); Index: llvm/lib/Transforms/IPO/GlobalOpt.cpp diff -u llvm/lib/Transforms/IPO/GlobalOpt.cpp:1.68.2.1 llvm/lib/Transforms/IPO/GlobalOpt.cpp:1.68.2.2 --- llvm/lib/Transforms/IPO/GlobalOpt.cpp:1.68.2.1 Wed Oct 18 22:57:56 2006 +++ llvm/lib/Transforms/IPO/GlobalOpt.cpp Thu Oct 19 19:34:44 2006 @@ -270,7 +270,7 @@ static Constant *getAggregateConstantElement(Constant *Agg, Constant *Idx) { ConstantInt *CI = dyn_cast<ConstantInt>(Idx); if (!CI) return 0; - unsigned IdxV = (unsigned)CI->getRawValue(); + unsigned IdxV = CI->getZExtValue(); if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Agg)) { if (IdxV < CS->getNumOperands()) return CS->getOperand(IdxV); @@ -435,8 +435,7 @@ // Ignore the 1th operand, which has to be zero or else the program is quite // broken (undefined). Get the 2nd operand, which is the structure or array // index. - unsigned Val = - (unsigned)cast<ConstantInt>(GEP->getOperand(2))->getRawValue(); + unsigned Val = cast<ConstantInt>(GEP->getOperand(2))->getZExtValue(); if (Val >= NewGlobals.size()) Val = 0; // Out of bound array access. Value *NewPtr = NewGlobals[Val]; @@ -673,11 +672,11 @@ DEBUG(std::cerr << "PROMOTING MALLOC GLOBAL: " << *GV << " MALLOC = " <<*MI); ConstantInt *NElements = cast<ConstantInt>(MI->getArraySize()); - if (NElements->getRawValue() != 1) { + if (NElements->getZExtValue() != 1) { // If we have an array allocation, transform it to a single element // allocation to make the code below simpler. Type *NewTy = ArrayType::get(MI->getAllocatedType(), - (unsigned)NElements->getRawValue()); + NElements->getZExtValue()); MallocInst *NewMI = new MallocInst(NewTy, Constant::getNullValue(Type::UIntTy), MI->getAlignment(), MI->getName(), MI); @@ -1089,7 +1088,7 @@ // Restrict this transformation to only working on small allocations // (2048 bytes currently), as we don't want to introduce a 16M global or // something. - if (NElements->getRawValue()* + if (NElements->getZExtValue()* TD.getTypeSize(MI->getAllocatedType()) < 2048) { GVI = OptimizeGlobalAddressOfMalloc(GV, MI); return true; @@ -1432,7 +1431,7 @@ // Init priority must be standard. ConstantInt *CI = dyn_cast<ConstantInt>(CS->getOperand(0)); - if (!CI || CI->getRawValue() != 65535) + if (!CI || CI->getZExtValue() != 65535) return 0; } else { return 0; @@ -1577,7 +1576,7 @@ // Replace the element that we are supposed to. ConstantInt *CU = cast<ConstantInt>(Addr->getOperand(OpNo)); - unsigned Idx = (unsigned)CU->getZExtValue(); + unsigned Idx = CU->getZExtValue(); assert(Idx < STy->getNumElements() && "Struct index out of range!"); Elts[Idx] = EvaluateStoreInto(Elts[Idx], Val, Addr, OpNo+1); @@ -1603,9 +1602,9 @@ " ConstantFoldLoadThroughGEPConstantExpr"); } - assert((uint64_t)CI->getRawValue() < ATy->getNumElements()); - Elts[(uint64_t)CI->getRawValue()] = - EvaluateStoreInto(Elts[(uint64_t)CI->getRawValue()], Val, Addr, OpNo+1); + assert(CI->getZExtValue() < ATy->getNumElements()); + Elts[CI->getZExtValue()] = + EvaluateStoreInto(Elts[CI->getZExtValue()], Val, Addr, OpNo+1); return ConstantArray::get(ATy, Elts); } } Index: llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp diff -u llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.69.2.1 llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.69.2.2 --- llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.69.2.1 Wed Oct 18 22:57:56 2006 +++ llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp Thu Oct 19 19:34:44 2006 @@ -723,7 +723,7 @@ bool len_arg_is_const = false; if (ConstantInt* len_CI = dyn_cast<ConstantInt>(ci->getOperand(3))) { len_arg_is_const = true; - len_arg = len_CI->getRawValue(); + len_arg = len_CI->getZExtValue(); if (len_arg == 0) { // strncmp(x,y,0) -> 0 ci->replaceAllUsesWith(ConstantInt::get(Type::IntTy,0)); @@ -891,7 +891,7 @@ if (ConstantInt* CI = dyn_cast<ConstantInt>(bop->getOperand(1))) { // Get the value the strlen result is compared to - uint64_t val = CI->getRawValue(); + uint64_t val = CI->getZExtValue(); // If its compared against length 0 with == or != if (val == 0 && @@ -985,7 +985,7 @@ // Make sure we have a constant length. ConstantInt *LenC = dyn_cast<ConstantInt>(CI->getOperand(3)); if (!LenC) return false; - uint64_t Len = LenC->getRawValue(); + uint64_t Len = LenC->getZExtValue(); // If the length is zero, this returns 0. switch (Len) { @@ -1075,8 +1075,8 @@ return false; // If the length is larger than the alignment, we can't optimize - uint64_t len = LEN->getRawValue(); - uint64_t alignment = ALIGN->getRawValue(); + uint64_t len = LEN->getZExtValue(); + uint64_t alignment = ALIGN->getZExtValue(); if (alignment == 0) alignment = 1; // Alignment 0 is identity for alignment 1 if (len > alignment) @@ -1154,8 +1154,8 @@ return false; // Extract the length and alignment - uint64_t len = LEN->getRawValue(); - uint64_t alignment = ALIGN->getRawValue(); + uint64_t len = LEN->getZExtValue(); + uint64_t alignment = ALIGN->getZExtValue(); // Alignment 0 is identity for alignment 1 if (alignment == 0) @@ -1325,16 +1325,16 @@ // The first character has to be a % if (ConstantInt* CI = dyn_cast<ConstantInt>(CA->getOperand(0))) - if (CI->getRawValue() != '%') + if (CI->getZExtValue() != '%') return false; // Get the second character and switch on its value ConstantInt* CI = dyn_cast<ConstantInt>(CA->getOperand(1)); - switch (CI->getRawValue()) { + switch (CI->getZExtValue()) { case 's': { if (len != 3 || - dyn_cast<ConstantInt>(CA->getOperand(2))->getRawValue() != '\n') + dyn_cast<ConstantInt>(CA->getOperand(2))->getZExtValue() != '\n') return false; // printf("%s\n",str) -> puts(str) @@ -1409,7 +1409,7 @@ for (unsigned i = 0; i < len; ++i) { if (ConstantInt* CI = dyn_cast<ConstantInt>(CA->getOperand(i))) { // Check for the null terminator - if (CI->getRawValue() == '%') + if (CI->getZExtValue() == '%') return false; // we found end of string } else { return false; @@ -1446,12 +1446,12 @@ // The first character has to be a % if (ConstantInt* CI = dyn_cast<ConstantInt>(CA->getOperand(0))) - if (CI->getRawValue() != '%') + if (CI->getZExtValue() != '%') return false; // Get the second character and switch on its value ConstantInt* CI = dyn_cast<ConstantInt>(CA->getOperand(1)); - switch (CI->getRawValue()) { + switch (CI->getZExtValue()) { case 's': { uint64_t len = 0; @@ -1546,7 +1546,7 @@ for (unsigned i = 0; i < len; ++i) { if (ConstantInt* CI = dyn_cast<ConstantInt>(CA->getOperand(i))) { // Check for the null terminator - if (CI->getRawValue() == '%') + if (CI->getZExtValue() == '%') return false; // we found a %, can't optimize } else { return false; // initializer is not constant int, can't optimize @@ -1578,12 +1578,12 @@ // The first character has to be a % if (ConstantInt* CI = dyn_cast<ConstantInt>(CA->getOperand(0))) - if (CI->getRawValue() != '%') + if (CI->getZExtValue() != '%') return false; // Get the second character and switch on its value ConstantInt* CI = dyn_cast<ConstantInt>(CA->getOperand(1)); - switch (CI->getRawValue()) { + switch (CI->getZExtValue()) { case 's': { // sprintf(dest,"%s",str) -> llvm.memcpy(dest, str, strlen(str)+1, 1) Function* strlen_func = SLC.get_strlen(); @@ -1716,7 +1716,7 @@ virtual bool OptimizeCall(CallInst *ci, SimplifyLibCalls &SLC) { if (ConstantInt* CI = dyn_cast<ConstantInt>(ci->getOperand(1))) { // isdigit(c) -> 0 or 1, if 'c' is constant - uint64_t val = CI->getRawValue(); + uint64_t val = CI->getZExtValue(); if (val >= '0' && val <='9') ci->replaceAllUsesWith(ConstantInt::get(Type::IntTy,1)); else @@ -1828,7 +1828,7 @@ // ffs(cnst) -> bit# // ffsl(cnst) -> bit# // ffsll(cnst) -> bit# - uint64_t val = CI->getRawValue(); + uint64_t val = CI->getZExtValue(); int result = 0; if (val) { ++result; @@ -2048,7 +2048,7 @@ // value. We'll need this later for indexing the ConstantArray. uint64_t start_idx = 0; if (ConstantInt* CI = dyn_cast<ConstantInt>(GEP->getOperand(2))) - start_idx = CI->getRawValue(); + start_idx = CI->getZExtValue(); else return false; _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits