24205 Commits

Author SHA1 Message Date
Simon Pilgrim
8b43c1be23
[X86] X86FixupVectorConstants - shrink vector load to movsd/movsd/movd/movq 'zero upper' instructions (#79000)
If we're loading a vector constant that is known to be zero in the upper elements, then attempt to shrink the constant and just scalar load the lower 32/64 bits.

Always chose the vzload/broadcast with the smallest constant load, and prefer vzload over broadcasts for same bitwidth to avoid domain flips (mainly a AVX1 issue).

Fixes #73783
2024-01-24 14:00:51 +00:00
Simon Pilgrim
72f10f7eb5 [X86] Fold not(pcmpeq(and(X,CstPow2),0)) -> pcmpeq(and(X,CstPow2),CstPow2)
Fixes #78888
2024-01-24 12:04:45 +00:00
Simon Pilgrim
17cfc15d6b Fix spelling typo. NFC
commutatvity -> commutativity
2024-01-24 12:04:44 +00:00
Shengchen Kan
303e64826b [X86][NFC] Remove dead code for "_REV" instructions
ADC/SBB with reverse encoding is never emitted by compiler before
encoding optimization, which is called after flag-copy lowering.

This is a partial reland for 8bbf100799a97f8342bf1a8409c6fb48f03e837f
2024-01-24 17:26:57 +08:00
Shengchen Kan
33ecef9812
[X86][CodeGen] Fix crash when commute operands of Instruction for code size (#79245)
Reported in 134fcc62786d31ab73439201dce2d73808d1785a

Incorrect opcode is used  b/c there is a `[[fallthrough]]` at line 2386.
2024-01-24 17:10:28 +08:00
Shengchen Kan
71d64ed80f [X86][Peephole] Add NDD entries for EFLAGS optimization 2024-01-24 15:47:58 +08:00
Shengchen Kan
f7b61f81b5
[X86][CodeGen] Transform NDD SUB to CMP if dest reg is dead (#79135) 2024-01-24 13:58:48 +08:00
paperchalice
7251243315
[CodeGen][Passes] Move CodeGenPassBuilder.h to Passes (#79242)
`CodeGenPassBuilder` is not very tightly coupled to CodeGen, it may need
to reference some method in pass builder in future, so move
`CodeGenPassBuilder.h` to Passes.
2024-01-24 11:29:18 +08:00
paperchalice
7e50f006f7
[NewPM][CodeGen][llc] Add NPM support (#70922)
Add new pass manager support to `llc`. Users can use
`--passes=pass1,pass2...` to run mir passes, and use `--enable-new-pm`
to run default codegen pipeline.
This patch is taken from [D83612](https://reviews.llvm.org/D83612), the
original author is @yuanfang-chen.

---------

Co-authored-by: Yuanfang Chen <455423+yuanfang-chen@users.noreply.github.com>
2024-01-24 09:27:25 +08:00
Anatoly Trosinenko
10bd69a4f7
[MachineOutliner] Refactor iterating over Candidate's instructions (#78972)
Make Candidate's front() and back() functions return references to
MachineInstr and introduce begin() and end() returning iterators, the
same way it is usually done in other container-like classes.

This makes possible to iterate over the instructions contained in
Candidate the same way one can iterate over MachineBasicBlock (note that
begin() and end() return bundled iterators, just like MachineBasicBlock
does, but no instr_begin() and instr_end() are defined yet).
2024-01-23 17:21:40 +03:00
Simon Pilgrim
4318b033bd
[MC][X86] Merge lane/element broadcast comment printers. (#79020)
This is /almost/ NFC - the only annoyance is that for some reason we were using "<C1,C2,..>" for ConstantVector types unlike all other cases - these now use the same "[C1,C2,..]" format as the other constant printers.
2024-01-23 12:33:52 +00:00
Simon Pilgrim
5c7bbe383b [X86] canonicalizeShuffleWithOp - recognise constant vectors with getTargetConstantFromNode
Allows shuffle to fold constant vectors that have already been lowered to constant pool - shuffle combining can then constant fold this.

Noticed while triaging #79100
2024-01-23 11:30:06 +00:00
Shengchen Kan
66237d647e [X86][CodeGen] Add entries for NDD SHLD/SHRD to the commuteInstructionImpl 2024-01-23 17:05:09 +08:00
Shengchen Kan
134fcc6278 [X86][NFC] Simplify function X86InstrInfo::commuteInstructionImpl 2024-01-23 16:32:32 +08:00
Aiden Grossman
7da7695839
[llvm-exegesis] Add additional validation counters (#76788)
This patch adds support for additional types of validation counters and
also adds mappings between these new validation counter types and
physical counters on the hardware for microarchitectures that I have the
ability to test on.
2024-01-23 00:06:46 -08:00
Shengchen Kan
5c68c6d70f
[X86] Support encoding/decoding and lowering for APX variant SHL/SHR/SAR/ROL/ROR/RCL/RCR/SHLD/SHRD (#78853)
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-23 10:23:27 +08:00
Alexandre Ganea
bb28442c0b
[CodeGen][X86] Fix lowering of tailcalls when -ms-hotpatch is used (#77245)
Previously, tail jump pseudo-opcodes were skipped by the
`encodeInstruction()` call inside `X86AsmPrinter::LowerPATCHABLE_OP`.
This caused emission of a 2-byte NOP and dropping of the tail jump.

With this PR, we change `PATCHABLE_OP` to not wrap the first
`MachineInstr` anymore, but inserting itself before,
leaving the instruction unaltered. At lowering time in `X86AsmPrinter`,
we now "look ahead" for the next non-pseudo `MachineInstr` and
lower+encode it, to inspect its size. If the size is below what
`PATCHABLE_OP` expects, it inserts NOPs; otherwise it does nothing. That
way, now the first `MachineInstr` is always lowered as usual even if
`"patchable-function"="prologue-short-redirect"` is used.

Fixes https://github.com/llvm/llvm-project/issues/76879,
https://github.com/llvm/llvm-project/issues/76958 and
https://github.com/llvm/llvm-project/issues/59039
2024-01-22 14:19:08 -05:00
Simon Pilgrim
27eb8d53ae [X86] printConstant - add ConstantVector handling 2024-01-22 15:59:55 +00:00
Simon Pilgrim
74ab7958bd [X86] printZeroUpperMove - add support for constant vectors.
Allows cases where movss/movsd etc. are loading constant (ConstantDataSequential) sub-vectors, ensuring we pad with the correct number of zero upper elements by making repeated printConstant calls to print zeroes in a matching int/fp format.
2024-01-22 15:40:46 +00:00
Simon Pilgrim
4e64ed9780 [X86] Update X86::getConstantFromPool to take base OperandNo instead of Displacement MachineOperand
This allows us to check the entire constant address calculation, and ensure we're not performing any runtime address math into the constant pool (noticed in an upcoming patch).
2024-01-22 15:40:45 +00:00
Simon Pilgrim
60963272c5 [X86] Add printElementBroadcast constant comments helper. NFC.
Pull out helper instead of repeating switch cases.
2024-01-22 12:16:19 +00:00
Simon Pilgrim
09bd2cb70f [X86] Add printLaneBroadcast constant comments helper. NFC.
Pull out helper instead of repeating switch cases.
2024-01-22 12:16:18 +00:00
Simon Pilgrim
1a5eeade16 [X86] Add printZeroUpperMove constant/shuffle comments helper. NFC.
Pull out helper instead of repeating switch cases.
2024-01-22 11:44:51 +00:00
Simon Pilgrim
c1729c8df2 [X86] X86FixupVectorConstants.cpp - pull out rebuildConstant helper for future patches. NFC.
Add helper to convert raw APInt bit stream into ConstantDataVector elements.

This was used internally by rebuildSplatableConstant but will be reused in future patches for #73783 and #71078
2024-01-22 11:44:51 +00:00
Shengchen Kan
c2bef33c5e [X86][NFC] Auto-generate the function to check predicate for EVEX compression 2024-01-22 11:49:24 +08:00
XinWang10
dd6fec5d4f
[X86][APX]Support lowering for APX promoted AMX-TILE instructions (#78689)
The enc/dec of promoted AMX-TILE instructions have been supported in
https://github.com/llvm/llvm-project/pull/76210.
This patch support lowering for promoted AMX-TILE instructions and
integrate test to existing tests.
2024-01-22 11:33:23 +08:00
XinWang10
d3cd1ce6ab
[X86] Add lowering tests for promoted CMPCCXADD and update CC representation (#78685)
https://github.com/llvm/llvm-project/pull/76125 supported the enc/dec
for CMPCCXADD instructions, this patch
1. Add lowering test for promoted CMPCCXADD
2. Update the representation of condition code for promoted CMPCCXADD to
align with the existing one
2024-01-22 11:32:03 +08:00
Shengchen Kan
07e6b983cc [X86][NFC] Remove unnecessary parameters for MaskedShiftAmountPats/MaskedRotateAmountPats and rename one_bit_patterns
This patch is to extract NFC in #78853 into a separate commit.
2024-01-21 19:20:10 +08:00
Arthur Eubanks
86eaf6083b
[X86] Refine X86DAGToDAGISel::isSExtAbsoluteSymbolRef() (#76191)
We just need to check if the global is large or not.

In the kernel code model, globals are in the negative 2GB of the address
space, so globals can be a sign extended 32-bit immediate.

In other code models, small globals are in the low 2GB of the address
space, so sign extending them is equivalent to zero extending them.
2024-01-19 14:11:18 -08:00
Jie Fu
0d51c8704c [X86] Fix -Wsign-compare in X86MCInstLower.cpp (NFC)
llvm-project/llvm/lib/Target/X86/X86MCInstLower.cpp:1867:20:
 error: comparison of integers of different signs: 'int' and 'unsigned int' [-Werror,-Wsign-compare]
      if (SclWidth == C->getType()->getScalarSizeInBits()) {
          ~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
2024-01-19 22:38:47 +08:00
Simon Pilgrim
a2a0089ac3
[X86] movsd/movss/movd/movq - add support for constant comments (#78601)
If we're loading a constant value, print the constant (and the zero upper elements) instead of just the shuffle mask.

This did require me to move the shuffle mask handling into addConstantComments as we can't handle this in the MC layer.
2024-01-19 14:21:26 +00:00
Amir Ayupov
9fec33aadc Revert "[BOLT] Fix unconditional output of boltedcollection in merge-fdata (#78653)"
This reverts commit 82bc33ea3f1a539be50ed46919dc53fc6b685da9.

Accidentally pushed unrelated changes.
2024-01-18 19:59:09 -08:00
Amir Ayupov
82bc33ea3f
[BOLT] Fix unconditional output of boltedcollection in merge-fdata (#78653)
Fix the bug where merge-fdata unconditionally outputs boltedcollection 
line, regardless of whether input files have it set.

Test Plan:
Added bolt/test/X86/merge-fdata-nobat-mode.test which fails without this
fix.
2024-01-18 19:44:16 -08:00
Shoaib Meenai
741b836330
[X86] Fix RTTI proxy emission for 32-bit (#78622)
32-bit x86 doesn't have an appropriate relocation type we can use to
elide the RTTI proxies, so we need to emit them. This would previously
cause crashes when using the relative vtable ABI for 32-bit x86.
2024-01-18 13:31:33 -08:00
XinWang10
d124b02242
[X86][MC] Fix wrong encoding of promoted BMI instructions due to missing NoCD8 (#78386)
Address review comments in #76709

Add `NoCD8` to class `ITy`, and rewrite the promoted instructions with
`ITy` to avoid unexpected incorrect encoding about `NoCD8`.
2024-01-19 00:27:16 +08:00
Shengchen Kan
8bc7c0a058 [X86] Fix failures on EXPENSIVE_CHECKS builds
Error message

```
*** Bad machine code: Illegal virtual register for instruction ***
- function:    test__blsi_u32
- basic block: %bb.0  (0x7a61208)
- instruction: %5:gr32 = MOV32r0 implicit-def $eflags
- operand 0:   %5:gr32
Expected a GR32_NOREX2 register, but got a GR32 register
```

Reported by RKSimon in #77433

The failure is b/c compiler emits a MOV32r0 with operand GR32 when
fast-isel is enabled.

```
// X86FastISel.cpp
Register SrcReg = fastEmitInst_(X86::MOV32r0, &X86::GR32RegClass)
```

However, before this patch, compiler only allows GR32_NOREX operand
b/c MOV32r0 is a pseudo instruction. In this patch, we relax the
register class of the operand to GR32 b/c MOV32r0 is always expanded
to XOR32rr, which can use EGPR.

The bug was not introduced by #77433 but caught by it.
2024-01-19 00:19:55 +08:00
Simon Pilgrim
110e1717b3 [X86] X86MCInstLower.cpp - fix spelling mistake 2024-01-18 15:44:27 +00:00
Simon Pilgrim
33287e35f2
[X86] Emit verbose (constant) comments before EVEX compression tag (#78585)
This helps ensure the encoding details are next to the EVEX tag

Noticed while preparing to add more constant commenting as part of #73783 and #71078
2024-01-18 15:13:42 +00:00
Simon Pilgrim
d12dffacaa [X86] Add X86::getConstantFromPool helper function to replace duplicate implementations.
We had the same helper function in shuffle decode / vector constant code - move this to X86InstrInfo to avoid duplication.
2024-01-18 11:59:46 +00: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
Fangrui Song
d4cb5d9f2b
[X86] Add "Ws" constraint and "p" modifier for symbolic address/label reference (#77886)
Printing the raw symbol is useful in inline asm (e.g. getting the C++
mangled name, referencing a symbol in a custom way while ensuring it is
not optimized out even if internal). Similar constraints are available
in other targets (e.g. "S" for aarch64/riscv, "Cs" for m68k).

```
namespace ns { extern int var, a[4]; }
void foo() {
  asm(".pushsection .xxx,\"aw\"; .dc.a %p0; .popsection" :: "Ws"(&ns::var));
  asm(".reloc ., BFD_RELOC_NONE, %p0" :: "Ws"(&ns::a[3]));
}
```

Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105576
2024-01-16 23:57:42 -08:00
Phoebe Wang
8d6e82d501
[X86] Use vXi1 for k constraint in inline asm (#77733)
Fixes #77172
2024-01-17 11:40:32 +08:00
Phoebe Wang
9745c13ca8
[X86][BF16] Improve float -> bfloat lowering under AVX512BF16 and AVXNECONVERT (#78042) 2024-01-17 10:09:26 +08:00
Shengchen Kan
6c1b5ec213 [X86][NFC] Simplify the patterns of BMI shift/rotate instructions in X86InstrCompiler.td
This patch is to extract NFC in #77433 into a separate commit.
2024-01-16 23:59:08 +08:00
Shengchen Kan
dfaf09b5d1 [X86][NFC] Simplify the patterns of BMI shift/rotate instructions in X86InstrShiftRotate.td
This patch is to extract NFC in #77433 into a separate commit.
2024-01-16 23:02:02 +08:00
Shengchen Kan
86bc18ade8 [X86][NFC] Simplify the definitions of BMI shift/rotate instructions 2024-01-16 19:53:57 +08:00
Shengchen Kan
2c4a53ad51 [X86][NFC] Simplify the definitions of double precision shift instructions 2024-01-16 17:45:54 +08:00
Shengchen Kan
199117ae09 [X86] Fix error: unused variable 'isMemOp' after #78019, NFCI
BTW, I adjust the code by LLVM coding standards.
2024-01-16 13:14:55 +08:00
Jie Fu
d338d15243 [X86] Fix -Wunused-variable in X86InstrInfo.cpp (NFC)
llvm-project/llvm/lib/Target/X86/X86InstrInfo.cpp:3467:14:
error: unused variable 'isMemOp' [-Werror,-Wunused-variable]
 3467 |   const auto isMemOp = [](const MCOperandInfo &OpInfo) -> bool {
      |              ^~~~~~~
1 error generated.
2024-01-16 11:57:13 +08:00
Shengchen Kan
3d68217454 [X86][NFC] Simplify the definitions of rotate instructions 2024-01-16 11:24:31 +08:00