mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-15 04:30:12 +00:00
Use Type::getIntegralTypeMask() to simplify some code
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26034 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6dce1a7dfe
commit
1a074fce15
@ -844,9 +844,8 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
|
|||||||
|
|
||||||
// X + (signbit) --> X ^ signbit
|
// X + (signbit) --> X ^ signbit
|
||||||
if (ConstantInt *CI = dyn_cast<ConstantInt>(RHSC)) {
|
if (ConstantInt *CI = dyn_cast<ConstantInt>(RHSC)) {
|
||||||
unsigned NumBits = CI->getType()->getPrimitiveSizeInBits();
|
uint64_t Val = CI->getRawValue() & CI->getType()->getIntegralTypeMask();
|
||||||
uint64_t Val = CI->getRawValue() & (~0ULL >> (64- NumBits));
|
if (Val == (1ULL << (CI->getType()->getPrimitiveSizeInBits()-1)))
|
||||||
if (Val == (1ULL << (NumBits-1)))
|
|
||||||
return BinaryOperator::createXor(LHS, RHS);
|
return BinaryOperator::createXor(LHS, RHS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -970,7 +969,7 @@ FoundSExt:
|
|||||||
|
|
||||||
// Form a mask of all bits from the lowest bit added through the top.
|
// Form a mask of all bits from the lowest bit added through the top.
|
||||||
uint64_t AddRHSHighBits = ~((AddRHSV & -AddRHSV)-1);
|
uint64_t AddRHSHighBits = ~((AddRHSV & -AddRHSV)-1);
|
||||||
AddRHSHighBits &= ~0ULL >> (64-C2->getType()->getPrimitiveSizeInBits());
|
AddRHSHighBits &= C2->getType()->getIntegralTypeMask();
|
||||||
|
|
||||||
// See if the and mask includes all of these bits.
|
// See if the and mask includes all of these bits.
|
||||||
uint64_t AddRHSHighBitsAnd = AddRHSHighBits & C2->getRawValue();
|
uint64_t AddRHSHighBitsAnd = AddRHSHighBits & C2->getRawValue();
|
||||||
@ -1523,13 +1522,8 @@ Instruction *InstCombiner::visitRem(BinaryOperator &I) {
|
|||||||
|
|
||||||
// isMaxValueMinusOne - return true if this is Max-1
|
// isMaxValueMinusOne - return true if this is Max-1
|
||||||
static bool isMaxValueMinusOne(const ConstantInt *C) {
|
static bool isMaxValueMinusOne(const ConstantInt *C) {
|
||||||
if (const ConstantUInt *CU = dyn_cast<ConstantUInt>(C)) {
|
if (const ConstantUInt *CU = dyn_cast<ConstantUInt>(C))
|
||||||
// Calculate -1 casted to the right type...
|
return CU->getValue() == C->getType()->getIntegralTypeMask()-1;
|
||||||
unsigned TypeBits = C->getType()->getPrimitiveSizeInBits();
|
|
||||||
uint64_t Val = ~0ULL; // All ones
|
|
||||||
Val >>= 64-TypeBits; // Shift out unwanted 1 bits...
|
|
||||||
return CU->getValue() == Val-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ConstantSInt *CS = cast<ConstantSInt>(C);
|
const ConstantSInt *CS = cast<ConstantSInt>(C);
|
||||||
|
|
||||||
@ -1709,7 +1703,7 @@ Instruction *InstCombiner::OptAndOp(Instruction *Op,
|
|||||||
uint64_t AndRHSV = cast<ConstantInt>(AndRHS)->getRawValue();
|
uint64_t AndRHSV = cast<ConstantInt>(AndRHS)->getRawValue();
|
||||||
|
|
||||||
// Clear bits that are not part of the constant.
|
// Clear bits that are not part of the constant.
|
||||||
AndRHSV &= ~0ULL >> (64-AndRHS->getType()->getPrimitiveSizeInBits());
|
AndRHSV &= AndRHS->getType()->getIntegralTypeMask();
|
||||||
|
|
||||||
// If there is only one bit set...
|
// If there is only one bit set...
|
||||||
if (isOneBitSet(cast<ConstantInt>(AndRHS))) {
|
if (isOneBitSet(cast<ConstantInt>(AndRHS))) {
|
||||||
@ -2644,8 +2638,7 @@ static Value *EmitGEPOffset(User *GEP, Instruction &I, InstCombiner &IC) {
|
|||||||
Value *Result = Constant::getNullValue(SIntPtrTy);
|
Value *Result = Constant::getNullValue(SIntPtrTy);
|
||||||
|
|
||||||
// Build a mask for high order bits.
|
// Build a mask for high order bits.
|
||||||
uint64_t PtrSizeMask = ~0ULL;
|
uint64_t PtrSizeMask = ~0ULL >> (64-TD.getPointerSize()*8);
|
||||||
PtrSizeMask >>= 64-(TD.getPointerSize()*8);
|
|
||||||
|
|
||||||
for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i, ++GTI) {
|
for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i, ++GTI) {
|
||||||
Value *Op = GEP->getOperand(i);
|
Value *Op = GEP->getOperand(i);
|
||||||
@ -4245,7 +4238,7 @@ Instruction *InstCombiner::visitCastInst(CastInst &CI) {
|
|||||||
CI.getType()->getPrimitiveSizeInBits()) {
|
CI.getType()->getPrimitiveSizeInBits()) {
|
||||||
assert(CSrc->getType() != Type::ULongTy &&
|
assert(CSrc->getType() != Type::ULongTy &&
|
||||||
"Cannot have type bigger than ulong!");
|
"Cannot have type bigger than ulong!");
|
||||||
uint64_t AndValue = ~0ULL>>(64-CSrc->getType()->getPrimitiveSizeInBits());
|
uint64_t AndValue = CSrc->getType()->getIntegralTypeMask();
|
||||||
Constant *AndOp = ConstantUInt::get(A->getType()->getUnsignedVersion(),
|
Constant *AndOp = ConstantUInt::get(A->getType()->getUnsignedVersion(),
|
||||||
AndValue);
|
AndValue);
|
||||||
AndOp = ConstantExpr::getCast(AndOp, A->getType());
|
AndOp = ConstantExpr::getCast(AndOp, A->getType());
|
||||||
|
Loading…
Reference in New Issue
Block a user