Simplify code by using ConstantInt::getRawValue instead of checking to see

whether the constant is signed or unsigned, then casting


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7252 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2003-07-23 15:22:26 +00:00
parent c8bf87af3e
commit c07736a397
17 changed files with 45 additions and 133 deletions

View File

@@ -370,8 +370,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
if (Constant *Op1 = dyn_cast<Constant>(I.getOperand(1))) {
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
const Type *Ty = CI->getType();
int64_t Val = Ty->isSigned() ? cast<ConstantSInt>(CI)->getValue() :
(int64_t)cast<ConstantUInt>(CI)->getValue();
int64_t Val = (int64_t)cast<ConstantInt>(CI)->getRawValue();
switch (Val) {
case -1: // X * -1 -> -X
return BinaryOperator::createNeg(Op0, I.getName());

View File

@@ -103,11 +103,7 @@ bool SROA::runOnFunction(Function &F) {
Instruction *User = cast<Instruction>(*I);
if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(User)) {
// We now know that the GEP is of the form: GEP <ptr>, 0, <cst>
uint64_t Idx;
if (ConstantSInt *CSI = dyn_cast<ConstantSInt>(GEPI->getOperand(2)))
Idx = CSI->getValue();
else
Idx = cast<ConstantUInt>(GEPI->getOperand(2))->getValue();
uint64_t Idx = cast<ConstantInt>(GEPI->getOperand(2))->getRawValue();
assert(Idx < ElementAllocas.size() && "Index out of range?");
AllocaInst *AllocaToUse = ElementAllocas[Idx];

View File

@@ -16,9 +16,7 @@
#include <set>
static inline int64_t getConstantValue(const ConstantInt *CPI) {
if (const ConstantSInt *CSI = dyn_cast<ConstantSInt>(CPI))
return CSI->getValue();
return (int64_t)cast<ConstantUInt>(CPI)->getValue();
return (int64_t)cast<ConstantInt>(CPI)->getRawValue();
}