296 Commits

Author SHA1 Message Date
Evgenii Kudriashov
5b9e1a5758
[X86][AsmParser] Improve rel8 validation (#126073)
* Check the size of immediate operand of rel8
* Rename AbsMem16 related names to AbsMemMode16 to disambiguate mem size
and mode checks.
2025-03-06 21:45:16 +01:00
JaydeepChauhan14
cf05b6e25a
[X86] Added support for 8 and 16bit LEA instructions (#122102) 2025-03-04 08:12:17 +08:00
Craig Topper
9844badfca
[X86] Use loaded/stored element size when parsing/printing gather/scatter pointer size in Intel syntax. (#122530)
This matches binutils.
2025-01-13 10:36:40 -08:00
Phoebe Wang
c72a751dab
[X86][AMX] Support AMX-TRANSPOSE (#113532)
Ref.: https://cdrdv2.intel.com/v1/dl/getContent/671368
2024-11-01 16:45:03 +08:00
Rahul Joshi
62e2c7fb2d
[LLVM][TableGen] Change all Init pointers to const (#112705)
This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-10-18 07:50:22 -07:00
Rahul Joshi
a140931be5
[TableGen] Change getValueAsListOfDefs to return const pointer vector (#110713)
Change `getValueAsListOfDefs` to return a vector of const Record
pointer, and remove `getValueAsListOfConstDefs` that was added as a
transition aid.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-10-01 14:30:38 -07:00
Rahul Joshi
1a793a8ca0
[LLVM][TableGen] Change X86InstrMapping to use const RecordKeeper (#109066)
Change X86InstrMappingEmitter to use const RecordKeeper.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-18 10:41:21 -07:00
Phoebe Wang
259ca9ee9c
Reland "[X86][AVX10.2] Support AVX10.2 option and VMPSADBW/VADDP[D,H,S] new instructions (#101452)" (#101616)
Ref.: https://cdrdv2.intel.com/v1/dl/getContent/828965
2024-08-03 09:26:07 +08:00
Phoebe Wang
2e0588d5e1
Revert "[X86][AVX10.2] Support AVX10.2 option and VMPSADBW/VADDP[D,H,S] new instructions" (#101612)
Reverts llvm/llvm-project#101452

There are several buildbot failed. Revert first.
2024-08-02 13:04:10 +08:00
Phoebe Wang
10bad2c8d7
[X86][AVX10.2] Support AVX10.2 option and VMPSADBW/VADDP[D,H,S] new instructions (#101452)
Ref.: https://cdrdv2.intel.com/v1/dl/getContent/828965
2024-08-02 12:10:50 +08:00
XinWang10
7b766a6f50
[X86] Support APX CMOV/CFCMOV instructions (#82592)
This patch support ND CMOV instructions and CFCMOV instructions.

RFC:
https://discourse.llvm.org/t/rfc-design-for-apx-feature-egpr-and-ndd-support/73031/4
2024-03-17 20:18:56 +08:00
Shengchen Kan
1ca8092e87
[X86][MC] Support encoding/decoding for APX CCMP/CTEST (#83863)
APX assembly syntax recommendations:
  https://cdrdv2.intel.com/v1/dl/getContent/817241

NOTE:
The change in llvm/tools/llvm-exegesis/lib/X86/Target.cpp is for test
LLVM ::
tools/llvm-exegesis/X86/latency/latency-SETCCr-cond-codes-sweep.s

For `SETcc`, llvm-exegesis would randomly choose 1 other instruction to
test with `SETcc`, after selecting the instruction, llvm-exegesis would
check if the operand is initialized and valid, if not
`randomizeTargetMCOperand` would choose a value for invalid operand, it
misses support for condition code operand, which cause the flaky failure
after `CCMP` supported.

llvm-exegesis can choose `CCMP` without specifying ccmp feature b/c it
use `MCSubtarget` and only16/32/64 bit is considered.
llvm-exegesis doesn't choose other instructions b/c requirement in
`hasAliasingRegistersThrough`: the instruction should use GPR (defined
by `SETcc`) and define `EFLAGS` (used by `SETcc`).
2024-03-08 20:54:33 +08:00
Shengchen Kan
7cd3268804 [X86][TableGen] Fix the mnemonic table for CMPCCXADD
The mnemonic of CMPCCXADD is `cmp${cond}xadd` and the condition code
is in the middle of mnemonic. When generating the function name for
CMPCCXADD, the substring `xadd` should be kept.

Before this patch, the name is `isCMPCC`. After this patch, the name
is `isCMPCCXADD`.
2024-03-05 12:30:55 +08:00
Pierre van Houtryve
b9079baadd
[NFC] clang-format utils/TableGen (#80973)
```
find llvm/utils/TableGen -iname "*.h" -o -iname "*.cpp" | xargs clang-format-16 -i
```

Split from #80847
2024-02-09 09:27:04 +01:00
XinWang10
6d0080b5de
[X86] Support promoted ENQCMD, KEYLOCKER and USERMSR (#77293)
R16-R31 was added into GPRs in
https://github.com/llvm/llvm-project/pull/70958,
This patch supports the promoted ENQCMD, KEYLOCKER and USER-MSR
instructions in EVEX space.

RFC:
https://discourse.llvm.org/t/rfc-design-for-apx-feature-egpr-and-ndd-support/73031/4
2024-01-26 14:24:43 +08:00
Shengchen Kan
d79ccee8dc
[X86][MC] Support encoding/decoding for APX variant ADD/SUB/ADC/SBB/OR/XOR/NEG/NOT instructions (#76319)
Four variants: promoted legacy, ND (new data destination), NF (no flags
update) and NF_ND (NF + ND).

The syntax of NF instructions is aligned with GNU binutils.
https://sourceware.org/pipermail/binutils/2023-September/129545.html
2023-12-28 21:22:03 +08:00
XinWang10
295415e720
[X86][MC] Support Enc/Dec for EGPR for promoted MOVDIR instruction (#74713)
R16-R31 was added into GPRs in
https://github.com/llvm/llvm-project/pull/70958,
This patch supports the encoding/decoding for promoted MOVDIR
instruction in EVEX space.

RFC:
https://discourse.llvm.org/t/rfc-design-for-apx-feature-egpr-and-ndd-support/73031/4
2023-12-15 16:03:17 +08:00
Shengchen Kan
8c2537fde6
[X86][MC] Support encoding/decoding for PUSH2[P]/POP2[P] (#73233)
PUSH2 and POP2 are two new instructions for (respectively)
pushing/popping 2 GPRs at a time to/from
the stack. The opcodes of PUSH2 and POP2 are those of “PUSH r/m” and
“POP r/m” from legacy map 0, but we
require ModRM.Mod = 3 in order to disallow memory operand. 

The 1-bit Push-Pop Acceleration hint described in #73092 applies to
PUSH2/POP2 too, then we have PUSH2P/POP2P.

For AT&T syntax, PUSH2[P] pushes the registers from right to left onto
the stack. POP2[P] pops the stack to registers from right to left. Intel
syntax has the opposite order - from left to right.

The assembly syntax is aligned with GCC & binutils
https://gcc.gnu.org/pipermail/gcc-patches/2023-November/637718.html
2023-11-24 12:29:56 +08:00
Shengchen Kan
39124f525a
[NFC][X86] Clang-format X86RecognizableInstr.cpp (#73278) 2023-11-24 11:45:23 +08:00
Shengchen Kan
42d484082c
[X86][MC] Support encoding/decoding for JMPABS (#72835)
JMPABS is a 64-bit only ISA extension, and acts as a near-direct branch
with an absolute target. The 64-bit immediate operand is treated an as
absolute effective address, which is subject to canonicality checks. It
is in legacy map 0 and requires REX2 prefix with `REX2.M0=0` and
`REX2.W=0`. All other REX2 payload bits are ignored.

blog: https://kanrobert.github.io/rfc/All-about-APX-JMPABS/

This patch
1. Extends `ExplicitVEXPrefix` to `ExplicitOpPrefix` for instrcutions
requires explicit `REX2` or `EVEX`
2. Adds `ATTR_REX2` and `IC_64BIT_REX2` to put `JMPABS` , `MOV EAX,
moffs32` in different tables to avoid opcode conflict

NOTE:
1. `ExplicitREX2Prefix` can be reused by the following PUSHP/POPP
instructions.
2. `ExplicitEVEXPrefix` will be used by the instructions promoted to
EVEX space for EGPR.
2023-11-22 10:26:23 +08:00
Freddy Ye
819ac45d1c
[X86] Add USER_MSR instructions. (#68944)
For more details about this instruction, please refer to the latest ISE
document:
https://www.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html
2023-10-16 10:12:53 +08:00
Shengchen Kan
9616fd1a7d [X86][tablgen] Fix typo in comments, NFC 2023-04-24 13:57:00 +08:00
Shengchen Kan
33e2e713c6 [X86][Tablgen] Rename IgnoresVEX_W to IgnoresW, VEX_WIG to WIG, NFCI
We no longer distinguish REX.W from VEX.W in .td.
2023-04-20 11:15:09 +08:00
Shengchen Kan
3490345670 [X86][NFC] Combine HasVEX_W with hasREX_W to save 1 bit of TSFlags
Post: https://discourse.llvm.org/t/save-some-bits-in-tsflags-for-x86/69025

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D147443
2023-04-04 10:24:55 +08:00
Wang, Xin10
4dd5e9c60e [X86][MC]Fix wrong action for encode movdir64b
Movdir64b is special for its mem operand, 67 prefex can not only modify its add size,
so it's mem base and index reg should be the same type as source reg, such as
movdir64b (%rdx), rcx, and could not be movdir64b (%edx), rcx.
Now llvm-mc can encode the asm 'movdir64b (%edx), rcx' but the result is the same as
'movdir64b (%edx), ecx', which offend users' intention, while gcc will object this
action and give a warning.
I add 3 new mem descriptions to let llvm-mc to report the same error.

Reviewed By: skan, craig.topper

Differential Revision: https://reviews.llvm.org/D145893
2023-03-17 03:30:16 -04:00
Fangrui Song
3cfe412e4c [TableGen] llvm::Optional => std::optional 2022-12-06 07:21:02 +00:00
Freddy Ye
fdac4c4e92 [X86] Add CMPCCXADD instructions.
For more details about these instructions, please refer to the latest ISE document: https://www.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html

Reviewed By: pengfei, skan

Differential Revision: https://reviews.llvm.org/D135933
2022-10-25 14:33:39 +08:00
Amir Ayupov
c0128549b0 [TableGen][X86] Add Size field to X86MemOperand class
Set Size appropriately in operand definitions and query it for dumping memory
operand size table `getMemOperandSize` (follow-up use D126116) and
`X86Disassembler::getMemOperandSize`.

Excerpt from a produced `getMemOperandSize` table for X86:

```
static int getMemOperandSize(int OpType) {
  switch (OpType) {
  default: return 0;
  case OpTypes::i8mem:
  case OpTypes::i8mem_NOREX:
    return 8;

  case OpTypes::f16mem:
  case OpTypes::i16mem:
    return 16;

  case OpTypes::f32mem:
  case OpTypes::i32mem:
    return 32;
...
```

Reviewed By: skan, pengfei

Differential Revision: https://reviews.llvm.org/D127787
2022-06-19 11:46:56 -07:00
Harald van Dijk
3337f50625
[X86] Fix handling of maskmovdqu in x32 differently
This reverts the functional changes of D103427 but keeps its tests, and
and reimplements the functionality by reusing the existing 32-bit
MASKMOVDQU and VMASKMOVDQU instructions as suggested by skan in review.
These instructions were previously predicated on Not64BitMode. This
reimplementation restores the disassembly of a class of instructions,
which will see a test added in followup patch D122449.

These instructions are in 64-bit mode special cased in
X86MCInstLower::Lower, because we use flags with one meaning for subtly
different things: we have an AdSize32 class which indicates both that
the instruction needs a 0x67 prefix and that the text form of the
instruction implies a 0x67 prefix. These instructions are special in
needing a 0x67 prefix but having a text form that does *not* imply a
0x67 prefix, so we encode this in MCInst as an instruction that has an
explicit address size override.

Note that originally VMASKMOVDQU64 was special cased to be excluded from
disassembly, as we cannot distinguish between VMASKMOVDQU and
VMASKMOVDQU64 and rely on the fact that these are indistinguishable, or
close enough to it, at the MCInst level that it does not matter which we
use. Because VMASKMOVDQU now receives special casing, even though it
does not make a difference in the current implementation, as a
precaution VMASKMOVDQU is excluded from disassembly rather than
VMASKMOVDQU64.

Reviewed By: RKSimon, skan

Differential Revision: https://reviews.llvm.org/D122540
2022-04-12 18:32:14 +01:00
Shengchen Kan
4a48742922 [X86][tablgen] Extract common functions in X86EVEX2VEXTablesEmitter.cpp and X86FoldTablesEmitter.cpp to avoid duplicated code. NFC 2022-03-27 08:47:18 +08:00
Shengchen Kan
a86cd3be1c [X86][tablgen] Rename some fields for RecognizableInstrBase to align with fields in TD file. NFC
The comment for `HasVEX_L` is updated.
2022-03-26 23:32:50 +08:00
Shengchen Kan
dc68ca3eff [X86][tablgen] Rename field hasREX_WPrefix to hasREX_W for X86Inst. NFC
To make it more like hasVEX_L and hasEVEX_K, etc.
2022-03-26 23:14:08 +08:00
Shengchen Kan
271e8d2495 [X86][tablgen] Refine the class RecognizableInstr. NFCI
1. Add comments to explain why we set `isAsmParserOnly` for XACQUIRE and XRELEASE
2. Check `X86Inst` in the constructor of `RecognizableInstrBase` so that
   we can avoid the case where one of it's field is not initialized but
   accessed by user. (e.g. in X86EVEX2VEXTablesEmitter.cpp)
3. Move `Rec` from `RecognizableInstrBase` to `RecognizableInstr` to reduce
   size of `RecognizableInstrBase`
4. Remove out-of-date comments for shouldBeEmitted() (filter() was removed)
5. Add a basic field `IsAsmParserOnly` and remove the field
   `ShouldBeEmitted` b/c we can deduce it w/ little overhead
2022-03-26 22:41:49 +08:00
Shengchen Kan
c8ea732937 [X86][tablgen] Set ShouldBeEmitted to false when isAsmParserOnly is true. NFCI
In fact, an instruction can not be emitted to disassemble table when
`isAsmParserOnly` is true, so `isAsmParserOnly=true` implies
`ShouldBeEmitted=false`.

We check `isAsmParserOnly` in X86FoldTablesEmitter.cpp at a early stage
b/c none of them is foldable.
2022-03-26 19:10:58 +08:00
Shengchen Kan
5f543cb0ef [X86][tablgen] Use initializer list for some fields of RecognizableInstr*. NFC
Also, some code in constructor of `RecognizableInstrBase` is formatted.
2022-03-26 18:03:13 +08:00
Shengchen Kan
7a94fa58c4 [X86][tablgen] Move fields Name, Is64Bit, Is32Bit, Operands from RecognizableInstrBase to RecognizableInstr, NFCI
These four fields are not used by any user of `RecognizableInstrBase`,
so we can move them to `RecognizableInstr` to avoid unnecessary
construction.
2022-03-26 16:43:18 +08:00
Shengchen Kan
bf11ed293a [X86][tablgen] Add class RecognizableInstrBase to simplify X86 code, NFCI 2022-03-26 13:03:06 +08:00
Shengchen Kan
e13faa40cf [X86][tablgen] Add interface getMnemonic to namespace X86Disassembler, NFCI
Address comments in D122477 b/c `getMnemonic` is common to X86 and may be
used in more than one place.
2022-03-26 09:55:54 +08:00
Aakanksha
b0225ab8fd Prevent comparison with wider type in loop condition
This change fixes the code violations flagged in AMD compute CodeQL scan - "comparison-with-wider-type"

Differential Revision: https://reviews.llvm.org/D122447
2022-03-25 11:35:18 +00:00
Aakanksha
bf60a1c546 Avoid comparisons between types of different widths in a loop condition to prevent the loop from behaving unexpectedly
This change fixes the code violations flagged in AMD compute CodeQL scan -
Query Description: "Comparisons between types of different widths in a loop condition can cause the loop to behave unexpectedly."

Differential Revision: https://reviews.llvm.org/D120355
2022-02-25 17:30:12 +00:00
serge-sans-paille
2dde5c9734 Cleanup llvm/utils/TableGen headers
Based on the output of include-what-you-use.
It's an utility directory, so no much impact on other code areas.

clang++ -E  -Iinclude -I../llvm/include ../llvm/utils/TableGen/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l
before: 4327274
after:  4316190

Related discourse thread: https://llvm.discourse.group/t/include-what-you-use-include-cleanup
Differential Revision: https://reviews.llvm.org/D118466
2022-01-31 11:16:28 +01:00
Kazu Hirata
4e3eebc6bd [tools, utils] Use StringRef::contains (NFC) 2021-10-22 17:22:13 -07:00
Liu, Chen3
7f793b102c [X86][NFC] Remove unused encoding string: VK[1/2/4/8/16]PAIR
This is also a bug. The VK[1/2/4/8/16]PAIR here should be VK[1/2/4/8/16]Pair which has its
custom PrintMethod and ParserMatchClass. However we don't have any instructions using vvvv
and ModR/M.REG field so this issue is not exposed.

Differential Revision: https://reviews.llvm.org/D109564
2021-09-10 13:02:11 +08:00
Wang, Pengfei
6f7f5b54c8 [X86] AVX512FP16 instructions enabling 1/6
1. Enable FP16 type support and basic declarations used by following patches.
2. Enable new instructions VMOVW and VMOVSH.

Ref.: https://software.intel.com/content/www/us/en/develop/download/intel-avx512-fp16-architecture-specification.html

Reviewed By: LuoYuanke

Differential Revision: https://reviews.llvm.org/D105263
2021-08-10 12:46:01 +08:00
Harald van Dijk
a8ad917054
[X86] Fix handling of maskmovdqu in X32
The maskmovdqu instruction is an odd one: it has a 32-bit and a 64-bit
variant, the former using EDI, the latter RDI, but the use of the
register is implicit. In 64-bit mode, a 0x67 prefix can be used to get
the version using EDI, but there is no way to express this in
assembly in a single instruction, the only way is with an explicit
addr32.

This change adds support for the instruction. When generating assembly
text, that explicit addr32 will be added. When not generating assembly
text, it will be kept as a single instruction and will be emitted with
that 0x67 prefix. When parsing assembly text, it will be re-parsed as
ADDR32 followed by MASKMOVDQU64, which still results in the correct
bytes when converted to machine code.

The same applies to vmaskmovdqu as well.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D103427
2021-07-15 22:56:08 +01:00
Simon Pilgrim
94da2cf650 [X86] Avoid std::string creation in RecognizableInstr constructor. NFCI.
The value names in byteFromRec calls are compile time constants - just create StringRef directly instead of via std::string.
2020-12-18 16:00:41 +00:00
Craig Topper
71b49aa438 [X86] Allow lsl/lar to be parsed with a GR16, GR32, or GR64 as source register.
This matches GNU assembler behavior. Operand size is determined
only from the destination register.
2020-07-15 23:51:37 -07:00
Xiang1 Zhang
aded4f0cc0 [X86-64] Support Intel AMX instructions
Summary:
INTEL ADVANCED MATRIX EXTENSIONS (AMX).
AMX is a new programming paradigm, it has a set of 2-dimensional registers
(TILES) representing sub-arrays from a larger 2-dimensional memory image and
operate on TILES.

Spec can be found in Chapter 3 here https://software.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html

Reviewers: LuoYuanke, annita.zhang, pengfei, RKSimon, xiangzhangllvm

Reviewed By: xiangzhangllvm

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D82705
2020-07-02 08:57:04 +08:00
Craig Topper
0dda5e4ce2 [X86] Ignore bits 2:0 of the modrm byte when disassembling lfence, mfence, and sfence.
These are documented as using modrm byte of 0xe8, 0xf0, and 0xf8
respectively. But hardware ignore bits 2:0. So 0xe9-0xef is treated
the same as 0xe8. Similar for the other two.

Fixing this required adding 8 new formats to the X86 instructions
to convey this information. Could have gotten away with 3, but
adding all 8 made for a more logical conversion from format to
modrm encoding.

I renumbered the format encodings to keep the register modrm
formats grouped together.
2020-06-19 22:24:24 -07:00
Craig Topper
8875ee18d7 [X86] Add a new format type for instructions that represent named prefix bytes like data16 and rep. Use it to make a simpler version of isPrefix.
isPrefix was added to support the patches to align branches.
it relies on a switch over instruction names.

This moves those opcodes to a new format so the information is
tablegen and we can just check for a specific value in some bits
in TSFlags instead.

I've left the other function in place for now so that the
existing patches in phabricator will still work. I'll work with
the owner to get them migrated.
2020-02-21 12:34:59 -08:00