Skip to content

Commit 6239d67

Browse files
author
Aditya Nandakumar
committed
[GISel][NFC]: Add unit test for clarifying CSE behavior
Add a unit test that shows how CSE works if we install an observer at the machine function level and not use the CSEMIRBuilder to build instructions. https://reviews.llvm.org/D81625
1 parent c08ea07 commit 6239d67

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

llvm/unittests/CodeGen/GlobalISel/CSETest.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,25 @@ TEST_F(AArch64GISelMITest, TestCSE) {
7777
auto Undef0 = CSEB.buildUndef(s32);
7878
auto Undef1 = CSEB.buildUndef(s32);
7979
EXPECT_EQ(&*Undef0, &*Undef1);
80+
81+
// If the observer is installed to the MF, CSE can also
82+
// track new instructions built without the CSEBuilder and
83+
// the newly built instructions are available for CSEing next
84+
// time a build call is made through the CSEMIRBuilder.
85+
// Additionally, the CSE implementation lazily hashes instructions
86+
// (every build call) to give chance for the instruction to be fully
87+
// built (say using .addUse().addDef().. so on).
88+
GISelObserverWrapper WrapperObserver(&CSEInfo);
89+
RAIIMFObsDelInstaller Installer(*MF, WrapperObserver);
90+
MachineIRBuilder RegularBuilder(*MF);
91+
RegularBuilder.setInsertPt(*EntryMBB, EntryMBB->begin());
92+
auto NonCSEFMul = RegularBuilder.buildInstr(TargetOpcode::G_AND)
93+
.addDef(MRI->createGenericVirtualRegister(s32))
94+
.addUse(Copies[0])
95+
.addUse(Copies[1]);
96+
auto CSEFMul =
97+
CSEB.buildInstr(TargetOpcode::G_AND, {s32}, {Copies[0], Copies[1]});
98+
EXPECT_EQ(&*CSEFMul, &*NonCSEFMul);
8099
}
81100

82101
TEST_F(AArch64GISelMITest, TestCSEConstantConfig) {

0 commit comments

Comments
 (0)