/// Update known bits based on XORing with RHS.
KnownBits &operator^=(const KnownBits &RHS);
+
+ KnownBits byteSwap() {
+ return KnownBits(Zero.byteSwap(), One.byteSwap());
+ }
+
+ KnownBits reverseBits() {
+ return KnownBits(Zero.reverseBits(), One.reverseBits());
+ }
};
inline KnownBits operator&(KnownBits LHS, const KnownBits &RHS) {
Known = SrcOpKnown.extractBits(BitWidth, BitWidth * DstIdx);
break;
}
+ case TargetOpcode::G_BSWAP: {
+ Register SrcReg = MI.getOperand(1).getReg();
+ computeKnownBitsImpl(SrcReg, Known, DemandedElts, Depth + 1);
+ Known.byteSwap();
+ break;
+ }
+ case TargetOpcode::G_BITREVERSE: {
+ Register SrcReg = MI.getOperand(1).getReg();
+ computeKnownBitsImpl(SrcReg, Known, DemandedElts, Depth + 1);
+ Known.reverseBits();
+ break;
+ }
}
assert(!Known.hasConflict() && "Bits known to be one AND zero?");
}
case ISD::BITREVERSE: {
Known2 = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
- Known.Zero = Known2.Zero.reverseBits();
- Known.One = Known2.One.reverseBits();
+ Known = Known2.reverseBits();
break;
}
case ISD::BSWAP: {
Known2 = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
- Known.Zero = Known2.Zero.byteSwap();
- Known.One = Known2.One.byteSwap();
+ Known = Known2.byteSwap();
break;
}
case ISD::ABS: {
EXPECT_EQ(static_cast<uint16_t>(~PartTestVal), PartKnown.Zero.getZExtValue());
}
}
+
+TEST_F(AArch64GISelMITest, TestKnownBitsBSwapBitReverse) {
+ StringRef MIRString = R"(
+ %const:_(s32) = G_CONSTANT i32 287454020
+ %bswap:_(s32) = G_BSWAP %const
+ %bitreverse:_(s32) = G_BITREVERSE %const
+ %copy_bswap:_(s32) = COPY %bswap
+ %copy_bitreverse:_(s32) = COPY %bitreverse
+)";
+ setUp(MIRString);
+ if (!TM)
+ return;
+
+ const uint32_t TestVal = 0x11223344;
+
+ Register CopyBSwap = Copies[Copies.size() - 2];
+ Register CopyBitReverse = Copies[Copies.size() - 1];
+
+ GISelKnownBits Info(*MF);
+
+ KnownBits BSwapKnown = Info.getKnownBits(CopyBSwap);
+ EXPECT_EQ(32u, BSwapKnown.getBitWidth());
+ EXPECT_EQ(TestVal, BSwapKnown.One.getZExtValue());
+ EXPECT_EQ(~TestVal, BSwapKnown.Zero.getZExtValue());
+
+ KnownBits BitReverseKnown = Info.getKnownBits(CopyBitReverse);
+ EXPECT_EQ(32u, BitReverseKnown.getBitWidth());
+ EXPECT_EQ(TestVal, BitReverseKnown.One.getZExtValue());
+ EXPECT_EQ(~TestVal, BitReverseKnown.Zero.getZExtValue());
+}