Skip to content

Commit 8b9053a

Browse files
Nikola PericNikola Peric
authored andcommitted
NanoMips: Support for 16bit masks in OR to INS combine
This allows the INS instruction to be used to set the value of one field of the bitfields struct.
1 parent a2ea8c7 commit 8b9053a

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

llvm/lib/Target/Mips/MipsISelLowering.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,8 +1046,26 @@ static SDValue attemptOrToIns(SDValue &And, SDValue &Right, SDNode *N,
10461046
if (!(CN = dyn_cast<ConstantSDNode>(And.getOperand(1))))
10471047
return SDValue();
10481048
unsigned Mask0 = ~CN->getZExtValue();
1049-
if (!isShiftedMask(Mask0, SMPos0, SMSize0))
1050-
return SDValue();
1049+
1050+
KnownBits KnownMaskBits = DAG.computeKnownBits(And.getOperand(1));
1051+
APInt maxValue = KnownMaskBits.getMaxValue();
1052+
unsigned int MaxNumOfActiveBitsInMask = maxValue.getActiveBits();
1053+
1054+
// If the mask value fits into 16 bits, trim the leading ones.
1055+
// Leading ones were made after negating zero expanded 16 bit value.
1056+
// This enables the function isShiftedMask() to recognize 16 bit masks as
1057+
// valid.
1058+
// TODO: Support the case when there are two two consecutive OR instructions
1059+
// and two masks whose value fits in 16 bits.
1060+
if (MaxNumOfActiveBitsInMask <= 16) {
1061+
uint16_t Mask0_16 = Mask0;
1062+
if (!isShiftedMask(Mask0_16, SMPos0, SMSize0))
1063+
return SDValue();
1064+
} else if (MaxNumOfActiveBitsInMask <= 32) {
1065+
uint32_t Mask0_32 = Mask0;
1066+
if (!isShiftedMask(Mask0_32, SMPos0, SMSize0))
1067+
return SDValue();
1068+
}
10511069

10521070
SDLoc DL(N);
10531071
EVT ValTy = N->getValueType(0);

0 commit comments

Comments
 (0)