mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
Fix two bugs: one where a condition was mistakenly swapped, and another
where we folded (X & 254) -> X < 1 instead of X < 2. These problems were latent problems exposed by the latest patch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16528 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1522,7 +1522,7 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) {
|
|||||||
unsigned ShiftOp = Shift->getOpcode() == Instruction::Shl
|
unsigned ShiftOp = Shift->getOpcode() == Instruction::Shl
|
||||||
? Instruction::Shr : Instruction::Shl;
|
? Instruction::Shr : Instruction::Shl;
|
||||||
Constant *NewCst = ConstantExpr::get(ShiftOp, CI, ShAmt);
|
Constant *NewCst = ConstantExpr::get(ShiftOp, CI, ShAmt);
|
||||||
|
|
||||||
// Check to see if we are shifting out any of the bits being
|
// Check to see if we are shifting out any of the bits being
|
||||||
// compared.
|
// compared.
|
||||||
if (ConstantExpr::get(Shift->getOpcode(), NewCst, ShAmt) != CI){
|
if (ConstantExpr::get(Shift->getOpcode(), NewCst, ShAmt) != CI){
|
||||||
@@ -1545,7 +1545,8 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Instruction::Shr: // shr: (setcc (shr X, ShAmt), CI)
|
|
||||||
|
case Instruction::Shr: // (setcc (shr X, ShAmt), CI)
|
||||||
if (ConstantUInt *ShAmt = dyn_cast<ConstantUInt>(LHSI->getOperand(1))) {
|
if (ConstantUInt *ShAmt = dyn_cast<ConstantUInt>(LHSI->getOperand(1))) {
|
||||||
unsigned ShAmtVal = ShAmt->getValue();
|
unsigned ShAmtVal = ShAmt->getValue();
|
||||||
|
|
||||||
@@ -1721,31 +1722,27 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) {
|
|||||||
// If 'X' is not signed, insert a cast now...
|
// If 'X' is not signed, insert a cast now...
|
||||||
if (!BOC->getType()->isSigned()) {
|
if (!BOC->getType()->isSigned()) {
|
||||||
const Type *DestTy = BOC->getType()->getSignedVersion();
|
const Type *DestTy = BOC->getType()->getSignedVersion();
|
||||||
CastInst *NewCI = new CastInst(X,DestTy,X->getName()+".signed");
|
X = InsertCastBefore(X, DestTy, I);
|
||||||
InsertNewInstBefore(NewCI, I);
|
|
||||||
X = NewCI;
|
|
||||||
}
|
}
|
||||||
return new SetCondInst(isSetNE ? Instruction::SetLT :
|
return new SetCondInst(isSetNE ? Instruction::SetLT :
|
||||||
Instruction::SetGE, X,
|
Instruction::SetGE, X,
|
||||||
Constant::getNullValue(X->getType()));
|
Constant::getNullValue(X->getType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ((X & ~7) == 0) --> X < 7
|
// ((X & ~7) == 0) --> X < 8
|
||||||
if (CI->isNullValue() && isHighOnes(BOC)) {
|
if (CI->isNullValue() && isHighOnes(BOC)) {
|
||||||
Value *X = BO->getOperand(0);
|
Value *X = BO->getOperand(0);
|
||||||
Constant *NotX = ConstantExpr::getNot(BOC);
|
Constant *NegX = ConstantExpr::getNeg(BOC);
|
||||||
|
|
||||||
// If 'X' is signed, insert a cast now.
|
// If 'X' is signed, insert a cast now.
|
||||||
if (!NotX->getType()->isSigned()) {
|
if (NegX->getType()->isSigned()) {
|
||||||
const Type *DestTy = NotX->getType()->getUnsignedVersion();
|
const Type *DestTy = NegX->getType()->getUnsignedVersion();
|
||||||
CastInst *NewCI = new CastInst(X, DestTy, X->getName()+".uns");
|
X = InsertCastBefore(X, DestTy, I);
|
||||||
InsertNewInstBefore(NewCI, I);
|
NegX = ConstantExpr::getCast(NegX, DestTy);
|
||||||
X = NewCI;
|
|
||||||
NotX = ConstantExpr::getCast(NotX, DestTy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SetCondInst(isSetNE ? Instruction::SetGE :
|
return new SetCondInst(isSetNE ? Instruction::SetGE :
|
||||||
Instruction::SetLT, X, NotX);
|
Instruction::SetLT, X, NegX);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user