8702 Commits

Author SHA1 Message Date
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
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
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
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
Kazu Hirata
be76f1646f [Target] Use getConstantOperandAPInt (NFC) 2024-01-10 21:06:01 -08:00
Simon Pilgrim
cc21aa1922 [X86] lower1BitShuffle - fold permute(setcc(x,y)) -> setcc(permute(x),permute(y)) for 32/64-bit element vectors
Noticed in #77459 - for wider element types, its usually better to pre-shuffle the comparison arguments if we can, like we already for broadcasts
2024-01-10 12:35:50 +00:00
Simon Pilgrim
3210ce2763 [X86] Fold (iX bitreverse(bitcast(vXi1 X))) -> (iX bitcast(shuffle(X)))
X86 doesn't have a BITREVERSE instruction, so if we're working with a casted boolean vector, we're better off shuffling the vector instead if we have PSHUFB (SSSE3 or later)

Fixes #77459
2024-01-09 19:06:32 +00:00
Alex Bradbury
2d54ec36f7
[SelectionDAG] Add and use SDNode::getAsAPIntVal() helper (#77455)
This is the logical equivalent for #76710 for APInt and uses the same
naming scheme.

Converted existing users through:
`git grep -l "cast<ConstantSDNode>\(.*\).*getAPIntValueValue" | xargs
sed -E -i
's/cast<ConstantSDNode>\((.*)\)->getAPIntValue/\1->getAsAPIntVal/'`
2024-01-09 14:27:07 +00:00
Alex Bradbury
197214e39b
[RFC][SelectionDAG] Add and use SDNode::getAsZExtVal() helper (#76710)
This follows on from #76708, allowing
`cast<ConstantSDNode>(N)->getZExtValue()` to be replaced with just
`N->getAsZextVal();`
    
Introduced via `git grep -l "cast<ConstantSDNode>\(.*\).*getZExtValue" |
xargs sed -E -i
's/cast<ConstantSDNode>\((.*)\)->getZExtValue/\1->getAsZExtVal/'` and
then using `git clang-format` on the result.
2024-01-09 12:25:17 +00:00
Aiden Grossman
053aed2024
[X86] Check if machine loop is passed while getting loop alignment (#77283)
After d6bb96e677759375b2bea00115918b2cb6552f5b, calling
getPrefLoopAlignment without passing in a pointer to a MachineLoop
causes a segmentation fault. This conflicts with the API in
TargetLoweringBase where the default MachineLoop pointer passed is
nullptr. This patch fixes this by checking if the pointer points to
something before enabling the optional functionality.
2024-01-08 08:30:26 -08:00
Phoebe Wang
59af659ee3
[X86][BF16] Try to use f16 for lowering (#76901)
This patch fixes BF16 32-bit ABI problem:
https://godbolt.org/z/6dMnh8jGG
2024-01-05 15:25:18 +08:00
Benoit Jacob
054b5fc0fd
X86: add some missing lowerings for shuffles on bf16 element type. (#76076)
Some shuffles with `bf16` as element type were running into a
`llvm_unreachable`. Key to reproducing was to chain two shuffles.

```llvm
define <2 x bfloat> @shuffle_chained_v32bf16_v2bf16(<32 x bfloat> %a) {
  %s = shufflevector <32 x bfloat> %a, <32 x bfloat> zeroinitializer, <32 x i32> <i32 0, i32 16, i32 1, i32 17, i32 2, i32 18, i32 3, i32 19, i32 4, i32 20, i32 5, i32 21, i32 6, i32 22, i32 7, i32 23, i32 8, i32 24, i32 9, i32 25, i32 10, i32 26, i32 11, i32 27, i32 12, i32 28, i32 13, i32 29, i32 14, i32 30, i32 15, i32 31>
  %s2 = shufflevector <32 x bfloat> %s, <32 x bfloat> zeroinitializer, <2 x i32> <i32 0, i32 1>
  ret <2 x bfloat> %s2
}
```

This was hitting this UNREACHABLE:

```
Not a valid 512-bit x86 vector type!
UNREACHABLE executed at /home/benoit/iree/third_party/llvm-project/llvm/lib/Target/X86/X86ISelLowering.cpp:17124!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/benoit/mlir-build/bin/llc -mtriple=x86_64-unknown-linux-gnu -mattr=+avx512f,+avx512vl,+avx512bw,+avx512bf16
1.      Running pass 'Function Pass Manager' on module '<stdin>'.
2.      Running pass 'X86 DAG->DAG Instruction Selection' on function '@shuffle_chained_v32bf16_v2bf16'
```
2024-01-04 22:39:40 -05:00
Simon Pilgrim
076dbc0272 [X86] SimplifyDemandedVectorEltsForTargetNode - add X86ISD::VZEXT_LOAD handling.
Simplify to a scalar_to_vector(load()) if we don't demand any of the upper vector elements.
2024-01-04 17:17:07 +00:00
Simon Pilgrim
6bb8d69f2a [X86] combineLoad - pull out repeated cast<MemSDNode> calls. NFC. 2024-01-04 10:50:42 +00:00
Simon Pilgrim
1d27669e8a [X86] combineConcatVectorOps - fold 512-bit concat(blendi(x,y,c0),blendi(z,w,c1)) to AVX512BW mask select
Yet another yak shaving regression fix for #73509
2024-01-03 12:38:26 +00:00
Simon Pilgrim
39be138cb7 [X86] combineTargetShuffle - fold SHUF128(CONCAT(),CONCAT()) to peek through upper subvectors
If SHUF128 is accessing only the upper half of a vector source that is a concatenation/insert_subvector then try to access the subvector directly and adjust the element mask accordingly.
2024-01-03 11:09:14 +00:00
Simon Pilgrim
58a335a3f1 [X86] Fold concat_vectors(permq(x),permq(x)) -> permq(concat_vectors(x,x))
Handle a common subvector shuffle pattern in combineConcatVectorOps
2024-01-03 11:09:14 +00:00
Alex Bradbury
80aeb62211
[llvm][NFC] Use SDValue::getConstantOperandVal(i) where possible (#76708)
This helper function shortens examples like
`cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue();` to
`Node->getConstantOperandVal(1);`.

Implemented with:
`git grep -l
"cast<ConstantSDNode>\(.*->getOperand\(.*\)\)->getZExtValue\(\)" | xargs
sed -E -i

's/cast<ConstantSDNode>\((.*)->getOperand\((.*)\)\)->getZExtValue\(\)/\1->getConstantOperandVal(\2)/`
and `git grep -l
"cast<ConstantSDNode>\(.*\.getOperand\(.*\)\)->getZExtValue\(\)" | xargs
sed -E -i

's/cast<ConstantSDNode>\((.*)\.getOperand\((.*)\)\)->getZExtValue\(\)/\1.getConstantOperandVal(\2)/'`.
With a couple of simple manual fixes needed. Result then processed by
`git clang-format`.
2024-01-02 13:14:28 +00:00
Phoebe Wang
a384cd5012
[X86][BF16] Add subvec_zero_lowering patterns (#76507) 2023-12-31 11:14:41 +08:00
Phoebe Wang
e499ae53b3
[X86][BF16] Support INSERT_SUBVECTOR and CONCAT_VECTORS (#76485) 2023-12-28 13:29:01 +08:00
Kazu Hirata
af8d050286 [Target] Use range-based for loops (NFC) 2023-12-24 23:09:55 -08:00
Arthur Eubanks
2366d53d8d
[X86] Fix more medium code model addressing modes (#75641)
By looking at whether a global is large instead of looking at the code
model.

This also fixes references to large data in the small code model.

We now always fold any 32-bit offset into the addressing mode with the
large code model since it uses 64-bit relocations.
2023-12-21 10:40:56 -08:00
Simon Pilgrim
6ec350b483 [X86] SimplifyDemandedVectorEltsForTargetShuffle - don't simplify constant mask if it has multiple uses
Avoid generating extra constant vectors
2023-12-20 15:22:48 +00:00
Simon Pilgrim
3974d89bde [X86] getTargetConstantPoolFromBasePtr - drop const qualifier
Return ConstantPoolSDNode instead of const ConstantPoolSDNode - doesn't affect the accessors at all and makes it easier to use result in calls expecting a SDNode.
2023-12-20 10:40:13 +00:00
Simon Pilgrim
a418be96de [X86] combineLoad - extract target constants at the minimum scalar element width.
No need to extract at the byte level, and will make it easier to reconstruct constants in a future patch.
2023-12-17 13:44:17 +00:00
Simon Pilgrim
fb877c19c0 [X86] combineLoad - don't bother truncating the alternative target constant data. NFC.
We only iterate over the original target constant/undef width, so keep the alternative data in its original form.

This should help if we try to merge constant data in the future.
2023-12-17 11:31:21 +00:00
Arthur Eubanks
b3e353d263
[X86] Don't use rip-relative lea to get a function address in medium static mode (#75656)
This essentially reverts https://reviews.llvm.org/D140593. Somewhere
along the line we properly fixed the medium code model to assume
functions are small, so now we get a 32-bit movl as desired.
2023-12-15 15:15:18 -08:00
Simon Pilgrim
88f1a2c50d [X86] combineLoad - allow constant loads to share matching 'lower constant bits' with larger VBROADCAST_LOAD/SUBV_BROADCAST_LOAD nodes
We already had separate support for VBROADCAST_LOAD - merge this with the generic load handling and add SUBV_BROADCAST_LOAD support as well.
2023-12-14 17:31:07 +00:00
Simon Pilgrim
3c423722cf [X86] combineLoad - improve constant pool matches by ignoring undef elements
When trying to share constant pool entries, we can ignore the undef elements of the entry that is being removed
2023-12-14 15:13:39 +00:00
James Y Knight
ed4194bb8d
[X86] Set MaxAtomicSizeInBitsSupported. (#75112)
This will result in larger atomic operations getting expanded to
`__atomic_*` libcalls via AtomicExpandPass, which matches what Clang
already does in the frontend.
2023-12-12 08:16:55 -05:00
Simon Pilgrim
3be65325f9 [X86] canonicalizeShuffleWithBinOps - generalize to handle some unary ops
Rename to canonicalizeShuffleWithOp and begin adding SHUFFLE(UNARYOP(X),UNARYOP(Y)) -> UNARYOP(SHUFFLE(X,Y)) fold support.

This is only kicking in after legalization, so targets that expand bit counts are still duplicating but it helps with a few initial cases.

I'm investigating adding support for extensions/conversions as well, but this is a first step.
2023-12-12 10:59:38 +00:00
Simon Pilgrim
a7d8d11a14 [X86] combineConcatVectorOps - constant fold vector load concatenation directly into a new load.
Create a new constant pool entry directly instead of going via a BUILD_VECTOR node, which makes constant pool reuse more difficult.

Helps with some regressions in #73509
2023-12-11 16:23:04 +00:00
Simon Pilgrim
7ff2ce9c7b [X86] combineConcatVectorOps - pull out repeated DAG.getContext calls. NFC. 2023-12-11 15:32:07 +00:00
Simon Pilgrim
cb6c093433 [X86] combineConcatVectorOps - pull out repeated getTargetLoweringInfo calls. NFC. 2023-12-08 16:37:28 +00:00
Simon Pilgrim
3894a11acd [X86] combineConcatVectorOps - handle the load combines in the same place
The intention is to merge some of the concat folds of vector constant data to address some of the remaining regressions in #73509
2023-12-08 14:54:50 +00:00
Simon Pilgrim
22fbd07bd7 [X86] combineLoad - consistently use cast<MemSDNode>. NFCI.
getBasePtr()/getMemoryVT() are common methods for all memory nodes.
2023-12-08 12:24:55 +00:00
Simon Pilgrim
5f91335a55 [X86] canonicalizeBitSelect - always use VPTERNLOGD for sub-32bit types
We were using VPTERNLOGQ for everything but i32 types, which made broadcasts wider than necessary

Noticed in #73509
2023-12-08 11:38:32 +00:00
Simon Pilgrim
8859a4f630 [X86] LowerBUILD_VECTOR - don't use insert_element(constant, elt, idx) if we have a freeze(undef) element
Fixes #74736
2023-12-08 10:28:56 +00:00
Simon Pilgrim
80fa79609e [X86] combineStore - add early out for 32-bit f64 store combines. NFC. 2023-12-05 15:39:21 +00:00
Philip Reames
943f3e52a0 [X86] Remove x86-experimental-unordered-atomic-isel option and associated code
This option enables an experimental lowering for unordered atomics I worked
on a few years back.  It never reached production quality, and hasn't been
worked on in years.  So let's rip it out.

This wasn't a crazy idea, but I hit some stumbling block which prevented me
from pushing it across the finish line.  From the look of 027aa27, that
change description is probably a good summary.  I don't remember the
details any longer.
2023-12-04 20:03:38 -08:00
Douglas Yung
c12de14876 Revert "[X86] Canonicalize fp zero vectors from bitcasted integer zero vectors"
This reverts commit 169db80e41936811c6744f2c513a1ed00d97f10e.

This change is causing many test failures on Windows bots:
- https://lab.llvm.org/buildbot/#/builders/235/builds/3616
- https://lab.llvm.org/buildbot/#/builders/233/builds/4883
- https://lab.llvm.org/buildbot/#/builders/216/builds/31174
2023-11-30 11:59:50 -08:00
Simon Pilgrim
169db80e41 [X86] Canonicalize fp zero vectors from bitcasted integer zero vectors
Generic code is supposed to handle this but can be blocked by hasOneUse checks.

Noticed while investigating #26392
2023-11-30 18:33:52 +00:00
Simon Pilgrim
1d20b009a0 [X86] Enable v8f16/v16f16/v32f16 FCOPYSIGN custom lowering on SSE2/AVX/AVX512 targets 2023-11-30 11:48:33 +00:00
Simon Pilgrim
d2856ff457 [X86] Enable v32f16 FNEG custom lowering on AVX512 targets 2023-11-30 10:07:01 +00:00
Simon Pilgrim
8851e411ed [X86] Enable v16f16 FNEG custom lowering on AVX targets 2023-11-30 10:07:01 +00:00
Simon Pilgrim
06b9d92e0e [X86] Enable v8f16 FABS custom lowering on SSE2 targets 2023-11-30 10:07:00 +00:00
Simon Pilgrim
9d4c3e9035 [X86] Enable v8f16 FNEG custom lowering 2023-11-30 10:07:00 +00:00