1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 12:12:47 +01:00

[GlobalISel] Fix known bits for G_BSWAP and B_BITREVERSE not doing anything.

llvm::KnownBits::byteSwap() and reverse() don't modify in-place, so
we weren't actually computing anything. This was causing a miscompile on an
arm64 stage2 bootstrap clang build.
This commit is contained in:
Amara Emerson 2021-07-17 23:03:52 -07:00
parent 970c655f5e
commit 71177b0c4c
3 changed files with 14 additions and 12 deletions

View File

@ -501,13 +501,13 @@ void GISelKnownBits::computeKnownBitsImpl(Register R, KnownBits &Known,
case TargetOpcode::G_BSWAP: { case TargetOpcode::G_BSWAP: {
Register SrcReg = MI.getOperand(1).getReg(); Register SrcReg = MI.getOperand(1).getReg();
computeKnownBitsImpl(SrcReg, Known, DemandedElts, Depth + 1); computeKnownBitsImpl(SrcReg, Known, DemandedElts, Depth + 1);
Known.byteSwap(); Known = Known.byteSwap();
break; break;
} }
case TargetOpcode::G_BITREVERSE: { case TargetOpcode::G_BITREVERSE: {
Register SrcReg = MI.getOperand(1).getReg(); Register SrcReg = MI.getOperand(1).getReg();
computeKnownBitsImpl(SrcReg, Known, DemandedElts, Depth + 1); computeKnownBitsImpl(SrcReg, Known, DemandedElts, Depth + 1);
Known.reverseBits(); Known = Known.reverseBits();
break; break;
} }
case TargetOpcode::G_UBFX: { case TargetOpcode::G_UBFX: {

View File

@ -1369,7 +1369,8 @@ TEST_F(AArch64GISelMITest, TestKnownBitsBSwapBitReverse) {
if (!TM) if (!TM)
return; return;
const uint32_t TestVal = 0x11223344; const uint32_t ByteSwappedVal = 0x44332211;
const uint32_t BitSwappedVal = 0x22cc4488;
Register CopyBSwap = Copies[Copies.size() - 2]; Register CopyBSwap = Copies[Copies.size() - 2];
Register CopyBitReverse = Copies[Copies.size() - 1]; Register CopyBitReverse = Copies[Copies.size() - 1];
@ -1378,13 +1379,13 @@ TEST_F(AArch64GISelMITest, TestKnownBitsBSwapBitReverse) {
KnownBits BSwapKnown = Info.getKnownBits(CopyBSwap); KnownBits BSwapKnown = Info.getKnownBits(CopyBSwap);
EXPECT_EQ(32u, BSwapKnown.getBitWidth()); EXPECT_EQ(32u, BSwapKnown.getBitWidth());
EXPECT_EQ(TestVal, BSwapKnown.One.getZExtValue()); EXPECT_EQ(ByteSwappedVal, BSwapKnown.One.getZExtValue());
EXPECT_EQ(~TestVal, BSwapKnown.Zero.getZExtValue()); EXPECT_EQ(~ByteSwappedVal, BSwapKnown.Zero.getZExtValue());
KnownBits BitReverseKnown = Info.getKnownBits(CopyBitReverse); KnownBits BitReverseKnown = Info.getKnownBits(CopyBitReverse);
EXPECT_EQ(32u, BitReverseKnown.getBitWidth()); EXPECT_EQ(32u, BitReverseKnown.getBitWidth());
EXPECT_EQ(TestVal, BitReverseKnown.One.getZExtValue()); EXPECT_EQ(BitSwappedVal, BitReverseKnown.One.getZExtValue());
EXPECT_EQ(~TestVal, BitReverseKnown.Zero.getZExtValue()); EXPECT_EQ(~BitSwappedVal, BitReverseKnown.Zero.getZExtValue());
} }
TEST_F(AArch64GISelMITest, TestKnownBitsUMAX) { TEST_F(AArch64GISelMITest, TestKnownBitsUMAX) {

View File

@ -1227,7 +1227,8 @@ TEST_F(AArch64GISelMITest, TestVectorKnownBitsBSwapBitReverse) {
if (!TM) if (!TM)
return; return;
const uint32_t TestVal = 0x11223344; const uint32_t ByteSwappedVal = 0x44332211;
const uint32_t BitSwappedVal = 0x22cc4488;
Register CopyBSwap = Copies[Copies.size() - 2]; Register CopyBSwap = Copies[Copies.size() - 2];
Register CopyBitReverse = Copies[Copies.size() - 1]; Register CopyBitReverse = Copies[Copies.size() - 1];
@ -1236,13 +1237,13 @@ TEST_F(AArch64GISelMITest, TestVectorKnownBitsBSwapBitReverse) {
KnownBits BSwapKnown = Info.getKnownBits(CopyBSwap); KnownBits BSwapKnown = Info.getKnownBits(CopyBSwap);
EXPECT_EQ(32u, BSwapKnown.getBitWidth()); EXPECT_EQ(32u, BSwapKnown.getBitWidth());
EXPECT_EQ(TestVal, BSwapKnown.One.getZExtValue()); EXPECT_EQ(ByteSwappedVal, BSwapKnown.One.getZExtValue());
EXPECT_EQ(~TestVal, BSwapKnown.Zero.getZExtValue()); EXPECT_EQ(~ByteSwappedVal, BSwapKnown.Zero.getZExtValue());
KnownBits BitReverseKnown = Info.getKnownBits(CopyBitReverse); KnownBits BitReverseKnown = Info.getKnownBits(CopyBitReverse);
EXPECT_EQ(32u, BitReverseKnown.getBitWidth()); EXPECT_EQ(32u, BitReverseKnown.getBitWidth());
EXPECT_EQ(TestVal, BitReverseKnown.One.getZExtValue()); EXPECT_EQ(BitSwappedVal, BitReverseKnown.One.getZExtValue());
EXPECT_EQ(~TestVal, BitReverseKnown.Zero.getZExtValue()); EXPECT_EQ(~BitSwappedVal, BitReverseKnown.Zero.getZExtValue());
} }
TEST_F(AArch64GISelMITest, TestKnownBitsVectorUMAX) { TEST_F(AArch64GISelMITest, TestKnownBitsVectorUMAX) {