[llvm] f3d9abf - [X86][mem-fold] Use the generated memory folding table

Shengchen Kan via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 6 04:49:46 PDT 2023


Author: Shengchen Kan
Date: 2023-04-06T19:49:39+08:00
New Revision: f3d9abf1f87c308e9d7bd368b3ad54cb8f28ac4f

URL: https://github.com/llvm/llvm-project/commit/f3d9abf1f87c308e9d7bd368b3ad54cb8f28ac4f
DIFF: https://github.com/llvm/llvm-project/commit/f3d9abf1f87c308e9d7bd368b3ad54cb8f28ac4f.diff

LOG: [X86][mem-fold] Use the generated memory folding table

Reviewed By: yubing

Differential Revision: https://reviews.llvm.org/D147527

Added: 
    llvm/test/TableGen/x86-fold-tables.inc
    llvm/test/TableGen/x86-fold-tables.td

Modified: 
    llvm/lib/Target/X86/CMakeLists.txt
    llvm/lib/Target/X86/X86InstrFoldTables.cpp

Removed: 
    llvm/lib/Target/X86/X86MemFoldTables.inc
    llvm/test/TableGen/x86-memory-folding.td


################################################################################
diff  --git a/llvm/lib/Target/X86/CMakeLists.txt b/llvm/lib/Target/X86/CMakeLists.txt
index 5eba6db5b06eb..4296ab1a6b33e 100644
--- a/llvm/lib/Target/X86/CMakeLists.txt
+++ b/llvm/lib/Target/X86/CMakeLists.txt
@@ -18,10 +18,7 @@ tablegen(LLVM X86GenMnemonicTables.inc -gen-x86-mnemonic-tables -asmwriternum=1)
 tablegen(LLVM X86GenRegisterBank.inc -gen-register-bank)
 tablegen(LLVM X86GenRegisterInfo.inc -gen-register-info)
 tablegen(LLVM X86GenSubtargetInfo.inc -gen-subtarget)
-
-if (X86_GEN_FOLD_TABLES)
-  tablegen(LLVM X86GenFoldTables.inc -gen-x86-fold-tables -asmwriternum=1)
-endif()
+tablegen(LLVM X86GenFoldTables.inc -gen-x86-fold-tables -asmwriternum=1)
 
 add_public_tablegen_target(X86CommonTableGen)
 

diff  --git a/llvm/lib/Target/X86/X86InstrFoldTables.cpp b/llvm/lib/Target/X86/X86InstrFoldTables.cpp
index c66355ddec395..51b37fdc626e1 100644
--- a/llvm/lib/Target/X86/X86InstrFoldTables.cpp
+++ b/llvm/lib/Target/X86/X86InstrFoldTables.cpp
@@ -22,18 +22,7 @@ using namespace llvm;
 // searched at runtime without the need for additional storage. The enum values
 // are currently emitted in X86GenInstrInfo.inc in alphabetical order. Which
 // makes sorting these tables a simple matter of alphabetizing the table.
-//
-// We also have a tablegen emitter that tries to autogenerate these tables
-// by comparing encoding information. This can be enabled by passing
-// X86_GEN_FOLD_TABLES=ON to cmake which fill produce X86GenFoldTables.inc
-// in the build area. There are currently some bugs in the autogenerated table
-// that require a manual review to copy them from the autogenerated table into
-// this table. It is unclear if we will ever be able to fully automate this
-// because as new instruction are added into holes in the X86 opcode map they
-// potentially pair up with old instructions and create new entries in the
-// tables that would be incorrect. The manual review process allows us a chance
-// to catch these before they become observable bugs.
-#include "X86MemFoldTables.inc"
+#include "X86GenFoldTables.inc"
 static const X86MemoryFoldTableEntry BroadcastFoldTable2[] = {
   { X86::VADDPDZ128rr,   X86::VADDPDZ128rmb,   TB_BCAST_SD },
   { X86::VADDPDZ256rr,   X86::VADDPDZ256rmb,   TB_BCAST_SD },

diff  --git a/llvm/lib/Target/X86/X86MemFoldTables.inc b/llvm/test/TableGen/x86-fold-tables.inc
similarity index 100%
rename from llvm/lib/Target/X86/X86MemFoldTables.inc
rename to llvm/test/TableGen/x86-fold-tables.inc

diff  --git a/llvm/test/TableGen/x86-fold-tables.td b/llvm/test/TableGen/x86-fold-tables.td
new file mode 100644
index 0000000000000..d6e59bea0000b
--- /dev/null
+++ b/llvm/test/TableGen/x86-fold-tables.td
@@ -0,0 +1,7 @@
+// Steps to fix this test if it fails:
+//   1. Update X86ManualFoldTables.def to manually correct the entries in fold tables, or
+//      fix the vulnerable rules in X86FoldTablesEmitter.cpp until the 
diff  is reasonable
+//   2. cp <generated_file> x86-fold-tables.inc
+
+// RUN: llvm-tblgen -gen-x86-fold-tables -asmwriternum=1 %p/../../lib/Target/X86/X86.td -I %p/../../lib/Target/X86 -I %p/../../include -o %t
+// RUN: 
diff  %p/x86-fold-tables.inc %t

diff  --git a/llvm/test/TableGen/x86-memory-folding.td b/llvm/test/TableGen/x86-memory-folding.td
deleted file mode 100644
index a33d587ed8bdd..0000000000000
--- a/llvm/test/TableGen/x86-memory-folding.td
+++ /dev/null
@@ -1,2 +0,0 @@
-// RUN: llvm-tblgen -gen-x86-fold-tables -asmwriternum=1 %p/../../lib/Target/X86/X86.td -I %p/../../lib/Target/X86 -I %p/../../include -o %t1
-// RUN: cmp %p/../../lib/Target/X86/X86MemFoldTables.inc %t1


        


More information about the llvm-commits mailing list