[PATCH] D150633: [X86]check that Uses, Defs are same for entries in memory folding table
Wang, Xin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 15 20:37:48 PDT 2023
XinWang10 created this revision.
Herald added a project: All.
XinWang10 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Add expensive check that Uses, Defs are same for entries in memory folding table.
MemFolding could not change the Uses/Defs.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D150633
Files:
llvm/utils/TableGen/X86FoldTablesEmitter.cpp
Index: llvm/utils/TableGen/X86FoldTablesEmitter.cpp
===================================================================
--- llvm/utils/TableGen/X86FoldTablesEmitter.cpp
+++ llvm/utils/TableGen/X86FoldTablesEmitter.cpp
@@ -107,6 +107,35 @@
OS << SimplifiedAttrs << "},\n";
}
+ #ifndef NDEBUG
+ bool CheckCorrectness() const{
+ // Check that Uses, Defs are same for entries in memory folding table
+ auto& RegInstRec = *RegInst->TheDef;
+ auto& MemInstRec = *MemInst->TheDef;
+ auto ListOfUses_l = RegInstRec.getValueAsListOfDefs("Uses");
+ auto ListOfUses_r = MemInstRec.getValueAsListOfDefs("Uses");
+ auto ListOfDefs_l = RegInstRec.getValueAsListOfDefs("Defs");
+ auto ListOfDefs_r = MemInstRec.getValueAsListOfDefs("Defs");
+ bool ret = true;
+ if (ListOfUses_l.size() != ListOfUses_r.size() ||
+ ListOfDefs_l.size() != ListOfDefs_r.size())
+ ret = false;
+ for (unsigned long i = 0; i < ListOfUses_l.size(); i++) {
+ if (ListOfUses_l[i] != ListOfUses_r[i])
+ ret = false;
+ }
+ for (unsigned long i = 0; i < ListOfDefs_l.size(); i++) {
+ if (ListOfDefs_l[i] != ListOfDefs_r[i])
+ ret = false;
+ }
+ if (!ret) {
+ errs() << "Error: Incorrect converting ";
+ errs() << RegInstRec.getName() << " to ";
+ errs() << MemInstRec.getName() << "\n";
+ }
+ return ret;
+ }
+ #endif
};
// NOTE: We check the fold tables are sorted in X86InstrFoldTables.cpp by the enum of the
@@ -600,6 +629,24 @@
&(Target.getInstruction(MemInstIter)), Entry.Strategy, true);
}
+ #ifndef NDEBUG
+ // To Check if the instructions convertion in MemFoldTable change the Uses
+ // and Defs, it's wrong when we convert it and changed its Defs/Uses.
+ auto CheckMemFoldTable = [] (const FoldTable& table) -> void {
+ for (const auto &record: table){
+ auto& FoldEntry = record.second;
+ if(!FoldEntry.CheckCorrectness()){
+ break;
+ }
+ }
+ };
+ CheckMemFoldTable(Table2Addr);
+ CheckMemFoldTable(Table0);
+ CheckMemFoldTable(Table1);
+ CheckMemFoldTable(Table2);
+ CheckMemFoldTable(Table3);
+ CheckMemFoldTable(Table4);
+ #endif
// Print all tables.
printTable(Table2Addr, "Table2Addr", OS);
printTable(Table0, "Table0", OS);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150633.522420.patch
Type: text/x-patch
Size: 2374 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230516/c91b74fa/attachment.bin>
More information about the llvm-commits
mailing list