[llvm] 6239d67 - [GISel][NFC]: Add unit test for clarifying CSE behavior
Aditya Nandakumar via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 11 12:50:14 PDT 2020
Author: Aditya Nandakumar
Date: 2020-06-11T12:49:41-07:00
New Revision: 6239d67001843722cb5d6e08d4368492fa5dbd9e
URL: https://github.com/llvm/llvm-project/commit/6239d67001843722cb5d6e08d4368492fa5dbd9e
DIFF: https://github.com/llvm/llvm-project/commit/6239d67001843722cb5d6e08d4368492fa5dbd9e.diff
LOG: [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
Added:
Modified:
llvm/unittests/CodeGen/GlobalISel/CSETest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/CodeGen/GlobalISel/CSETest.cpp b/llvm/unittests/CodeGen/GlobalISel/CSETest.cpp
index 1c86d5ff9943..556f4f29b992 100644
--- a/llvm/unittests/CodeGen/GlobalISel/CSETest.cpp
+++ b/llvm/unittests/CodeGen/GlobalISel/CSETest.cpp
@@ -77,6 +77,25 @@ TEST_F(AArch64GISelMITest, TestCSE) {
auto Undef0 = CSEB.buildUndef(s32);
auto Undef1 = CSEB.buildUndef(s32);
EXPECT_EQ(&*Undef0, &*Undef1);
+
+ // If the observer is installed to the MF, CSE can also
+ // track new instructions built without the CSEBuilder and
+ // the newly built instructions are available for CSEing next
+ // time a build call is made through the CSEMIRBuilder.
+ // Additionally, the CSE implementation lazily hashes instructions
+ // (every build call) to give chance for the instruction to be fully
+ // built (say using .addUse().addDef().. so on).
+ GISelObserverWrapper WrapperObserver(&CSEInfo);
+ RAIIMFObsDelInstaller Installer(*MF, WrapperObserver);
+ MachineIRBuilder RegularBuilder(*MF);
+ RegularBuilder.setInsertPt(*EntryMBB, EntryMBB->begin());
+ auto NonCSEFMul = RegularBuilder.buildInstr(TargetOpcode::G_AND)
+ .addDef(MRI->createGenericVirtualRegister(s32))
+ .addUse(Copies[0])
+ .addUse(Copies[1]);
+ auto CSEFMul =
+ CSEB.buildInstr(TargetOpcode::G_AND, {s32}, {Copies[0], Copies[1]});
+ EXPECT_EQ(&*CSEFMul, &*NonCSEFMul);
}
TEST_F(AArch64GISelMITest, TestCSEConstantConfig) {
More information about the llvm-commits
mailing list