mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-13 10:32:06 +00:00
Remove trailing spaces.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169701 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6297bfa80e
commit
0fb7687b61
@ -49,7 +49,7 @@ Instruction *InstCombiner::commonShiftTransforms(BinaryOperator &I) {
|
|||||||
I.setOperand(1, Rem);
|
I.setOperand(1, Rem);
|
||||||
return &I;
|
return &I;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,10 +70,10 @@ static bool CanEvaluateShifted(Value *V, unsigned NumBits, bool isLeftShift,
|
|||||||
// We can always evaluate constants shifted.
|
// We can always evaluate constants shifted.
|
||||||
if (isa<Constant>(V))
|
if (isa<Constant>(V))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Instruction *I = dyn_cast<Instruction>(V);
|
Instruction *I = dyn_cast<Instruction>(V);
|
||||||
if (!I) return false;
|
if (!I) return false;
|
||||||
|
|
||||||
// If this is the opposite shift, we can directly reuse the input of the shift
|
// If this is the opposite shift, we can directly reuse the input of the shift
|
||||||
// if the needed bits are already zero in the input. This allows us to reuse
|
// if the needed bits are already zero in the input. This allows us to reuse
|
||||||
// the value which means that we don't care if the shift has multiple uses.
|
// the value which means that we don't care if the shift has multiple uses.
|
||||||
@ -95,14 +95,14 @@ static bool CanEvaluateShifted(Value *V, unsigned NumBits, bool isLeftShift,
|
|||||||
return CanEvaluateTruncated(I->getOperand(0), Ty);
|
return CanEvaluateTruncated(I->getOperand(0), Ty);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can't mutate something that has multiple uses: doing so would
|
// We can't mutate something that has multiple uses: doing so would
|
||||||
// require duplicating the instruction in general, which isn't profitable.
|
// require duplicating the instruction in general, which isn't profitable.
|
||||||
if (!I->hasOneUse()) return false;
|
if (!I->hasOneUse()) return false;
|
||||||
|
|
||||||
switch (I->getOpcode()) {
|
switch (I->getOpcode()) {
|
||||||
default: return false;
|
default: return false;
|
||||||
case Instruction::And:
|
case Instruction::And:
|
||||||
@ -111,7 +111,7 @@ static bool CanEvaluateShifted(Value *V, unsigned NumBits, bool isLeftShift,
|
|||||||
// Bitwise operators can all arbitrarily be arbitrarily evaluated shifted.
|
// Bitwise operators can all arbitrarily be arbitrarily evaluated shifted.
|
||||||
return CanEvaluateShifted(I->getOperand(0), NumBits, isLeftShift, IC) &&
|
return CanEvaluateShifted(I->getOperand(0), NumBits, isLeftShift, IC) &&
|
||||||
CanEvaluateShifted(I->getOperand(1), NumBits, isLeftShift, IC);
|
CanEvaluateShifted(I->getOperand(1), NumBits, isLeftShift, IC);
|
||||||
|
|
||||||
case Instruction::Shl: {
|
case Instruction::Shl: {
|
||||||
// We can often fold the shift into shifts-by-a-constant.
|
// We can often fold the shift into shifts-by-a-constant.
|
||||||
CI = dyn_cast<ConstantInt>(I->getOperand(1));
|
CI = dyn_cast<ConstantInt>(I->getOperand(1));
|
||||||
@ -119,10 +119,10 @@ static bool CanEvaluateShifted(Value *V, unsigned NumBits, bool isLeftShift,
|
|||||||
|
|
||||||
// We can always fold shl(c1)+shl(c2) -> shl(c1+c2).
|
// We can always fold shl(c1)+shl(c2) -> shl(c1+c2).
|
||||||
if (isLeftShift) return true;
|
if (isLeftShift) return true;
|
||||||
|
|
||||||
// We can always turn shl(c)+shr(c) -> and(c2).
|
// We can always turn shl(c)+shr(c) -> and(c2).
|
||||||
if (CI->getValue() == NumBits) return true;
|
if (CI->getValue() == NumBits) return true;
|
||||||
|
|
||||||
unsigned TypeWidth = I->getType()->getScalarSizeInBits();
|
unsigned TypeWidth = I->getType()->getScalarSizeInBits();
|
||||||
|
|
||||||
// We can turn shl(c1)+shr(c2) -> shl(c3)+and(c4), but it isn't
|
// We can turn shl(c1)+shr(c2) -> shl(c3)+and(c4), but it isn't
|
||||||
@ -133,20 +133,20 @@ static bool CanEvaluateShifted(Value *V, unsigned NumBits, bool isLeftShift,
|
|||||||
APInt::getLowBitsSet(TypeWidth, NumBits) << LowBits))
|
APInt::getLowBitsSet(TypeWidth, NumBits) << LowBits))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case Instruction::LShr: {
|
case Instruction::LShr: {
|
||||||
// We can often fold the shift into shifts-by-a-constant.
|
// We can often fold the shift into shifts-by-a-constant.
|
||||||
CI = dyn_cast<ConstantInt>(I->getOperand(1));
|
CI = dyn_cast<ConstantInt>(I->getOperand(1));
|
||||||
if (CI == 0) return false;
|
if (CI == 0) return false;
|
||||||
|
|
||||||
// We can always fold lshr(c1)+lshr(c2) -> lshr(c1+c2).
|
// We can always fold lshr(c1)+lshr(c2) -> lshr(c1+c2).
|
||||||
if (!isLeftShift) return true;
|
if (!isLeftShift) return true;
|
||||||
|
|
||||||
// We can always turn lshr(c)+shl(c) -> and(c2).
|
// We can always turn lshr(c)+shl(c) -> and(c2).
|
||||||
if (CI->getValue() == NumBits) return true;
|
if (CI->getValue() == NumBits) return true;
|
||||||
|
|
||||||
unsigned TypeWidth = I->getType()->getScalarSizeInBits();
|
unsigned TypeWidth = I->getType()->getScalarSizeInBits();
|
||||||
|
|
||||||
// We can always turn lshr(c1)+shl(c2) -> lshr(c3)+and(c4), but it isn't
|
// We can always turn lshr(c1)+shl(c2) -> lshr(c3)+and(c4), but it isn't
|
||||||
@ -157,7 +157,7 @@ static bool CanEvaluateShifted(Value *V, unsigned NumBits, bool isLeftShift,
|
|||||||
APInt::getLowBitsSet(TypeWidth, NumBits) << LowBits))
|
APInt::getLowBitsSet(TypeWidth, NumBits) << LowBits))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case Instruction::Select: {
|
case Instruction::Select: {
|
||||||
@ -175,7 +175,7 @@ static bool CanEvaluateShifted(Value *V, unsigned NumBits, bool isLeftShift,
|
|||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// GetShiftedValue - When CanEvaluateShifted returned true for an expression,
|
/// GetShiftedValue - When CanEvaluateShifted returned true for an expression,
|
||||||
@ -194,7 +194,7 @@ static Value *GetShiftedValue(Value *V, unsigned NumBits, bool isLeftShift,
|
|||||||
IC.getTargetLibraryInfo());
|
IC.getTargetLibraryInfo());
|
||||||
return V;
|
return V;
|
||||||
}
|
}
|
||||||
|
|
||||||
Instruction *I = cast<Instruction>(V);
|
Instruction *I = cast<Instruction>(V);
|
||||||
IC.Worklist.Add(I);
|
IC.Worklist.Add(I);
|
||||||
|
|
||||||
@ -207,7 +207,7 @@ static Value *GetShiftedValue(Value *V, unsigned NumBits, bool isLeftShift,
|
|||||||
I->setOperand(0, GetShiftedValue(I->getOperand(0), NumBits,isLeftShift,IC));
|
I->setOperand(0, GetShiftedValue(I->getOperand(0), NumBits,isLeftShift,IC));
|
||||||
I->setOperand(1, GetShiftedValue(I->getOperand(1), NumBits,isLeftShift,IC));
|
I->setOperand(1, GetShiftedValue(I->getOperand(1), NumBits,isLeftShift,IC));
|
||||||
return I;
|
return I;
|
||||||
|
|
||||||
case Instruction::Shl: {
|
case Instruction::Shl: {
|
||||||
BinaryOperator *BO = cast<BinaryOperator>(I);
|
BinaryOperator *BO = cast<BinaryOperator>(I);
|
||||||
unsigned TypeWidth = BO->getType()->getScalarSizeInBits();
|
unsigned TypeWidth = BO->getType()->getScalarSizeInBits();
|
||||||
@ -227,7 +227,7 @@ static Value *GetShiftedValue(Value *V, unsigned NumBits, bool isLeftShift,
|
|||||||
BO->setHasNoSignedWrap(false);
|
BO->setHasNoSignedWrap(false);
|
||||||
return I;
|
return I;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We turn shl(c)+lshr(c) -> and(c2) if the input doesn't already have
|
// We turn shl(c)+lshr(c) -> and(c2) if the input doesn't already have
|
||||||
// zeros.
|
// zeros.
|
||||||
if (CI->getValue() == NumBits) {
|
if (CI->getValue() == NumBits) {
|
||||||
@ -240,7 +240,7 @@ static Value *GetShiftedValue(Value *V, unsigned NumBits, bool isLeftShift,
|
|||||||
}
|
}
|
||||||
return V;
|
return V;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We turn shl(c1)+shr(c2) -> shl(c3)+and(c4), but only when we know that
|
// We turn shl(c1)+shr(c2) -> shl(c3)+and(c4), but only when we know that
|
||||||
// the and won't be needed.
|
// the and won't be needed.
|
||||||
assert(CI->getZExtValue() > NumBits);
|
assert(CI->getZExtValue() > NumBits);
|
||||||
@ -255,19 +255,19 @@ static Value *GetShiftedValue(Value *V, unsigned NumBits, bool isLeftShift,
|
|||||||
unsigned TypeWidth = BO->getType()->getScalarSizeInBits();
|
unsigned TypeWidth = BO->getType()->getScalarSizeInBits();
|
||||||
// We only accept shifts-by-a-constant in CanEvaluateShifted.
|
// We only accept shifts-by-a-constant in CanEvaluateShifted.
|
||||||
ConstantInt *CI = cast<ConstantInt>(BO->getOperand(1));
|
ConstantInt *CI = cast<ConstantInt>(BO->getOperand(1));
|
||||||
|
|
||||||
// We can always fold lshr(c1)+lshr(c2) -> lshr(c1+c2).
|
// We can always fold lshr(c1)+lshr(c2) -> lshr(c1+c2).
|
||||||
if (!isLeftShift) {
|
if (!isLeftShift) {
|
||||||
// If this is oversized composite shift, then unsigned shifts get 0.
|
// If this is oversized composite shift, then unsigned shifts get 0.
|
||||||
unsigned NewShAmt = NumBits+CI->getZExtValue();
|
unsigned NewShAmt = NumBits+CI->getZExtValue();
|
||||||
if (NewShAmt >= TypeWidth)
|
if (NewShAmt >= TypeWidth)
|
||||||
return Constant::getNullValue(BO->getType());
|
return Constant::getNullValue(BO->getType());
|
||||||
|
|
||||||
BO->setOperand(1, ConstantInt::get(BO->getType(), NewShAmt));
|
BO->setOperand(1, ConstantInt::get(BO->getType(), NewShAmt));
|
||||||
BO->setIsExact(false);
|
BO->setIsExact(false);
|
||||||
return I;
|
return I;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We turn lshr(c)+shl(c) -> and(c2) if the input doesn't already have
|
// We turn lshr(c)+shl(c) -> and(c2) if the input doesn't already have
|
||||||
// zeros.
|
// zeros.
|
||||||
if (CI->getValue() == NumBits) {
|
if (CI->getValue() == NumBits) {
|
||||||
@ -280,7 +280,7 @@ static Value *GetShiftedValue(Value *V, unsigned NumBits, bool isLeftShift,
|
|||||||
}
|
}
|
||||||
return V;
|
return V;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We turn lshr(c1)+shl(c2) -> lshr(c3)+and(c4), but only when we know that
|
// We turn lshr(c1)+shl(c2) -> lshr(c3)+and(c4), but only when we know that
|
||||||
// the and won't be needed.
|
// the and won't be needed.
|
||||||
assert(CI->getZExtValue() > NumBits);
|
assert(CI->getZExtValue() > NumBits);
|
||||||
@ -289,7 +289,7 @@ static Value *GetShiftedValue(Value *V, unsigned NumBits, bool isLeftShift,
|
|||||||
BO->setIsExact(false);
|
BO->setIsExact(false);
|
||||||
return BO;
|
return BO;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Instruction::Select:
|
case Instruction::Select:
|
||||||
I->setOperand(1, GetShiftedValue(I->getOperand(1), NumBits,isLeftShift,IC));
|
I->setOperand(1, GetShiftedValue(I->getOperand(1), NumBits,isLeftShift,IC));
|
||||||
I->setOperand(2, GetShiftedValue(I->getOperand(2), NumBits,isLeftShift,IC));
|
I->setOperand(2, GetShiftedValue(I->getOperand(2), NumBits,isLeftShift,IC));
|
||||||
@ -304,7 +304,7 @@ static Value *GetShiftedValue(Value *V, unsigned NumBits, bool isLeftShift,
|
|||||||
NumBits, isLeftShift, IC));
|
NumBits, isLeftShift, IC));
|
||||||
return PN;
|
return PN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -312,24 +312,24 @@ static Value *GetShiftedValue(Value *V, unsigned NumBits, bool isLeftShift,
|
|||||||
Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||||
BinaryOperator &I) {
|
BinaryOperator &I) {
|
||||||
bool isLeftShift = I.getOpcode() == Instruction::Shl;
|
bool isLeftShift = I.getOpcode() == Instruction::Shl;
|
||||||
|
|
||||||
|
|
||||||
// See if we can propagate this shift into the input, this covers the trivial
|
// See if we can propagate this shift into the input, this covers the trivial
|
||||||
// cast of lshr(shl(x,c1),c2) as well as other more complex cases.
|
// cast of lshr(shl(x,c1),c2) as well as other more complex cases.
|
||||||
if (I.getOpcode() != Instruction::AShr &&
|
if (I.getOpcode() != Instruction::AShr &&
|
||||||
CanEvaluateShifted(Op0, Op1->getZExtValue(), isLeftShift, *this)) {
|
CanEvaluateShifted(Op0, Op1->getZExtValue(), isLeftShift, *this)) {
|
||||||
DEBUG(dbgs() << "ICE: GetShiftedValue propagating shift through expression"
|
DEBUG(dbgs() << "ICE: GetShiftedValue propagating shift through expression"
|
||||||
" to eliminate shift:\n IN: " << *Op0 << "\n SH: " << I <<"\n");
|
" to eliminate shift:\n IN: " << *Op0 << "\n SH: " << I <<"\n");
|
||||||
|
|
||||||
return ReplaceInstUsesWith(I,
|
return ReplaceInstUsesWith(I,
|
||||||
GetShiftedValue(Op0, Op1->getZExtValue(), isLeftShift, *this));
|
GetShiftedValue(Op0, Op1->getZExtValue(), isLeftShift, *this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// See if we can simplify any instructions used by the instruction whose sole
|
// See if we can simplify any instructions used by the instruction whose sole
|
||||||
// purpose is to compute bits we don't care about.
|
// purpose is to compute bits we don't care about.
|
||||||
uint32_t TypeBits = Op0->getType()->getScalarSizeInBits();
|
uint32_t TypeBits = Op0->getType()->getScalarSizeInBits();
|
||||||
|
|
||||||
// shl i32 X, 32 = 0 and srl i8 Y, 9 = 0, ... just don't eliminate
|
// shl i32 X, 32 = 0 and srl i8 Y, 9 = 0, ... just don't eliminate
|
||||||
// a signed shift.
|
// a signed shift.
|
||||||
//
|
//
|
||||||
@ -340,14 +340,14 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
|||||||
I.setOperand(1, ConstantInt::get(I.getType(), TypeBits-1));
|
I.setOperand(1, ConstantInt::get(I.getType(), TypeBits-1));
|
||||||
return &I;
|
return &I;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ((X*C1) << C2) == (X * (C1 << C2))
|
// ((X*C1) << C2) == (X * (C1 << C2))
|
||||||
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(Op0))
|
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(Op0))
|
||||||
if (BO->getOpcode() == Instruction::Mul && isLeftShift)
|
if (BO->getOpcode() == Instruction::Mul && isLeftShift)
|
||||||
if (Constant *BOOp = dyn_cast<Constant>(BO->getOperand(1)))
|
if (Constant *BOOp = dyn_cast<Constant>(BO->getOperand(1)))
|
||||||
return BinaryOperator::CreateMul(BO->getOperand(0),
|
return BinaryOperator::CreateMul(BO->getOperand(0),
|
||||||
ConstantExpr::getShl(BOOp, Op1));
|
ConstantExpr::getShl(BOOp, Op1));
|
||||||
|
|
||||||
// Try to fold constant and into select arguments.
|
// Try to fold constant and into select arguments.
|
||||||
if (SelectInst *SI = dyn_cast<SelectInst>(Op0))
|
if (SelectInst *SI = dyn_cast<SelectInst>(Op0))
|
||||||
if (Instruction *R = FoldOpIntoSelect(I, SI))
|
if (Instruction *R = FoldOpIntoSelect(I, SI))
|
||||||
@ -355,7 +355,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
|||||||
if (isa<PHINode>(Op0))
|
if (isa<PHINode>(Op0))
|
||||||
if (Instruction *NV = FoldOpIntoPhi(I))
|
if (Instruction *NV = FoldOpIntoPhi(I))
|
||||||
return NV;
|
return NV;
|
||||||
|
|
||||||
// Fold shift2(trunc(shift1(x,c1)), c2) -> trunc(shift2(shift1(x,c1),c2))
|
// Fold shift2(trunc(shift1(x,c1)), c2) -> trunc(shift2(shift1(x,c1),c2))
|
||||||
if (TruncInst *TI = dyn_cast<TruncInst>(Op0)) {
|
if (TruncInst *TI = dyn_cast<TruncInst>(Op0)) {
|
||||||
Instruction *TrOp = dyn_cast<Instruction>(TI->getOperand(0));
|
Instruction *TrOp = dyn_cast<Instruction>(TI->getOperand(0));
|
||||||
@ -364,7 +364,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
|||||||
// require that the input operand is a shift-by-constant so that we have
|
// require that the input operand is a shift-by-constant so that we have
|
||||||
// confidence that the shifts will get folded together. We could do this
|
// confidence that the shifts will get folded together. We could do this
|
||||||
// xform in more cases, but it is unlikely to be profitable.
|
// xform in more cases, but it is unlikely to be profitable.
|
||||||
if (TrOp && I.isLogicalShift() && TrOp->isShift() &&
|
if (TrOp && I.isLogicalShift() && TrOp->isShift() &&
|
||||||
isa<ConstantInt>(TrOp->getOperand(1))) {
|
isa<ConstantInt>(TrOp->getOperand(1))) {
|
||||||
// Okay, we'll do this xform. Make the shift of shift.
|
// Okay, we'll do this xform. Make the shift of shift.
|
||||||
Constant *ShAmt = ConstantExpr::getZExt(Op1, TrOp->getType());
|
Constant *ShAmt = ConstantExpr::getZExt(Op1, TrOp->getType());
|
||||||
@ -378,7 +378,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
|||||||
unsigned SrcSize = TrOp->getType()->getScalarSizeInBits();
|
unsigned SrcSize = TrOp->getType()->getScalarSizeInBits();
|
||||||
unsigned DstSize = TI->getType()->getScalarSizeInBits();
|
unsigned DstSize = TI->getType()->getScalarSizeInBits();
|
||||||
APInt MaskV(APInt::getLowBitsSet(SrcSize, DstSize));
|
APInt MaskV(APInt::getLowBitsSet(SrcSize, DstSize));
|
||||||
|
|
||||||
// The mask we constructed says what the trunc would do if occurring
|
// The mask we constructed says what the trunc would do if occurring
|
||||||
// between the shifts. We want to know the effect *after* the second
|
// between the shifts. We want to know the effect *after* the second
|
||||||
// shift. We know that it is a logical shift by a constant, so adjust the
|
// shift. We know that it is a logical shift by a constant, so adjust the
|
||||||
@ -399,7 +399,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
|||||||
return new TruncInst(And, I.getType());
|
return new TruncInst(And, I.getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Op0->hasOneUse()) {
|
if (Op0->hasOneUse()) {
|
||||||
if (BinaryOperator *Op0BO = dyn_cast<BinaryOperator>(Op0)) {
|
if (BinaryOperator *Op0BO = dyn_cast<BinaryOperator>(Op0)) {
|
||||||
// Turn ((X >> C) + Y) << C -> (X + (Y << C)) & (~0 << C)
|
// Turn ((X >> C) + Y) << C -> (X + (Y << C)) & (~0 << C)
|
||||||
@ -425,11 +425,11 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
|||||||
return BinaryOperator::CreateAnd(X, ConstantInt::get(I.getContext(),
|
return BinaryOperator::CreateAnd(X, ConstantInt::get(I.getContext(),
|
||||||
APInt::getHighBitsSet(TypeBits, TypeBits-Op1Val)));
|
APInt::getHighBitsSet(TypeBits, TypeBits-Op1Val)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Turn (Y + ((X >> C) & CC)) << C -> ((X & (CC << C)) + (Y << C))
|
// Turn (Y + ((X >> C) & CC)) << C -> ((X & (CC << C)) + (Y << C))
|
||||||
Value *Op0BOOp1 = Op0BO->getOperand(1);
|
Value *Op0BOOp1 = Op0BO->getOperand(1);
|
||||||
if (isLeftShift && Op0BOOp1->hasOneUse() &&
|
if (isLeftShift && Op0BOOp1->hasOneUse() &&
|
||||||
match(Op0BOOp1,
|
match(Op0BOOp1,
|
||||||
m_And(m_Shr(m_Value(V1), m_Specific(Op1)),
|
m_And(m_Shr(m_Value(V1), m_Specific(Op1)),
|
||||||
m_ConstantInt(CC))) &&
|
m_ConstantInt(CC))) &&
|
||||||
cast<BinaryOperator>(Op0BOOp1)->getOperand(0)->hasOneUse()) {
|
cast<BinaryOperator>(Op0BOOp1)->getOperand(0)->hasOneUse()) {
|
||||||
@ -442,7 +442,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
|||||||
return BinaryOperator::Create(Op0BO->getOpcode(), YS, XM);
|
return BinaryOperator::Create(Op0BO->getOpcode(), YS, XM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FALL THROUGH.
|
// FALL THROUGH.
|
||||||
case Instruction::Sub: {
|
case Instruction::Sub: {
|
||||||
// Turn ((X >> C) + Y) << C -> (X + (Y << C)) & (~0 << C)
|
// Turn ((X >> C) + Y) << C -> (X + (Y << C)) & (~0 << C)
|
||||||
@ -458,7 +458,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
|||||||
return BinaryOperator::CreateAnd(X, ConstantInt::get(I.getContext(),
|
return BinaryOperator::CreateAnd(X, ConstantInt::get(I.getContext(),
|
||||||
APInt::getHighBitsSet(TypeBits, TypeBits-Op1Val)));
|
APInt::getHighBitsSet(TypeBits, TypeBits-Op1Val)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Turn (((X >> C)&CC) + Y) << C -> (X + (Y << C)) & (CC << C)
|
// Turn (((X >> C)&CC) + Y) << C -> (X + (Y << C)) & (CC << C)
|
||||||
if (isLeftShift && Op0BO->getOperand(0)->hasOneUse() &&
|
if (isLeftShift && Op0BO->getOperand(0)->hasOneUse() &&
|
||||||
match(Op0BO->getOperand(0),
|
match(Op0BO->getOperand(0),
|
||||||
@ -471,21 +471,21 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
|||||||
// X & (CC << C)
|
// X & (CC << C)
|
||||||
Value *XM = Builder->CreateAnd(V1, ConstantExpr::getShl(CC, Op1),
|
Value *XM = Builder->CreateAnd(V1, ConstantExpr::getShl(CC, Op1),
|
||||||
V1->getName()+".mask");
|
V1->getName()+".mask");
|
||||||
|
|
||||||
return BinaryOperator::Create(Op0BO->getOpcode(), XM, YS);
|
return BinaryOperator::Create(Op0BO->getOpcode(), XM, YS);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// If the operand is an bitwise operator with a constant RHS, and the
|
// If the operand is an bitwise operator with a constant RHS, and the
|
||||||
// shift is the only use, we can pull it out of the shift.
|
// shift is the only use, we can pull it out of the shift.
|
||||||
if (ConstantInt *Op0C = dyn_cast<ConstantInt>(Op0BO->getOperand(1))) {
|
if (ConstantInt *Op0C = dyn_cast<ConstantInt>(Op0BO->getOperand(1))) {
|
||||||
bool isValid = true; // Valid only for And, Or, Xor
|
bool isValid = true; // Valid only for And, Or, Xor
|
||||||
bool highBitSet = false; // Transform if high bit of constant set?
|
bool highBitSet = false; // Transform if high bit of constant set?
|
||||||
|
|
||||||
switch (Op0BO->getOpcode()) {
|
switch (Op0BO->getOpcode()) {
|
||||||
default: isValid = false; break; // Do not perform transform!
|
default: isValid = false; break; // Do not perform transform!
|
||||||
case Instruction::Add:
|
case Instruction::Add:
|
||||||
@ -499,7 +499,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
|||||||
highBitSet = true;
|
highBitSet = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is a signed shift right, and the high bit is modified
|
// If this is a signed shift right, and the high bit is modified
|
||||||
// by the logical operation, do not perform the transformation.
|
// by the logical operation, do not perform the transformation.
|
||||||
// The highBitSet boolean indicates the value of the high bit of
|
// The highBitSet boolean indicates the value of the high bit of
|
||||||
@ -508,26 +508,26 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
|||||||
//
|
//
|
||||||
if (isValid && I.getOpcode() == Instruction::AShr)
|
if (isValid && I.getOpcode() == Instruction::AShr)
|
||||||
isValid = Op0C->getValue()[TypeBits-1] == highBitSet;
|
isValid = Op0C->getValue()[TypeBits-1] == highBitSet;
|
||||||
|
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
Constant *NewRHS = ConstantExpr::get(I.getOpcode(), Op0C, Op1);
|
Constant *NewRHS = ConstantExpr::get(I.getOpcode(), Op0C, Op1);
|
||||||
|
|
||||||
Value *NewShift =
|
Value *NewShift =
|
||||||
Builder->CreateBinOp(I.getOpcode(), Op0BO->getOperand(0), Op1);
|
Builder->CreateBinOp(I.getOpcode(), Op0BO->getOperand(0), Op1);
|
||||||
NewShift->takeName(Op0BO);
|
NewShift->takeName(Op0BO);
|
||||||
|
|
||||||
return BinaryOperator::Create(Op0BO->getOpcode(), NewShift,
|
return BinaryOperator::Create(Op0BO->getOpcode(), NewShift,
|
||||||
NewRHS);
|
NewRHS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find out if this is a shift of a shift by a constant.
|
// Find out if this is a shift of a shift by a constant.
|
||||||
BinaryOperator *ShiftOp = dyn_cast<BinaryOperator>(Op0);
|
BinaryOperator *ShiftOp = dyn_cast<BinaryOperator>(Op0);
|
||||||
if (ShiftOp && !ShiftOp->isShift())
|
if (ShiftOp && !ShiftOp->isShift())
|
||||||
ShiftOp = 0;
|
ShiftOp = 0;
|
||||||
|
|
||||||
if (ShiftOp && isa<ConstantInt>(ShiftOp->getOperand(1))) {
|
if (ShiftOp && isa<ConstantInt>(ShiftOp->getOperand(1))) {
|
||||||
|
|
||||||
// This is a constant shift of a constant shift. Be careful about hiding
|
// This is a constant shift of a constant shift. Be careful about hiding
|
||||||
@ -548,9 +548,9 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
|||||||
assert(ShiftAmt2 != 0 && "Should have been simplified earlier");
|
assert(ShiftAmt2 != 0 && "Should have been simplified earlier");
|
||||||
if (ShiftAmt1 == 0) return 0; // Will be simplified in the future.
|
if (ShiftAmt1 == 0) return 0; // Will be simplified in the future.
|
||||||
Value *X = ShiftOp->getOperand(0);
|
Value *X = ShiftOp->getOperand(0);
|
||||||
|
|
||||||
IntegerType *Ty = cast<IntegerType>(I.getType());
|
IntegerType *Ty = cast<IntegerType>(I.getType());
|
||||||
|
|
||||||
// Check for (X << c1) << c2 and (X >> c1) >> c2
|
// Check for (X << c1) << c2 and (X >> c1) >> c2
|
||||||
if (I.getOpcode() == ShiftOp->getOpcode()) {
|
if (I.getOpcode() == ShiftOp->getOpcode()) {
|
||||||
uint32_t AmtSum = ShiftAmt1+ShiftAmt2; // Fold into one big shift.
|
uint32_t AmtSum = ShiftAmt1+ShiftAmt2; // Fold into one big shift.
|
||||||
@ -561,11 +561,11 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
|||||||
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
|
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
|
||||||
AmtSum = TypeBits-1; // Saturate to 31 for i32 ashr.
|
AmtSum = TypeBits-1; // Saturate to 31 for i32 ashr.
|
||||||
}
|
}
|
||||||
|
|
||||||
return BinaryOperator::Create(I.getOpcode(), X,
|
return BinaryOperator::Create(I.getOpcode(), X,
|
||||||
ConstantInt::get(Ty, AmtSum));
|
ConstantInt::get(Ty, AmtSum));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ShiftAmt1 == ShiftAmt2) {
|
if (ShiftAmt1 == ShiftAmt2) {
|
||||||
// If we have ((X << C) >>u C), turn this into X & (-1 >>u C).
|
// If we have ((X << C) >>u C), turn this into X & (-1 >>u C).
|
||||||
if (I.getOpcode() == Instruction::LShr &&
|
if (I.getOpcode() == Instruction::LShr &&
|
||||||
@ -605,7 +605,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
|||||||
return NewLShr;
|
return NewLShr;
|
||||||
}
|
}
|
||||||
Value *Shift = Builder->CreateLShr(X, ShiftDiffCst);
|
Value *Shift = Builder->CreateLShr(X, ShiftDiffCst);
|
||||||
|
|
||||||
APInt Mask(APInt::getLowBitsSet(TypeBits, TypeBits - ShiftAmt2));
|
APInt Mask(APInt::getLowBitsSet(TypeBits, TypeBits - ShiftAmt2));
|
||||||
return BinaryOperator::CreateAnd(Shift,
|
return BinaryOperator::CreateAnd(Shift,
|
||||||
ConstantInt::get(I.getContext(),Mask));
|
ConstantInt::get(I.getContext(),Mask));
|
||||||
@ -653,12 +653,12 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
|||||||
return NewShl;
|
return NewShl;
|
||||||
}
|
}
|
||||||
Value *Shift = Builder->CreateShl(X, ShiftDiffCst);
|
Value *Shift = Builder->CreateShl(X, ShiftDiffCst);
|
||||||
|
|
||||||
APInt Mask(APInt::getLowBitsSet(TypeBits, TypeBits - ShiftAmt2));
|
APInt Mask(APInt::getLowBitsSet(TypeBits, TypeBits - ShiftAmt2));
|
||||||
return BinaryOperator::CreateAnd(Shift,
|
return BinaryOperator::CreateAnd(Shift,
|
||||||
ConstantInt::get(I.getContext(),Mask));
|
ConstantInt::get(I.getContext(),Mask));
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can't handle (X << C1) >>s C2, it shifts arbitrary bits in. However,
|
// We can't handle (X << C1) >>s C2, it shifts arbitrary bits in. However,
|
||||||
// we can handle (X <<nsw C1) >>s C2 since it only shifts in sign bits.
|
// we can handle (X <<nsw C1) >>s C2 since it only shifts in sign bits.
|
||||||
if (I.getOpcode() == Instruction::AShr &&
|
if (I.getOpcode() == Instruction::AShr &&
|
||||||
@ -682,21 +682,21 @@ Instruction *InstCombiner::visitShl(BinaryOperator &I) {
|
|||||||
I.hasNoSignedWrap(), I.hasNoUnsignedWrap(),
|
I.hasNoSignedWrap(), I.hasNoUnsignedWrap(),
|
||||||
TD))
|
TD))
|
||||||
return ReplaceInstUsesWith(I, V);
|
return ReplaceInstUsesWith(I, V);
|
||||||
|
|
||||||
if (Instruction *V = commonShiftTransforms(I))
|
if (Instruction *V = commonShiftTransforms(I))
|
||||||
return V;
|
return V;
|
||||||
|
|
||||||
if (ConstantInt *Op1C = dyn_cast<ConstantInt>(I.getOperand(1))) {
|
if (ConstantInt *Op1C = dyn_cast<ConstantInt>(I.getOperand(1))) {
|
||||||
unsigned ShAmt = Op1C->getZExtValue();
|
unsigned ShAmt = Op1C->getZExtValue();
|
||||||
|
|
||||||
// If the shifted-out value is known-zero, then this is a NUW shift.
|
// If the shifted-out value is known-zero, then this is a NUW shift.
|
||||||
if (!I.hasNoUnsignedWrap() &&
|
if (!I.hasNoUnsignedWrap() &&
|
||||||
MaskedValueIsZero(I.getOperand(0),
|
MaskedValueIsZero(I.getOperand(0),
|
||||||
APInt::getHighBitsSet(Op1C->getBitWidth(), ShAmt))) {
|
APInt::getHighBitsSet(Op1C->getBitWidth(), ShAmt))) {
|
||||||
I.setHasNoUnsignedWrap();
|
I.setHasNoUnsignedWrap();
|
||||||
return &I;
|
return &I;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the shifted out value is all signbits, this is a NSW shift.
|
// If the shifted out value is all signbits, this is a NSW shift.
|
||||||
if (!I.hasNoSignedWrap() &&
|
if (!I.hasNoSignedWrap() &&
|
||||||
ComputeNumSignBits(I.getOperand(0)) > ShAmt) {
|
ComputeNumSignBits(I.getOperand(0)) > ShAmt) {
|
||||||
@ -712,7 +712,7 @@ Instruction *InstCombiner::visitShl(BinaryOperator &I) {
|
|||||||
match(I.getOperand(1), m_Constant(C2)))
|
match(I.getOperand(1), m_Constant(C2)))
|
||||||
return BinaryOperator::CreateShl(ConstantExpr::getShl(C1, C2), A);
|
return BinaryOperator::CreateShl(ConstantExpr::getShl(C1, C2), A);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Instruction *InstCombiner::visitLShr(BinaryOperator &I) {
|
Instruction *InstCombiner::visitLShr(BinaryOperator &I) {
|
||||||
@ -722,9 +722,9 @@ Instruction *InstCombiner::visitLShr(BinaryOperator &I) {
|
|||||||
|
|
||||||
if (Instruction *R = commonShiftTransforms(I))
|
if (Instruction *R = commonShiftTransforms(I))
|
||||||
return R;
|
return R;
|
||||||
|
|
||||||
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
|
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
|
||||||
|
|
||||||
if (ConstantInt *Op1C = dyn_cast<ConstantInt>(Op1)) {
|
if (ConstantInt *Op1C = dyn_cast<ConstantInt>(Op1)) {
|
||||||
unsigned ShAmt = Op1C->getZExtValue();
|
unsigned ShAmt = Op1C->getZExtValue();
|
||||||
|
|
||||||
@ -743,15 +743,15 @@ Instruction *InstCombiner::visitLShr(BinaryOperator &I) {
|
|||||||
return new ZExtInst(Cmp, II->getType());
|
return new ZExtInst(Cmp, II->getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the shifted-out value is known-zero, then this is an exact shift.
|
// If the shifted-out value is known-zero, then this is an exact shift.
|
||||||
if (!I.isExact() &&
|
if (!I.isExact() &&
|
||||||
MaskedValueIsZero(Op0,APInt::getLowBitsSet(Op1C->getBitWidth(),ShAmt))){
|
MaskedValueIsZero(Op0,APInt::getLowBitsSet(Op1C->getBitWidth(),ShAmt))){
|
||||||
I.setIsExact();
|
I.setIsExact();
|
||||||
return &I;
|
return &I;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -762,12 +762,12 @@ Instruction *InstCombiner::visitAShr(BinaryOperator &I) {
|
|||||||
|
|
||||||
if (Instruction *R = commonShiftTransforms(I))
|
if (Instruction *R = commonShiftTransforms(I))
|
||||||
return R;
|
return R;
|
||||||
|
|
||||||
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
|
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
|
||||||
|
|
||||||
if (ConstantInt *Op1C = dyn_cast<ConstantInt>(Op1)) {
|
if (ConstantInt *Op1C = dyn_cast<ConstantInt>(Op1)) {
|
||||||
unsigned ShAmt = Op1C->getZExtValue();
|
unsigned ShAmt = Op1C->getZExtValue();
|
||||||
|
|
||||||
// If the input is a SHL by the same constant (ashr (shl X, C), C), then we
|
// If the input is a SHL by the same constant (ashr (shl X, C), C), then we
|
||||||
// have a sign-extend idiom.
|
// have a sign-extend idiom.
|
||||||
Value *X;
|
Value *X;
|
||||||
@ -791,23 +791,23 @@ Instruction *InstCombiner::visitAShr(BinaryOperator &I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the shifted-out value is known-zero, then this is an exact shift.
|
// If the shifted-out value is known-zero, then this is an exact shift.
|
||||||
if (!I.isExact() &&
|
if (!I.isExact() &&
|
||||||
MaskedValueIsZero(Op0,APInt::getLowBitsSet(Op1C->getBitWidth(),ShAmt))){
|
MaskedValueIsZero(Op0,APInt::getLowBitsSet(Op1C->getBitWidth(),ShAmt))){
|
||||||
I.setIsExact();
|
I.setIsExact();
|
||||||
return &I;
|
return &I;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// See if we can turn a signed shr into an unsigned shr.
|
// See if we can turn a signed shr into an unsigned shr.
|
||||||
if (MaskedValueIsZero(Op0,
|
if (MaskedValueIsZero(Op0,
|
||||||
APInt::getSignBit(I.getType()->getScalarSizeInBits())))
|
APInt::getSignBit(I.getType()->getScalarSizeInBits())))
|
||||||
return BinaryOperator::CreateLShr(Op0, Op1);
|
return BinaryOperator::CreateLShr(Op0, Op1);
|
||||||
|
|
||||||
// Arithmetic shifting an all-sign-bit value is a no-op.
|
// Arithmetic shifting an all-sign-bit value is a no-op.
|
||||||
unsigned NumSignBits = ComputeNumSignBits(Op0);
|
unsigned NumSignBits = ComputeNumSignBits(Op0);
|
||||||
if (NumSignBits == Op0->getType()->getScalarSizeInBits())
|
if (NumSignBits == Op0->getType()->getScalarSizeInBits())
|
||||||
return ReplaceInstUsesWith(I, Op0);
|
return ReplaceInstUsesWith(I, Op0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user