Skip to content

Commit c57e534

Browse files
committed
Do not change demanded bits if it is already legal
1 parent dbff538 commit c57e534

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20138,6 +20138,16 @@ void ARMTargetLowering::computeKnownBitsForTargetNode(const SDValue Op,
2013820138
}
2013920139
}
2014020140

20141+
static bool isLegalLogicalImmediate(unsigned Imm, const ARMSubtarget *Subtarget) {
20142+
// Handle special cases first
20143+
if (!Subtarget->isThumb())
20144+
return ARM_AM::getSOImmVal(Imm) != -1;
20145+
if (Subtarget->isThumb2())
20146+
return ARM_AM::getT2SOImmVal(Imm) != -1;
20147+
// Thumb1 only has 8-bit unsigned immediate.
20148+
return Imm <= 255;
20149+
}
20150+
2014120151
bool ARMTargetLowering::targetShrinkDemandedConstant(
2014220152
SDValue Op, const APInt &DemandedBits, const APInt &DemandedElts,
2014320153
TargetLoweringOpt &TLO) const {
@@ -20178,6 +20188,14 @@ bool ARMTargetLowering::targetShrinkDemandedConstant(
2017820188
// code won't do this, so we have to do it explicitly to avoid an infinite
2017920189
// loop in obscure cases.)
2018020190
if (ExpandedMask == ~0U)
20191+
return TLO.CombineTo(Op, Op.getOperand(0));
20192+
20193+
// Don't optimize if it is legal already.
20194+
if (isLegalLogicalImmediate(Mask, Subtarget))
20195+
return false;
20196+
20197+
// bic
20198+
if (isLegalLogicalImmediate(~Mask, Subtarget))
2018120199
return false;
2018220200

2018320201
auto IsLegalMask = [ShrunkMask, ExpandedMask](unsigned Mask) -> bool {
@@ -20215,7 +20233,6 @@ bool ARMTargetLowering::targetShrinkDemandedConstant(
2021520233
// We could try to recognize lsls+lsrs or lsrs+lsls pairs here.
2021620234
// We could try to prefer Thumb1 immediates which can be lowered to a
2021720235
// two-instruction sequence.
20218-
// We could try to recognize more legal ARM/Thumb2 immediates here.
2021920236

2022020237
return false;
2022120238
}

0 commit comments

Comments
 (0)