198 Commits

Author SHA1 Message Date
Phoebe Wang
17ac7e0e84
[X86][APX] Fix a typo in LEA suffix (#135734)
Found during reviewing #135632
2025-04-15 17:00:25 +08:00
JaydeepChauhan14
cf05b6e25a
[X86] Added support for 8 and 16bit LEA instructions (#122102) 2025-03-04 08:12:17 +08:00
Sergei Barannikov
501a583441
[TableGen][SelectionDAG] Remove the implicit DAG node (#115295)
The node was introduced in 59c39dc1 and was intended to allow writing
patterns like this:
`[(set AL, (mul AL, GR8:$src1)), (implicit EFLAGS)]`

However, it does not introduce new functionality because the same
pattern can be equivalently expressed as:
`[(set AL, EFLAGS, (mul AL, GR8:$src1))]`

The latter form is also more flexible as it allows reordering output
operands.

In most places uses of `implicit` were redundant -- removing them didn't
change anything in the generated DAG tables. The only three cases where
it did have effect are in X86InstrArithmetic.td and X86InstrSystem.td --
those were rewritten to use `set` node.

Removing `implicit` from some patterns made them importable by GISel,
hence the change in a test.
2024-11-09 07:25:40 +03:00
Shengchen Kan
b6c9dcc9f5 [X86][CodeGen] Not emit mr_ND if rr_ND is commutable
This gives us more chance to compress instruction in X86CompressEVEX.cpp
b/c mr_ND is not a candidate of instructions to be compressed while
rm_ND is.
2024-06-20 21:09:04 +08:00
Shengchen Kan
919c547130 [X86] Fix indention in X86InstrArithmetic.td, NFCI 2024-06-20 17:32:17 +08:00
Freddy Ye
db7d243978
[X86][MC] Support enc/dec for IMULZU. (#86653)
apx-spec: https://cdrdv2.intel.com/v1/dl/getContent/784266
apx-syntax-recommendation:
https://cdrdv2.intel.com/v1/dl/getContent/817241
2024-03-29 15:52:41 +08:00
XinWang10
816cc9d24b
[X86][MC] Support Enc/Dec for NF BMI instructions (#76709)
Promoted BMI instructions were supported in #73899
2024-01-25 10:33:14 +08:00
XinWang10
2d92f7de80
[X86] Support lowering for APX promoted BMI instructions. (#77433)
R16-R31 was added into GPRs in
https://github.com/llvm/llvm-project/pull/70958,
This patch supports the lowering for promoted BMI instructions in EVEX
space, enc/dec has been supported in
https://github.com/llvm/llvm-project/pull/73899.

RFC:
https://discourse.llvm.org/t/rfc-design-for-apx-feature-egpr-and-ndd-support/73031/4
2024-01-18 10:15:54 +08:00
Shengchen Kan
1fe7bdb87b
[X86][CodeGen] Support lowering for NDD ADD/SUB/ADC/SBB/OR/XOR/NEG/NOT/INC/DEC/IMUL (#77564)
We supported encoding/decoding for these instructions in

https://github.com/llvm/llvm-project/pull/76319
https://github.com/llvm/llvm-project/pull/76721
https://github.com/llvm/llvm-project/pull/76919
2024-01-11 12:15:17 +08:00
Shengchen Kan
4daea501c4
[X86][MC] Support encoding/decoding for APX variant MUL/IMUL/DIV/IDIV instructions (#76919)
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
2024-01-05 17:16:55 +08:00
Shengchen Kan
dd9681f839
[X86][MC] Support encoding/decoding for APX variant INC/DEC/ADCX/ADOX instructions (#76721)
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
2024-01-04 10:12:12 +08:00
Shengchen Kan
82fabd537f [X86][NFC] Remove redundant "NAME#" in X86InstrArithmetic.td 2024-01-03 10:41:15 +08:00
Shengchen Kan
a1f1371fdc [X86][NFC] Remove redundant constraints in X86InstrArithmetic.td after #76319 2023-12-29 19:52:53 +08:00
Shengchen Kan
d3ddb93d04 [X86] Fix typo about the internal name of instructions
64ri -> 64ri32
2023-12-29 12:18:34 +08:00
Shengchen Kan
0207e9eae9 [X86][NFC] Move classe BinOp*, UnaryOp* to X86InstrUtils.td and simplify CRC32 definitions
1. BinOp*, UnaryOp* will be used in X86InstrShiftRotate.td for the APX
   support
2. Simplify CRC32 definitions to extract the NFC change in 76434 into a
   separate commit
2023-12-29 00:12:08 +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
Shengchen Kan
9f4b6e1bd3 [X86][NFC] Simplify the definitions of INC/DEC and NEG/NOT
This patch is to extract the NFC in #76319 into a separate commit.
2023-12-27 13:58:17 +08:00
Shengchen Kan
75073e0c88 [X86][NFC] Simplify the definitions of MUL/IMUL and DIV/IDIV
This patch is to extract the NFC in #76319 into a separate commit.
2023-12-26 22:05:39 +08:00
Shengchen Kan
250e98ee66 [X86][NFC] Simplify the definition of ANDN by using class ITy 2023-12-26 16:35:04 +08:00
Shengchen Kan
66922a566b [X86][NFC] Simplify the definition of MULX by using class ITy 2023-12-26 14:32:22 +08:00
Shengchen Kan
f9e23991a7 [X86][NFC] Remove class ADCOXOp(RR|RM) and redundant let statements
1. Remove these two classes b/c opcode is changed from 0xF6 to 0x66
   after promotion, then the classes become useless.
2. Remove `OpSize = OpSizeFixed` b/c the default value is OpSizeFixed.
3. Remove `let isCommutable = 1` b/c ADCX/ADOX is not VEX-encoding,
   we can not apply VEX3ToVEX2 optimization for it and the compiler
   never emits it.
4. Remove predicate `HasADX` due to no pattern

This patch is to extract the NFC in #76319 into a separate commit.
2023-12-26 12:55:47 +08:00
Shengchen Kan
1479fe8492 [X86][NFC] Rename variables and define a var for duplicated strings in X86InstrArithmetic.td
This patch is to extract the NFC in #76319 into a separate commit.
2023-12-24 18:54:54 +08:00
Shengchen Kan
17ff25a58e [X86][NFC] Not infer OpSize from Xi8|16|32|64
For legacy (arithmetic) instructions, the operand size override prefix (0x66)
is used to switch the operand data size from 32b to 16b (in 32/64-bit mode),
16b to 32b (in 16-bit mode). That's why we set OpSize16 for 16-bit instructions
and set OpSize32 for 32-bit instructions.

But it's not a generic rule any more after APX. APX adds 4 variants for
arithmetic instructions: promoted EVEX, NDD (new data destination), NF (no flag),
NF_NDD. All the 4 variants are in EVEX space and only legal in 64-bit
mode. EVEX.pp is set to 01 for the 16-bit instructions to encode 0x66.
For APX, we should set OpSizeFixed for 8/16/32/64-bit variants and set PD for
the 16-bit variants.

Hence, to reuse the classes ITy and its subclasses BinOp* for APX instructions,
we extract the OpSize setting from the class ITy.
2023-12-24 12:00:25 +08:00
Shengchen Kan
6e20df1a3b [X86][NFC] Set default OpPrefix to PS for XOP/VEX/EVEX instructions
It helps simplify the class definitions. Now, the only explicit usage of PS is
to check prefix 0x66/0xf2/0xf3 can not be used a prefix, e.g. wbinvd.

See 82974e0114f02ffc07557e217d87f8dc4e100a26 for more details.
2023-12-24 10:20:40 +08:00
Shengchen Kan
ff32ab3ae7 [X86][NFC] Not imply TB in PS|PD|XS|XD
This can help us aovid introducing new classes T_MAP*PS|PD|XS|XD
when a new opcode map is supported.

And, T_MAP*PS|PD|XS|XD does not look better than T_MAP*, PS|PD|XS|XD.
2023-12-22 15:44:30 +08:00
Shengchen Kan
62d8ae0a1e [X86][NFC] Remove class (VEX/EVEX/XOP)_4V and add class VVVV
`VEX_4V` does not look simpler than `VEX, VVVV`. It's kind of confusing
b/c classes like `VEX_L`, `VEX_LIG` do not imply `VEX` but it does.

For APX, we have promote EVEX, NDD, NF and NDD_NF instructions. All of
the 4 variants are in EVEX space and NDD/NDD_NF set the VVVV fields.
To extract the common fields (e.g EVEX) into a class and set VVVV
conditionally, we need VVVV to not imply other prefixes.
2023-12-22 10:38:15 +08:00
Shengchen Kan
8eccf2b872 [X86] Set Uses = [EFLAGS] for ADCX/ADOX
According to Intel SDE, ADCX reads CF and ADOX reads OF. `Uses` was
set to empty by accident, the bug was not exposed b/c compiler never
emits these instructions.
2023-12-21 23:01:00 +08:00
Shengchen Kan
2fe94cead0 [X86][NFC] Refine code in X86InstrArithmetic.td
1. Simplify the variable name
2. Change HasOddOpcode to HasEvenOpcode b/c
  a. opcode of any 8-bit arithmetic instruction is even
  b. opcode of a 16/32/64-bit arithmetic instruction is usually
     odd, but it can be even sometimes, e.g. INC/DEC, ADCX/ADOX
  c. so that we can remove `let Opcode = o` for the mentioned corner
     cases.
2023-12-21 22:24:59 +08:00
Shengchen Kan
b223aebd3f [X86][NFC] Refine code in X86InstrArithmetic.td
1. Remove redandunt classes
2. Correct comments
3. Move duplicated `let` statement into class definition
4. Simplify the variable name and align the code
2023-12-21 20:50:09 +08:00
Shengchen Kan
b26c0ed93a [X86][NFC] Remove class BinOpRM_ImplicitUse b/c it's used once only 2023-12-21 11:31:39 +08:00
Shengchen Kan
689db42c9c
[X86][NFC] Reorgnize the X86Instr*.td (#74454)
1. Move all pattern fragments for SIMD instructions to X86InstrFragmentsSIMD.td
2. Create X86InstrFragments.td and move non-SIMD pattern fragments into it
3. Create X86InstrOperands.td and move operand definitions into it
4. Create X86InstrPredicates.td and move predicate definitions into it
5. Create X86InstrUtils.td and move utilities for simplifying the instruction definitions into it
2023-12-06 11:00:22 +08:00
XinWang10
de55a2843f
[X86][MC] Support Enc/Dec for EGPR for promoted BMI instructions (#73899)
R16-R31 was added into GPRs in
https://github.com/llvm/llvm-project/pull/70958,
This patch supports the encoding/decoding for promoted BMI instructions
in EVEX space.


RFC:
https://discourse.llvm.org/t/rfc-design-for-apx-feature-egpr-and-ndd-support/73031/4
2023-12-01 17:39:25 +08:00
Shengchen Kan
4537985ccc [X86][CodeGen] Remove CodeSize settings for instructions, NFCI
CodeSize was designed to used as the 3rd isel sorting tie-breaker.
From observation, it has no impact on X86 ISEL.
2023-11-28 10:59:42 +08:00
Shengchen Kan
f450fc3edb Revert "[X86][NFC] Remove dead code in TD for ADCX/ADOX"
This reverts commit 3ce43f16af86ffd6b454b76c5dced1b91c23676c.

It caused MC/Disassembler/X86/x86-64.txt to fail.
2023-08-14 16:28:36 +08:00
Shengchen Kan
3ce43f16af [X86][NFC] Remove dead code in TD for ADCX/ADOX 2023-08-14 16:21:07 +08:00
Wang, Xin10
af55b0d79d [X86][NFC] Fix a bug after D150436 and update some comments
D150436 changed the order for INC*r, but unintentionally remove 'isConvertibleToThreeAddress = 1' for INC*r_alt.
This patch also update wrong comment X86InstrArithmetic.td, and move class ITy to InstrInfo.td for it's a general class.

Reviewed By: skan

Differential Revision: https://reviews.llvm.org/D151527
2023-05-28 21:09:37 -04:00
Shengchen Kan
0d9b36ce7d [X86] Remove patterns for IMUL with immediate 8 and optimize during MC lowering, NFCI 2023-05-20 11:14:03 +08:00
Shengchen Kan
c81a121f3f Revert "Revert "[X86] Remove patterns for ADC/SBB with immediate 8 and optimize during MC lowering, NFCI""
This reverts commit cb16b33a03aff70b2499c3452f2f817f3f92d20d.

In fact, the test https://bugs.chromium.org/p/chromium/issues/detail?id=1446973#c2
already passed after 5586bc539acb26cb94e461438de01a5080513401
2023-05-19 22:21:56 +08:00
Hans Wennborg
cb16b33a03 Revert "[X86] Remove patterns for ADC/SBB with immediate 8 and optimize during MC lowering, NFCI"
This caused compiler assertions, see comment on
https://reviews.llvm.org/D150107.

This also reverts the dependent follow-up change:

> [X86] Remove patterns for ADD/AND/OR/SUB/XOR/CMP with immediate 8 and optimize during MC lowering, NFCI
>
> This is follow-up of D150107.
>
> In addition, the function `X86::optimizeToFixedRegisterOrShortImmediateForm` can be
> shared with project bolt and eliminates the code in X86InstrRelaxTables.cpp.
>
> Differential Revision: https://reviews.llvm.org/D150949

This reverts commit 2ef8ae134828876ab3ebda4a81bb2df7b095d030 and
5586bc539acb26cb94e461438de01a5080513401.
2023-05-19 14:43:33 +02:00
Shengchen Kan
5586bc539a [X86] Remove patterns for ADD/AND/OR/SUB/XOR/CMP with immediate 8 and optimize during MC lowering, NFCI
This is follow-up of D150107.

In addition, the function `X86::optimizeToFixedRegisterOrShortImmediateForm` can be
shared with project bolt and eliminates the code in X86InstrRelaxTables.cpp.

Differential Revision: https://reviews.llvm.org/D150949
2023-05-19 18:22:30 +08:00
Shengchen Kan
2ef8ae1348 [X86] Remove patterns for ADC/SBB with immediate 8 and optimize during MC lowering, NFCI
This is follow-up of D150107.
2023-05-19 10:33:52 +08:00
Wang, Xin10
9a24ba2397 Correct the sort logic in AsmMatcherEmmitter.cpp
The logic from line 633 to 640 is specific for ARM as the comments said, it will make all the targets will prefer to using instruction with more predicates when compiler do AsmMatching.
And for code from line 642 to 649, X86 want to use the order records written in source file to sort the instructions. So X86 could be affected by this logic. (These code could be arrived only by X86)
After change this, seems AVX instructions have not be affected but it exposed some other errors for instruction push and call.
CALLpcrel16 could not be used in 64 bit mode, we need add Predicate for it. And for push instruction, previously because pushi32 has predicates = [Not64bitmode], so it precede pushi16, which is incorrect here, we should get pushw here and it also align with gcc.

Reviewed By: skan

Differential Revision: https://reviews.llvm.org/D150436
2023-05-16 02:44:02 -04:00
Wang, Xin10
c719a19158 [NFC]adjust identaion and update comments in X86InstrArithmeic.td
After https://reviews.llvm.org/D144154, I introduce some identation issues,
and some comments are not that precise.

Reviewed By: skan

Differential Revision: https://reviews.llvm.org/D150025
2023-05-06 06:15:34 -04:00
Shengchen Kan
8c132c17bb [X86][tablgen] Fix typo in comments, NFC 2023-04-21 17:20:00 +08:00
Shengchen Kan
1e75ce4289 [X86][mem-fold] Remove the logic for FoldGenData, NFCI 2023-04-05 23:24:25 +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
XinWang10
4950104e24 [NFC][X86]remove trailing space in X86InstrArithmetic.td
In this file, most of the line don't have trailing spaces,
but some of them have. To keep consistent, remove the trailing
spaces.

Reviewed By: skan

Differential Revision: https://reviews.llvm.org/D146697
2023-03-23 22:32:45 -04:00
Luo, Yuanke
e4ceb5a7bb [X86] Create extra prolog/epilog for stack realignment
Fix some bugs and reland e4c1dfed38370b4 and 614c63bec6d67c.
1. Run argument stack rebase pass before the reserved physical register
   is finalized.
2. Add LEA pseudo instruction to prevent the instruction being
   eliminated.
3. Don't support X32.
2023-03-22 22:20:27 +08:00
Wang, Xin10
749318dbfb [X86][NFC] Refactor X86InstrArithmetic.td by class
1. Extract the common code of some instructions into a class to reduce duplication
2. Refine some comments to the make the description of the class clearer

By this way, the records defined here will be consistent and easier to
maintain, I think.

Reviewed By: skan

Differential Revision: https://reviews.llvm.org/D144154
2023-02-22 09:19:53 +08:00
Wang, Xin10
b9ea7327c0 [X86][NFC] Reorganize X86InstrInfo.td
For now X86InstrInfo.td has many definitions for some instrs
and patterns which I think should not exist here, extract them
and move to other files.

It will be more clear to me that X86InstrInfo just define some
X86 specific properties and would not include detailed instrs
definition.

Reviewed By: skan

Differential Revision: https://reviews.llvm.org/D144244
2023-02-21 11:03:31 +08:00