[llvm] e89bcfc - [SandboxIR] Add tracking for ShuffleVectorInst::commute. (#106644)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 3 10:03:14 PDT 2024
Author: Jorge Gorbe Moya
Date: 2024-09-03T10:03:08-07:00
New Revision: e89bcfc0e86cd4952c03fdf920d11c598ae6e16a
URL: https://github.com/llvm/llvm-project/commit/e89bcfc0e86cd4952c03fdf920d11c598ae6e16a
DIFF: https://github.com/llvm/llvm-project/commit/e89bcfc0e86cd4952c03fdf920d11c598ae6e16a.diff
LOG: [SandboxIR] Add tracking for ShuffleVectorInst::commute. (#106644)
Track it as an operand swap + a `setShuffleMask` and delegate to the
`llvm::ShuffleVectorInst` implementation.
Added:
Modified:
llvm/include/llvm/SandboxIR/SandboxIR.h
llvm/lib/SandboxIR/SandboxIR.cpp
llvm/unittests/SandboxIR/TrackerTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index 2ed7243fa612f4..63c32da7cad20e 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIR.h
+++ b/llvm/include/llvm/SandboxIR/SandboxIR.h
@@ -1143,7 +1143,7 @@ class ShuffleVectorInst final
/// Swap the operands and adjust the mask to preserve the semantics of the
/// instruction.
- void commute() { cast<llvm::ShuffleVectorInst>(Val)->commute(); }
+ void commute();
/// Return true if a shufflevector instruction can be formed with the
/// specified operands.
diff --git a/llvm/lib/SandboxIR/SandboxIR.cpp b/llvm/lib/SandboxIR/SandboxIR.cpp
index 6bdc580f751d18..f95ced880d4cb2 100644
--- a/llvm/lib/SandboxIR/SandboxIR.cpp
+++ b/llvm/lib/SandboxIR/SandboxIR.cpp
@@ -2185,6 +2185,13 @@ VectorType *ShuffleVectorInst::getType() const {
Ctx.getType(cast<llvm::ShuffleVectorInst>(Val)->getType()));
}
+void ShuffleVectorInst::commute() {
+ Ctx.getTracker().emplaceIfTracking<ShuffleVectorSetMask>(this);
+ Ctx.getTracker().emplaceIfTracking<UseSwap>(getOperandUse(0),
+ getOperandUse(1));
+ cast<llvm::ShuffleVectorInst>(Val)->commute();
+}
+
Constant *ShuffleVectorInst::getShuffleMaskForBitcode() const {
return Ctx.getOrCreateConstant(
cast<llvm::ShuffleVectorInst>(Val)->getShuffleMaskForBitcode());
diff --git a/llvm/unittests/SandboxIR/TrackerTest.cpp b/llvm/unittests/SandboxIR/TrackerTest.cpp
index c189100fbd6947..fe29452a8aea20 100644
--- a/llvm/unittests/SandboxIR/TrackerTest.cpp
+++ b/llvm/unittests/SandboxIR/TrackerTest.cpp
@@ -964,7 +964,7 @@ define void @foo(i32 %cond0, i32 %cond1) {
EXPECT_EQ(Switch->findCaseDest(BB1), One);
}
-TEST_F(TrackerTest, ShuffleVectorInstSetters) {
+TEST_F(TrackerTest, ShuffleVectorInst) {
parseIR(C, R"IR(
define void @foo(<2 x i8> %v1, <2 x i8> %v2) {
%shuf = shufflevector <2 x i8> %v1, <2 x i8> %v2, <2 x i32> <i32 1, i32 2>
@@ -983,10 +983,22 @@ define void @foo(<2 x i8> %v1, <2 x i8> %v2) {
SmallVector<int, 2> OrigMask(SVI->getShuffleMask());
Ctx.save();
SVI->setShuffleMask(ArrayRef<int>({0, 0}));
- EXPECT_THAT(SVI->getShuffleMask(),
- testing::Not(testing::ElementsAreArray(OrigMask)));
+ EXPECT_NE(SVI->getShuffleMask(), ArrayRef<int>(OrigMask));
Ctx.revert();
- EXPECT_THAT(SVI->getShuffleMask(), testing::ElementsAreArray(OrigMask));
+ EXPECT_EQ(SVI->getShuffleMask(), ArrayRef<int>(OrigMask));
+
+ // Check commute.
+ auto *Op0 = SVI->getOperand(0);
+ auto *Op1 = SVI->getOperand(1);
+ Ctx.save();
+ SVI->commute();
+ EXPECT_EQ(SVI->getOperand(0), Op1);
+ EXPECT_EQ(SVI->getOperand(1), Op0);
+ EXPECT_NE(SVI->getShuffleMask(), ArrayRef<int>(OrigMask));
+ Ctx.revert();
+ EXPECT_EQ(SVI->getOperand(0), Op0);
+ EXPECT_EQ(SVI->getOperand(1), Op1);
+ EXPECT_EQ(SVI->getShuffleMask(), ArrayRef<int>(OrigMask));
}
TEST_F(TrackerTest, PossiblyDisjointInstSetters) {
More information about the llvm-commits
mailing list