mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-27 14:24:40 +00:00
shl is always zero extending, so always use a zero extending shift right.
This latent bug was exposed by recent changes, and is tested as: llvm/test/Regression/Transforms/InstCombine/2004-09-28-BadShiftAndSetCC.llx git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16546 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -1506,7 +1506,7 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) {
|
|||||||
// rights, as they sign-extend.
|
// rights, as they sign-extend.
|
||||||
if (ShAmt) {
|
if (ShAmt) {
|
||||||
bool CanFold = Shift->getOpcode() != Instruction::Shr ||
|
bool CanFold = Shift->getOpcode() != Instruction::Shr ||
|
||||||
Shift->getType()->isUnsigned();
|
Shift->getType()->isUnsigned();
|
||||||
if (!CanFold) {
|
if (!CanFold) {
|
||||||
// To test for the bad case of the signed shr, see if any
|
// To test for the bad case of the signed shr, see if any
|
||||||
// of the bits shifted in could be tested after the mask.
|
// of the bits shifted in could be tested after the mask.
|
||||||
@ -1519,9 +1519,11 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (CanFold) {
|
if (CanFold) {
|
||||||
unsigned ShiftOp = Shift->getOpcode() == Instruction::Shl
|
Constant *NewCst;
|
||||||
? Instruction::Shr : Instruction::Shl;
|
if (Shift->getOpcode() == Instruction::Shl)
|
||||||
Constant *NewCst = ConstantExpr::get(ShiftOp, CI, ShAmt);
|
NewCst = ConstantExpr::getUShr(CI, ShAmt);
|
||||||
|
else
|
||||||
|
NewCst = ConstantExpr::getShl(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.
|
||||||
@ -1535,7 +1537,12 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) {
|
|||||||
return ReplaceInstUsesWith(I, ConstantBool::True);
|
return ReplaceInstUsesWith(I, ConstantBool::True);
|
||||||
} else {
|
} else {
|
||||||
I.setOperand(1, NewCst);
|
I.setOperand(1, NewCst);
|
||||||
LHSI->setOperand(1, ConstantExpr::get(ShiftOp, AndCST,ShAmt));
|
Constant *NewAndCST;
|
||||||
|
if (Shift->getOpcode() == Instruction::Shl)
|
||||||
|
NewAndCST = ConstantExpr::getUShr(AndCST, ShAmt);
|
||||||
|
else
|
||||||
|
NewAndCST = ConstantExpr::getShl(AndCST, ShAmt);
|
||||||
|
LHSI->setOperand(1, NewAndCST);
|
||||||
LHSI->setOperand(0, Shift->getOperand(0));
|
LHSI->setOperand(0, Shift->getOperand(0));
|
||||||
WorkList.push_back(Shift); // Shift is dead.
|
WorkList.push_back(Shift); // Shift is dead.
|
||||||
AddUsesToWorkList(I);
|
AddUsesToWorkList(I);
|
||||||
|
Reference in New Issue
Block a user