[llvm] 4c55cdb - [GlobalISel] Fix known bits for G_BSWAP and B_BITREVERSE not doing anything.
Amara Emerson via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 17 23:33:21 PDT 2021
Author: Amara Emerson
Date: 2021-07-17T23:07:16-07:00
New Revision: 4c55cdb00a8005826676848582b8450c21140e8a
URL: https://github.com/llvm/llvm-project/commit/4c55cdb00a8005826676848582b8450c21140e8a
DIFF: https://github.com/llvm/llvm-project/commit/4c55cdb00a8005826676848582b8450c21140e8a.diff
LOG: [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.
Added:
Modified:
llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
llvm/unittests/CodeGen/GlobalISel/KnownBitsTest.cpp
llvm/unittests/CodeGen/GlobalISel/KnownBitsVectorTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp b/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
index a7f0d5fde1284..8146a67d4dfb9 100644
--- a/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
@@ -501,13 +501,13 @@ void GISelKnownBits::computeKnownBitsImpl(Register R, KnownBits &Known,
case TargetOpcode::G_BSWAP: {
Register SrcReg = MI.getOperand(1).getReg();
computeKnownBitsImpl(SrcReg, Known, DemandedElts, Depth + 1);
- Known.byteSwap();
+ Known = Known.byteSwap();
break;
}
case TargetOpcode::G_BITREVERSE: {
Register SrcReg = MI.getOperand(1).getReg();
computeKnownBitsImpl(SrcReg, Known, DemandedElts, Depth + 1);
- Known.reverseBits();
+ Known = Known.reverseBits();
break;
}
case TargetOpcode::G_UBFX: {
diff --git a/llvm/unittests/CodeGen/GlobalISel/KnownBitsTest.cpp b/llvm/unittests/CodeGen/GlobalISel/KnownBitsTest.cpp
index 26153168e8e06..e948f150e6777 100644
--- a/llvm/unittests/CodeGen/GlobalISel/KnownBitsTest.cpp
+++ b/llvm/unittests/CodeGen/GlobalISel/KnownBitsTest.cpp
@@ -1369,7 +1369,8 @@ TEST_F(AArch64GISelMITest, TestKnownBitsBSwapBitReverse) {
if (!TM)
return;
- const uint32_t TestVal = 0x11223344;
+ const uint32_t ByteSwappedVal = 0x44332211;
+ const uint32_t BitSwappedVal = 0x22cc4488;
Register CopyBSwap = Copies[Copies.size() - 2];
Register CopyBitReverse = Copies[Copies.size() - 1];
@@ -1378,13 +1379,13 @@ TEST_F(AArch64GISelMITest, TestKnownBitsBSwapBitReverse) {
KnownBits BSwapKnown = Info.getKnownBits(CopyBSwap);
EXPECT_EQ(32u, BSwapKnown.getBitWidth());
- EXPECT_EQ(TestVal, BSwapKnown.One.getZExtValue());
- EXPECT_EQ(~TestVal, BSwapKnown.Zero.getZExtValue());
+ EXPECT_EQ(ByteSwappedVal, BSwapKnown.One.getZExtValue());
+ EXPECT_EQ(~ByteSwappedVal, 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());
+ EXPECT_EQ(BitSwappedVal, BitReverseKnown.One.getZExtValue());
+ EXPECT_EQ(~BitSwappedVal, BitReverseKnown.Zero.getZExtValue());
}
TEST_F(AArch64GISelMITest, TestKnownBitsUMAX) {
diff --git a/llvm/unittests/CodeGen/GlobalISel/KnownBitsVectorTest.cpp b/llvm/unittests/CodeGen/GlobalISel/KnownBitsVectorTest.cpp
index 6def98803b6bf..a4767ead1bf24 100644
--- a/llvm/unittests/CodeGen/GlobalISel/KnownBitsVectorTest.cpp
+++ b/llvm/unittests/CodeGen/GlobalISel/KnownBitsVectorTest.cpp
@@ -1227,7 +1227,8 @@ TEST_F(AArch64GISelMITest, TestVectorKnownBitsBSwapBitReverse) {
if (!TM)
return;
- const uint32_t TestVal = 0x11223344;
+ const uint32_t ByteSwappedVal = 0x44332211;
+ const uint32_t BitSwappedVal = 0x22cc4488;
Register CopyBSwap = Copies[Copies.size() - 2];
Register CopyBitReverse = Copies[Copies.size() - 1];
@@ -1236,13 +1237,13 @@ TEST_F(AArch64GISelMITest, TestVectorKnownBitsBSwapBitReverse) {
KnownBits BSwapKnown = Info.getKnownBits(CopyBSwap);
EXPECT_EQ(32u, BSwapKnown.getBitWidth());
- EXPECT_EQ(TestVal, BSwapKnown.One.getZExtValue());
- EXPECT_EQ(~TestVal, BSwapKnown.Zero.getZExtValue());
+ EXPECT_EQ(ByteSwappedVal, BSwapKnown.One.getZExtValue());
+ EXPECT_EQ(~ByteSwappedVal, 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());
+ EXPECT_EQ(BitSwappedVal, BitReverseKnown.One.getZExtValue());
+ EXPECT_EQ(~BitSwappedVal, BitReverseKnown.Zero.getZExtValue());
}
TEST_F(AArch64GISelMITest, TestKnownBitsVectorUMAX) {
More information about the llvm-commits
mailing list