mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-24 23:28:41 +00:00
Replace sra with srl if a single sign bit is required
E.g. (and (sra (i32 x) 31) 2) -> (and (srl (i32 x) 30) 2). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192884 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -750,13 +750,24 @@ bool TargetLowering::SimplifyDemandedBits(SDValue Op,
|
||||
|
||||
// If the input sign bit is known to be zero, or if none of the top bits
|
||||
// are demanded, turn this into an unsigned shift right.
|
||||
if (KnownZero.intersects(SignBit) || (HighBits & ~NewMask) == HighBits) {
|
||||
if (KnownZero.intersects(SignBit) || (HighBits & ~NewMask) == HighBits)
|
||||
return TLO.CombineTo(Op, TLO.DAG.getNode(ISD::SRL, dl, VT,
|
||||
Op.getOperand(0),
|
||||
Op.getOperand(1)));
|
||||
} else if (KnownOne.intersects(SignBit)) { // New bits are known one.
|
||||
KnownOne |= HighBits;
|
||||
|
||||
int Log2 = NewMask.exactLogBase2();
|
||||
if (Log2 >= 0) {
|
||||
// The bit must come from the sign.
|
||||
SDValue NewSA =
|
||||
TLO.DAG.getConstant(BitWidth - 1 - Log2,
|
||||
Op.getOperand(1).getValueType());
|
||||
return TLO.CombineTo(Op, TLO.DAG.getNode(ISD::SRL, dl, VT,
|
||||
Op.getOperand(0), NewSA));
|
||||
}
|
||||
|
||||
if (KnownOne.intersects(SignBit))
|
||||
// New bits are known one.
|
||||
KnownOne |= HighBits;
|
||||
}
|
||||
break;
|
||||
case ISD::SIGN_EXTEND_INREG: {
|
||||
|
Reference in New Issue
Block a user