23579 Commits

Author SHA1 Message Date
Simon Pilgrim
a279a09ab9 Revert rG98061013e01207444cfd3980 - [X86] X86FixupVectorConstantsPass - attempt to replace full width fp vector constant loads with broadcasts on AVX+ targets
Reverting while we address an existing issue exposed by this (Issue #63108)
2023-06-06 18:44:24 +01:00
Simon Pilgrim
78de45fd4a Revert rGab4b924832ce26c21b88d7f82fcf4992ea8906bb - [X86] X86FixupVectorConstantsPass - attempt to replace full width integer vector constant loads with broadcasts on AVX2+ targets
Reverting while we address an existing issue exposed by this (Issue #63108)
2023-06-06 18:07:33 +01:00
prabhukr
30198bd788 [Triple] Add triple for UEFI
Target triple to support "x86_64-unknown-uefi"

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D131594
2023-06-06 08:42:28 -07:00
Simon Pilgrim
c6f5f6ab61 [GlobalISel][X86] Move G_SEXT_INREG legalization handling to beside the regular integer extension legalizations 2023-06-06 14:39:10 +01:00
Jay Foad
304538ae7b [GlobalIsel][X86] Remove an unused variable 2023-06-06 14:10:14 +01:00
Simon Pilgrim
ee1d6132e7 [GlobalIsel][X86] Update legalization of G_FADD/G_FSUB/G_FMUL/G_FDIV + G_FC
Replace the legacy legalizer versions
2023-06-06 13:47:34 +01:00
Simon Pilgrim
85b77b13e3 [GlobalISel][X86] Add G_IMPLICIT_DEF / G_CONSTANT legalization handling 2023-06-06 11:45:22 +01:00
Thorsten Schütt
60b8019ea0 [GlobalIsel][X86] Legalize G_ANYEXT, G_SEXT, and G_ZEXT
Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D152243
2023-06-06 12:22:09 +02:00
Phoebe Wang
6e488e40e7 Reland "[X86][NFC] Refactor: there's only v16bf16 in 256-bit shuffle" 2023-06-06 10:49:25 +08:00
Phoebe Wang
4ac501c5ca Revert "[X86][NFC] Refactor: there's only v16bf16 in 256-bit shuffle"
This reverts commit 50a2341fe92f8a5ff934bd279450581e9cbcf103.

This results in buildbot fail.
2023-06-06 10:41:26 +08:00
Phoebe Wang
50a2341fe9 [X86][NFC] Refactor: there's only v16bf16 in 256-bit shuffle 2023-06-06 10:27:09 +08:00
Simon Pilgrim
d37bd544ff [X86] canonicalizeShuffleWithBinOps - ensure a binary shuffle of binops have the same value type
Fixes #63091
2023-06-05 11:18:28 +01:00
Simon Pilgrim
346ee549e5 [GlobalISel][X86] Add G_CTTZ_ZERO_UNDEF/G_CTTZ legalization handling
G_CTTZ_ZERO_UNDEF is always legal using the BSF instruction, G_CTTZ requires the BMI1 TZCNT instruction
2023-06-05 11:18:27 +01:00
Simon Pilgrim
0702d4e04d [GlobalIsel][X86] Move G_ICMP legalization before legacy handling and merge 32-bit/64-bit handling
I've kept the legalForCartesianProduct call, but this requires us to maintain 32-bit/64-bit integer lists - we might want to just use legalIf and perform the type pair set matching manually.
2023-06-04 17:01:57 +01:00
Simon Pilgrim
6effec1a50 [GlobalIsel][X86] Move G_PTRTOINT/G_INTTOPTR legalization before legacy handling and merge 32-bit/64-bit handling
I've kept the legalForCartesianProduct call, but this requires us to maintain 32-bit/64-bit integer lists - we might want to just use legalIf and perform the type pair set matching manually.
2023-06-04 15:21:42 +01:00
Simon Pilgrim
73f55f7928 [GlobalIsel][X86] Remove some unused setLegalizerInfo* methods. NFC.
We're moving away from using per-ISA legalization controls and using LegalIf etc. to handle specific ISAs instead.
2023-06-04 12:34:14 +01:00
Simon Pilgrim
9424a54201 [GlobalIsel][X86] Update legalization of G_AND/G_OR/G_XOR
Replace the legacy G_AND/G_OR/G_XOR legalizer, this handles all scalar promotion and vector clamping (allows AVX1 to handle 256-bit logic ops).
2023-06-04 11:44:27 +01:00
Simon Pilgrim
4dcd66a005 [GlobalIsel][X86] Update legalization of G_MUL
Replace the legacy G_MUL legalizer, this handles all scalar promotion and vector clamping, however we still need to add custom legalization for many vector multiplies.
2023-06-03 18:22:02 +01:00
Nitin John Raj
aa7eace843 [TableGen][GlobalISel] Account for HwMode in RegisterBank register sizes
This patch adds logic for determining RegisterBank size to RegisterBankInfo, which allows accounting for the HwMode of the target. Individual RegisterBanks cannot be constructed with HwMode information as construction is generated by TableGen, but a RegisterBankInfo subclass can provide the HwMode as a constructor argument. The HwMode is used to select the appropriate RegisterBank size from an array relating sizes to RegisterBanks.

Targets simply need to provide the HwMode argument to the <target>GenRegisterBankInfo constructor. The RISC-V RegisterBankInfo constructor has been updated accordingly (plus an unused argument removed).

Reviewed By: simoncook, craig.topper

Differential Revision: https://reviews.llvm.org/D76007
2023-06-02 23:14:17 -07:00
Simon Pilgrim
4fcbe5fbed Revert rG2f9a4d308d4517eee85e373bc09920f85f91fdcd "[GlobalISel][X86] Add G_CTLZ_ZERO_UNDEF legalization handling"
Unintentional commit - G_CTLZ_ZERO_UNDEF will have to be custom handled as BSR needs the bits flipping (and we don't have a pattern for that yet).
2023-06-02 18:43:11 +01:00
Simon Pilgrim
2f9a4d308d [GlobalISel][X86] Add G_CTLZ_ZERO_UNDEF legalization handling 2023-06-02 18:25:03 +01:00
Simon Pilgrim
6d8f889b73 [GlobalIsel][X86] Move G_SHL/G_LSHR/G_ASHR legalization before legacy handling and merge 32-bit/64-bit handling 2023-06-02 16:07:48 +01:00
Simon Pilgrim
d01ddfedba [GlobalIsel][X86] Move G_SDIV/G_SREM/G_UDIV/G_UREM legalization before legacy handling and merge 32-bit/64-bit handling 2023-06-02 16:07:48 +01:00
Simon Pilgrim
0ab4ffa028 [GlobalIsel][X86] Move G_BSWAP/G_CTPOP/G_CTLZ legalization before legacy handling
Also merge 32-bit/64-bit handling of G_CTPOP/G_CTLZ using legalIf()
2023-06-02 14:05:32 +01:00
Simon Pilgrim
a68cd63671 [GlobalIsel][X86] Update legalization of G_ADD/G_SUB
Replace the legacy legalizers for G_ADD/G_SUB with a pattern that should work for the full mixture of scalar/vector types we need to support for most opcodes.

If we can decide on this as a suitable pattern we can reuse it for the other op types, but G_ADD/G_SUB are the only ones that have decent legalizer test coverage at this stage.

Differential Revision: https://reviews.llvm.org/D151878
2023-06-02 11:33:51 +01:00
Thorsten Schütt
3ac9aa2020 [GlobalIsel][X86] Legalize G_BSWAP III
Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D151915
2023-06-02 11:42:25 +02:00
Haohai Wen
8db674ad06 [X86] Add schedule module for SapphireRapids
The X86SchedSapphireRapids.td file is automatically generated by
schedtool (D130897). Most of instruction's scheduling information
is from SapphireRapids tpt/lat data provided by intel doc. Some data
is from measured ADL-P data in uops.info. The rest instruction's
scheduling information is from skylake server schedule model in order
to get a relative complete model.

Reviewed By: LuoYuanke

Differential Revision: https://reviews.llvm.org/D141485
2023-06-02 15:23:50 +08:00
Amir Ayupov
15a719de01 [X86][MC] Use MCInstrDesc to access CondCode operand
BOLT may add an extra MCOperand as annotation, making the number of operands in
MCInst different from MCInstrDesc information. A recent change broke our use as
the last operand is no longer a cond code.

Partially revert 287dd0142c08caad5b32628f3842dfd5d5c59d03 to rely on MCInstrDesc
to access CondCode operand.

Reviewed By: skan

Differential Revision: https://reviews.llvm.org/D151930
2023-06-01 19:00:03 -07:00
Dávid Bolvanský
09515f2c20 [SDAG] Preserve unpredictable metadata, teach X86CmovConversion to respect this metadata
Sometimes an developer would like to have more control over cmov vs branch. We have unpredictable metadata in LLVM IR, but currently it is ignored by X86 backend. Propagate this metadata and avoid cmov->branch conversion in X86CmovConversion for cmov with this metadata.

Example:

```
int MaxIndex(int n, int *a) {
    int t = 0;
    for (int i = 1; i < n; i++) {
        // cmov is converted to branch by X86CmovConversion
        if (a[i] > a[t]) t = i;
    }
    return t;
}

int MaxIndex2(int n, int *a) {
    int t = 0;
    for (int i = 1; i < n; i++) {
        // cmov is preserved
        if (__builtin_unpredictable(a[i] > a[t])) t = i;
    }
    return t;
}
```

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D118118
2023-06-01 20:56:44 +02:00
Simon Pilgrim
8e58fdd1e3 [X86] Fix masked store scheduler ports for skylake models
Only uses port2+3 for agen, and was missing port4 for the actual store

Noticed while investigating the skylake vs icelake diffs for Issue #62602
2023-06-01 11:59:31 +01:00
Antonio Abbatangelo
b7e110fcfe [X86] Align stack to 16-bytes on 32-bit with X86_INTR call convention
Adds a dynamic stack alignment to functions under the interrupt call
convention on x86-32. This fixes the issue where the stack can be
misaligned on entry, since x86-32 makes no guarantees about the stack
pointer position when the interrupt service routine is called.

The alignment is done by overriding X86RegisterInfo::shouldRealignStack,
and by setting the correct alignment in X86FrameLowering::calculateMaxStackAlign.
This forces the interrupt handler to be dynamically aligned, generating
the appropriate `and` instruction in the prologue and `lea` in the
epilogue. The `no-realign-stack` attribute can be used as an opt-out.

Fixes #26851

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D151400
2023-06-01 17:00:34 +08:00
Phoebe Wang
801dd8870f [X86][BF16] Fix 2 crashes with vector broadcast
Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D151808
2023-06-01 13:38:47 +08:00
Simon Pilgrim
d6a36619ce [X86] X86FixupVectorConstantsPass - use VBROADCASTSS/VBROADCASTSD for integer vector loads on AVX1-only targets
Matches behaviour in lowerBuildVectorAsBroadcast
2023-05-31 16:39:09 +01:00
Thorsten Schütt
dd2fea9c23 [GlobalIsel][X86] Legalize G_CTLZ and G_CTPOP for 32-bit
Note that 32-bit support is very limited

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D151459
2023-05-31 14:24:52 +02:00
Simon Pilgrim
f1a42300aa [X86] printConstant - fix asm comment issue when broadcasting from a wider constant pool entry
In cases where a broadcast op is loading from a constant entry wider than the broadcast element, we were incorrectly printing the entire entry and not just the lower bits referenced by the broadcast.
2023-05-31 12:28:17 +01:00
Simon Pilgrim
65dce67f16 [X86] getTargetConstantBitsFromNode - ensure we truncate broadcasts from wider constants.
We might be broadcasting the lower portion of a wider constant pool entry, ensure we truncate the full width of the constant back to the broadcast width.

(This also exposes an issue with how asm comments print these constants - I'll address that in a followup).

Fixes #63030
2023-05-31 12:08:02 +01:00
Simon Pilgrim
9d6f2b1907 [X86] Fix SunnyCove ROB/MicroOpBufferSize
As raised on Issue #62602 - the IceLake scheduler model is still mainly a copy of the SkylakeServer model. This initial commit just fixes the ROB/MicroOpBufferSize to match the size reported on WikiChip/Agner, further fixes to follow in later commits.
2023-05-30 15:01:30 +01:00
Simon Pilgrim
f81f32adc9 [X86] lowerBuildVectorAsBroadcast - remove repeated hasAVX() check. NFC.
We already early-out at the top of the function.
2023-05-30 13:21:28 +01:00
Simon Pilgrim
ab4b924832 [X86] X86FixupVectorConstantsPass - attempt to replace full width integer vector constant loads with broadcasts on AVX2+ targets
lowerBuildVectorAsBroadcast will not broadcast splat constants in all cases, resulting in a lot of situations where a full width vector load that has failed to fold but is loading splat constant values could use a broadcast load instruction just as cheaply, and save constant pool space.
2023-05-30 13:17:26 +01:00
Simon Pilgrim
95661b9c75 [X86] getTargetConstantBitsFromNode - support extracting fp data from ConstantDataSequential
Fixes issue introduced by 0f8e0f4228805cbecce13dcfadef4c48a4f0f4cd where SimplifyDemandedBits could crash when trying to extract fp data from broadcasted constants
2023-05-30 11:38:31 +01:00
Phoebe Wang
8f386ff69a [ms-inline asm] Add error check for getAsInteger
.Imm can get lexed as a real, but a real doesn't equal to .Imm, e.g.,
2.5 or .123e+8. We should report error for it rather than silently ignore.

Reviewed By: skan

Differential Revision: https://reviews.llvm.org/D151652
2023-05-30 11:20:57 +08:00
Simon Pilgrim
98061013e0 [X86] X86FixupVectorConstantsPass - attempt to replace full width fp vector constant loads with broadcasts on AVX+ targets
lowerBuildVectorAsBroadcast will not broadcast splat constants in all cases, resulting in a lot of situations where a full width vector load that has failed to fold but is loading splat constant values could use a broadcast load instruction just as cheaply, and save constant pool space.

NOTE: SSE3 targets can use MOVDDUP but not all SSE era CPUs can perform this as cheaply as a vector load, we will need to add scheduler model checks if we want to pursue this.
2023-05-29 16:10:52 +01: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
Simon Pilgrim
0f8e0f4228 [X86] lowerBuildVectorAsBroadcast - broadcast Constant of original (BuildVector) element size
Noticed in D150143/D150526 - we currently create scalar Constant values using the broadcast instruction width, which might be wider than the original build vector width, making it tricky to recognise the original constant bits data.

If we have widened the broadcast value, its much more useful for asm comments if we create a ConstantVector with the original element data, add that to the constant-pool and load that with the same (wider) broadcast instruction.
2023-05-27 14:05:44 +01:00
Luo, Yuanke
969c686e54 [X86] fold select to mask instructions.
When avx512 is available the lhs operand of select instruction can be
folded with mask instruction, while the rhs operand can't. This patch is
to commute the lhs and rhs of the select instruction to create the
opportunity of folding.

Differential Revision: https://reviews.llvm.org/D151535
2023-05-26 21:53:03 +08:00
Luo, Yuanke
e821db39d2 [NFC] refactor code
Split the NFC patch from D151535. Refactor canCombineAsMaskOperation to
take 1 input operand.
2023-05-26 21:06:23 +08:00
Thorsten Schütt
bc713b193f [GlobalIsel][X86] fix legalization of G_CTLZ and G_CTPOP
Note that the builders are protected by is64Bit().

More fine-grained availibility checks.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D150790
2023-05-25 16:41:14 +02:00
Kyle Huey
3be667ae5a [X86] Use the CFA when appropriate for better variable locations around calls.
Without frame pointers, the locations of variables on the stack are emitted
relative to the stack pointer (via the stack pointer being the value of
DW_AT_frame_base on the subprogram). If a call modifies the stack pointer
this results in the locations being wrong and the debugger displaying the
wrong values for variables.

By using DW_OP_call_frame_cfa in these situations the emitted location for
the variable will automatically handle changes in the stack pointer
(provided LLVM is emitting the correct CFI directives elsewhere, of course).
The CFA needs to be adjusted for the size of the stack frame (including the
return address) to allow the variable locations themselves to remain
unchanged by this patch.

Certain LLDB features cannot cope with DW_OP_call_frame_cfa, so this change
is heuristically limited to the cases where it's necessary for correctness
to minimize the fallout there.

Reviewed By: #debug-info, scott.linder, jryans, jmorse

Differential Revision: https://reviews.llvm.org/D143463
2023-05-23 20:24:55 +00:00
Fangrui Song
e018cbf720 [IR] Make stack protector symbol dso_local according to -f[no-]direct-access-external-data
There are two motivations.

`-fno-pic -fstack-protector -mstack-protector-guard=global` created
`__stack_chk_guard` is referenced directly on all ELF OSes except FreeBSD.
This patch allows referencing the symbol indirectly with
-fno-direct-access-external-data.

Some Linux kernel folks want
`-fno-pic -fstack-protector -mstack-protector-guard-reg=gs -mstack-protector-guard-symbol=__stack_chk_guard`
created `__stack_chk_guard` to be referenced directly, avoiding
R_X86_64_REX_GOTPCRELX (even if the relocation may be optimized out by the linker).
https://github.com/llvm/llvm-project/issues/60116
Why they need this isn't so clear to me.

---

Add module flag "direct-access-external-data" and set the dso_local property of
the stack protector symbol. The module flag can benefit other LLVMCodeGen
synthesized symbols that are not represented in LLVM IR.

Nowadays, with `-fno-pic` being uncommon, ideally we should set
"direct-access-external-data" when it is true. However, doing so would require
~90 clang/test tests to be updated, which are too much.

As a compromise, we set "direct-access-external-data" only when it's different
from the implied default value.

Reviewed By: nickdesaulniers

Differential Revision: https://reviews.llvm.org/D150841
2023-05-23 09:49:57 -07:00
Simon Pilgrim
0b91de5ea3 [X86] Add X86FixupVectorConstantsPass to re-fold AVX512 vector load folds as broadcast folds
This patch analyzes AVX512 instructions for full vector width folded loads from the constant pool and attempts to determine if it can be replaced with a smaller broadcast folded variant. Typically the broadcast opportunities were missed by type-width mismatches or mulituse limitations which have been removed in later passes.

As well as introducing broadcast fold tables (which can hopefully be extended/automated in the future), this also handles mismatches in the AND/ANDN/OR/XOR/TERNLOG type-widths, catching additional missed opportunities.

This is patch is pulled from the ongoing work based on D150143, but without removing the existing DAG constant broadcast lowering code - this patch is currently a late stage cleanup only.

The intention is to add additional broadcast/extension handling of constants in future patches, but it turned out that AVX512 broadcast handling was the easiest to start with.

Differential Revision: https://reviews.llvm.org/D150526
2023-05-23 10:58:17 +01:00