47180 Commits

Author SHA1 Message Date
David Green
18af853022 [AArch64] Remove 64bit->128bit vector insert lowering
The AArch64 backend, during lowering, will convert an 64bit vector insert to a
128bit vector:

vector_insert %dreg, %v, %idx
=>
%qreg = insert_subvector undef, %dreg, 0
%ins = vector_insert %qreg, %v, %idx
EXTRACT_SUBREG %ins, dsub

This creates a bit of mess in the DAG, and the EXTRACT_SUBREG being a machine
nodes makes it difficult to simplify. This patch removes that, treating the
64bit vector insert as legal and handling them with extra tablegen patterns.

The end result is a simpler DAG that is easier to write tablegen patterns for.

Differential Revision: https://reviews.llvm.org/D144550
2023-03-01 09:39:51 +00:00
Zhongyunde
15d5c59280 [InstCombine] Improvement the analytics through the dominating condition
Address the dominating condition, the urem fold is benefit from the analytics improvements.
Fix https://github.com/llvm/llvm-project/issues/60546

NOTE: delete the calls in simplifyBinaryIntrinsic and foldICmpWithDominatingICmp
is used to reduce compile time.

Reviewed By: nikic, arsenm, erikdesjardins
Differential Revision: https://reviews.llvm.org/D144248
2023-03-01 17:03:34 +08:00
Caroline Concatto
cb96eba27c [IR][Legalization] Split illegal deinterleave and interleave vectors
To make legalization easier, the operands and outputs have the same size for
these ISD Nodes. When legalizing the results in SplitVectorResult the operands
are legalized to the same size as the outputs.
The ISD Node has two output/results, therefore the legalizing functions update
both results/outputs.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D144744
2023-03-01 08:30:16 +00:00
Noah Goldstein
a98ee27416 [X86] Add TuningPreferShiftShuffle for when Shifts are preferable to shuffles.
SKX has an objectively faster shift than shuffle, on all other targets
the two have equal performance (with maybe a slight preference for
shifts because p5 is a more common bottleneck).

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D143786
2023-02-28 23:25:20 -06:00
Noah Goldstein
05ca9ebc04 [X86] Make (shift X (xor/sub N-1, Y)) -> (shift X, (not Y)) check for one use.
`(xor/sub N-1, Y)` -> `(not Y)` is minorly preferable (especially for
`(sub N-1, Y)` where it saves an instruction), but isn't worth
potentially creating an extra instruction for.

So, only do the transformation if `(xor/sub N-1, Y)` has one use.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D144985
2023-02-28 23:25:16 -06:00
Noah Goldstein
4a23031fac [X86] Fix (shift X, (xor Y, N-1)) -> (shift X, (not Y)) by properly inserting not Y into DAG. [#61038]
Previously not inserting the `-1` in `not Y` (`xor Y, -1`) into the
DAG. Not inserting `-1` as a DAG node comes up as a bug when doing
`(xor (shl 1, A), B)` -> `(btc A, B)`. `btc` requires `B` (dst) to be
a register.

Differential Revision: https://reviews.llvm.org/D144984
2023-02-28 23:25:09 -06:00
Kazu Hirata
1e552d0c5b [X86] Improve select of constants
Without this patch:

  %cmp = icmp eq i32 %a, %b
  %cond = select i1 %cmp, i32 1, i32 2

is compiled as:

  31 c9                      xor    %ecx,%ecx
  39 f7                      cmp    %esi,%edi
  0f 94 c1                   sete   %cl
  b8 02 00 00 00             mov    $0x2,%eax
  29 c8                      sub    %ecx,%eax

With this patch, the compiler generates:

  31 c0                      xor    %eax,%eax
  39 f7                      cmp    %esi,%edi
  0f 95 c0                   setne  %al
  ff c0                      inc    %eax

saving 5 bytes while reducing register usage.

This patch transforms C - setcc into inverted_setcc + (C-1) if C is a
nonzero constant.

This patch fixes:

https://github.com/llvm/llvm-project/issues/60854

Differential Revision: https://reviews.llvm.org/D144449
2023-02-28 14:58:22 -08:00
ManuelJBrito
ece0b96979 Revert "[X86] Drop single use check for freeze(undef) in LowerAVXCONCAT_VECTORS"
This reverts commit 9e58182d6446bb61dbd13c0e6314f291e50d4d7c.
2023-02-28 21:50:36 +00:00
ManuelJBrito
9e58182d64 [X86] Drop single use check for freeze(undef) in LowerAVXCONCAT_VECTORS
Ignoring freeze(undef) if it has multiple uses in LowerAVXCONCAT_VECTORS
causes the custom INSERT_SUBVECTOR for vector widening to be ignored.

Differential Revision: https://reviews.llvm.org/D14490
2023-02-28 21:39:10 +00:00
Anshil Gandhi
a78301560d [AMDGPU] Replace LegacyDA with Uniformity Analysis in AnnotateUniformValues
Reviewed By: sameerds

Differential Revision: https://reviews.llvm.org/D144162
2023-02-28 13:05:38 -07:00
David Sherwood
6333779ac0 [AArch64][SME2] Add multi-vector uunpk and sunpk intrinsics
This patch adds the LLVM IR intrinsics for the following:

* uunpk (2 and 4 vectors)
* sunpk (2 and 4 vectors)

I have named the tests sve2p1-intrinsics-* because although
the instructions are added as part of the SME2 feature they
only operate on SVE vectors.

NOTE: These intrinsics are still in development and are subject to future changes.

Differential Revision: https://reviews.llvm.org/D142964
2023-02-28 14:01:38 +00:00
LiaoChunyu
fbace95408 [RISCV] Enable preferZeroCompareBranch to optimize branch on zero in codegenprepare
Similar to ARM and SystemZ.

Related Patchs: D101778(preferZeroCompareBranch)
https://reviews.llvm.org/rG9a9421a461166482465e786a46f8cced63cd2e9f   ( == 0 to u< 1)

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D142071
2023-02-28 14:43:40 +08:00
Ben Shi
30d8f4e843 [AVR] Fix incorrect flags of livein registers when spilling them
In AVRFrameLowering::spillCalleeSavedRegisters(), when a 16-bit
livein register is spilled, two PUSH instructions are generated
for the higher and lower 8-bit registers. But these two 8-bit
registers are marked as killed in the two PUSH instructions, so
any future use of them will cause a crash.

This patch fixes the above issue by adding the two sub 8-bit
registers to the livein list.

Fixes https://github.com/llvm/llvm-project/issues/56423

Reviewed By: jacquesguan

Differential Revision: https://reviews.llvm.org/D144720
2023-02-28 11:08:54 +08:00
Arthur Eubanks
773d663e47 [IPO] Remove various legacy passes
These are part of the optimization pipeline, of which the legacy pass manager version is deprecated and being removed.
2023-02-27 19:06:08 -08:00
Theodoros Kasampalis
2e0940c6a0 [X86] Fix for offsets of CFA directives
`emitPrologue` may insert stack pointer adjustment in tail call optimized functions where the callee argument stack size is bigger than the caller's. In such a case, the adjustment must be taken into account when generating CFA directives.

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D143618
2023-02-28 10:30:06 +08:00
Noah Goldstein
6957a8cc6c Add tests for replacing {v}unpck{l|h}pd -> {v}shufps; NFC
Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D144442
2023-02-27 18:53:25 -06:00
Noah Goldstein
69a322fed1 Add new pass X86FixupInstTuning for fixing up machine-instruction selection.
There are a variety of cases where we want more control over the exact
instruction emitted. This commit creates a new pass to fixup
instructions after the DAG has been lowered. The pass is only meant to
replace instructions that are guranteed to be interchangable, not to
do analysis for special cases.

Handling these instruction changes in in X86ISelLowering of
X86ISelDAGToDAG isn't ideal, as its liable to either break existing
patterns that expected a certain instruction or generate infinite
loops.

As well, operating as the MachineInstruction level allows us to access
scheduling/code size information for making the decisions.

Currently only implements `{v}permilps` -> `{v}shufps/{v}shufd` but
more transforms can be added.

Differential Revision: https://reviews.llvm.org/D143787
2023-02-27 18:53:25 -06:00
Noah Goldstein
e56ddae849 Add tests for replacing {v}permilps -> {v}shufps/{v}pshufd; NFC
Differential Revision: https://reviews.llvm.org/D144779
2023-02-27 18:53:25 -06:00
Vladislav Dzhidzhoev
3a51eed948 [AArch64][GlobalISel] Legalize G_SHUFFLE_VECTOR with smaller dest size
Legalize G_SHUFFLE_VECTOR having destination vector length smaller than
source vector length by reshaping destination vector.

Differential Revision: https://reviews.llvm.org/D144670
2023-02-27 23:46:44 +01:00
Michal Paszkowski
5ac69674bf [SPIR-V] Support TargetExtType for SPIR-V builtin types
This patch adds support for TargetExtType/target(...) representing
SPIR-V builtin types. After D135202, target(...) is the preferred way
for representing SPIR-V builtin types in LLVM IR and the only working
in the opaque pointer mode.

In order to maintain compatibility with LLVM IR generated by older
versions of Clang and LLVM/SPIR-V Translator, pointers-to-opaque-structs
denoting SPIR-V/OpenCL builtin types will be translated to equivalent
SPIR-V target extension types. This translation is only available in the
typed pointer mode (-opaque-pointers=0).

The relevant LIT tests with SPIR-V builtins were converted to use the
new target(...) notation.

Differential Revision: https://reviews.llvm.org/D144494
2023-02-27 21:39:25 +01:00
Nilanjana Basu
72105d10d5 [AArch64] Avoid using intermediate integer registers for copying between source and destination floating point registers
In post-isel code, there are cases where there were redundant copies from a source FPR to an intermediate GPR in order to copy to a destination FPR. In this patch, we identify these patterns in post-isel peephole optimization and replace them with a direct FPR-to-FPR copy.
One example for this will be the insertion of the scalar result of 'uaddlv' neon intrinsic function into a destination vector. During instruction selection phase, 'uaddlv' result is copied to a GPR, & a vector insert instruction is matched separately to copy the previous result to a destination SIMD&FP register.

Reviewed By: dmgreen

Differential Revision: https://reviews.llvm.org/D142594
2023-02-27 12:20:10 -08:00
Amara Emerson
31d6a57257 [AArch64][GlobalISel] Reorder stack up-adjustment and register copies
This change reorders the stack up-adjustment and return value copying phases of
machine-ir generation on Aarch64. Doing so prevents a bug observed for fastcc
calls with >8 arguments, where the up-adjustment required from making that call
is placed in the wrong place relative to spill and reloading code.

See: https://github.com/llvm/llvm-project/issues/60972 for full issue
reproduction and context.

Patch contributed by Bruce Collie

Differential Revision: https://reviews.llvm.org/D144791
2023-02-27 11:24:24 -08:00
David Green
06daa515b2 [AArch64] Don't remove free sext_inreg(vector_extract(x)) if it leads to multiple extracts
If we have sext_inreg(vector_extract(x)) but the top bits are not used, DAG
will try to remove the sext_inreg, using vector_extract(x) directly. This can
lead to multiple uses of both sext_inreg(vector_extract(x)) and
vector_extract(x), leading to the generation of both umov and smov extracts.
This adds a target hook to prevent that under AArch64 where the sext_inreg can
be considered free if there are multiple uses of the sext and no uses of the
vector_extract. This helps fix a small regression from D144550.

Differential Revision: https://reviews.llvm.org/D144850
2023-02-27 19:20:10 +00:00
zhongyunde
d514726d31 [AMDGPU] Update the CHECK autogenerated as it's expired
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D144771
2023-02-28 02:01:25 +08:00
David Green
9e5bfa1ae3 [AArch64] Add some tests for multiple uses of extended vector extracts. NFC 2023-02-27 14:34:52 +00:00
Pavel Kosov
c417b7a695 [OHOS] Add support for OpenHarmony
Add support for OpenHarmony OS

General OpenHarmony OS discussion on discourse thread "[RFC] Add support for OpenHarmony OS"
https://discourse.llvm.org/t/rfc-add-support-for-openharmony-os/66656

Reviewed By: DavidSpickett

Differential Revision: https://reviews.llvm.org/D138202
2023-02-27 17:15:45 +03:00
Kerry McLaughlin
a9df627050 [SME2][AArch64] Add multi-indexed multiply-add long long intrinsics
Adds intrinsics for the following SME2 instructions (1, 2 & 4 vector):
 - smlall
 - umlall
 - smlsll
 - umlsll
 - sumlall
 - usmlall

NOTE: These intrinsics are still in development and are subject to future changes.

Reviewed By: david-arm

Differential Revision: https://reviews.llvm.org/D143278
2023-02-27 13:58:35 +00:00
Marco Elver
7f635b90e7 [SelectionDAG] Transitively copy NodeExtraInfo on RAUW
During legalization of the SelectionDAG, some nodes are replaced with
arch-specific nodes. These may be complex nodes, where the root node no
longer corresponds to the node that should carry the extra info.

Fix the issue by copying extra info to the new node and all its new
transitive operands during RAUW. See code comments for more details.

This fixes the remaining pcsections-atomics.ll tests on X86.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D144677
2023-02-27 12:16:14 +01:00
Marco Elver
d73da86812 [X86][FixupBWInsts] Fix propagation of !pcsections metadata
Use MIMetadata() to propagate both DebugLoc and !pcsections metadata.

This fixes several of the non-native sized !pcsections tests in
pcsections-atomics.ll.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D144676
2023-02-27 12:16:14 +01:00
Marco Elver
a5653b82d0 [X86] Improve atomics test for !pcsections
Extend pcsections-atomics.ll to exhaustively test all atomic ops up to
64 bits. This currently shows that some atomic operations do not end up
in PC sections. This will be addressed in a subsequent change.

Differential Revision: https://reviews.llvm.org/D144710
2023-02-27 12:16:13 +01:00
Marco Elver
ba63ddd595 [X86] Move atomics test for !pcsections into separate file
The pcsections.ll test primarily tests that the AsmPrinter produces the
right output in sections. This output is not easily covered by
update_llc_test_checks.py, and as such is hand written. This makes
maintenance rather burdensome. Instead, let's keep pcsections.ll as
simple as possible.

Move the more complex tests that primarily test that some atomic
operations end up in the PC section to pcsections-atomics.ll.

NFC.

Reviewed By: dvyukov, vitalybuka

Differential Revision: https://reviews.llvm.org/D144675
2023-02-27 12:16:13 +01:00
chendewen
ec67d703cf [SVE] Add intrinsics for uniform dsp operations that explicitly undefine the result for inactive lanes.
This patch adds new intrinsics for uniform dsp operations and changes the lowering for the following builtins to emit calls to the new aarch64.sve.###.u intrinsics.
  svsqsub_x
  svsqsub_n_x
  svuqsub_x
  svuqsub_n_x
  svsqsubr_x
  svsqsubr_n_x
  svuqsubr_x
  svuqsubr_n_x

Reviewed By: Paul Walker
Differential Revision: https://reviews.llvm.org/D144704
2023-02-27 18:44:55 +08:00
Diana Picus
44f1cb04e5 [AMDGPU] Run update scripts on existing tests. NFC
Update a few tests where the checks aren't exactly kosher.

Differential Revision: https://reviews.llvm.org/D144639
2023-02-27 09:48:57 +01:00
Nilanjana Basu
f3b8aef242 [AArch64] Added tests for inserting scalar result of uaddlv neon instrinsic function into a vector
Inserting scalar result of 'uaddlv' neon intrinsic function to a destination vector currently makes use of the integer unit. Subsequent patches will eliminate the redundant use of the integer registers in a more generic way that will include this special case. This is an initial set of tests for this functionality.

Differential Revision: https://reviews.llvm.org/D143038
2023-02-26 22:54:09 -08:00
Amara Emerson
4bc6434624 [GlobalISel] Fix an assertion failure in matchHoistLogicOpWithSameOpcodeHands().
We use this combine in the AArch64 postlegalizer combiner, which causes this
function to query the legalizer rules for the action for an invalid opcode/type
combination (G_AND and p0). Moving the legalizer query until after the validity
check in matchHoistLogicOpWithSameOpcodeHands() fixes this.
2023-02-26 15:42:57 -08:00
Alex Bradbury
1ae859753c [WebAssembly][test] Clean up ir-locals.ll after opaque pointer conversion
The `tyname_cell` definitions at the top are now all the same, so
replace them with a single `alloca_cell` type.
2023-02-26 19:17:06 +00:00
Alex Bradbury
771261ff01 [Webassembly][test] Regenerate ir-locals.ll using update_llc_test_checks.py
Preparation for further additions.
2023-02-26 19:12:36 +00:00
Noah Goldstein
b5fc2a474e Add additional operations that masked instructions can combine with
Added: OR, SMAX, SMIN, UMAX, UMIN, ABS, SHL, SRL, SRA, MUL

Intentionally not generically using TLI.isBinOp as that causes
regressions as there are many binops that cannot combine with masked
instructions.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D143860
2023-02-26 12:11:16 -06:00
Noah Goldstein
d821ac1aaf Add tests for combining mask with shuffles; NFC
Differential Revision: https://reviews.llvm.org/D144144
2023-02-26 12:11:16 -06:00
Noah Goldstein
6b6c62c75b Widen i16 shuffle masks if vector width < 512 even with BWI
`{v}blend{d|ps|pd}` is preferable to `{v}blendw` so widen so that we
can match it.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D143789
2023-02-26 12:11:16 -06:00
Noah Goldstein
7ae071f981 Add more tests for promoting blendw -> blendd; NFC
Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D143788
2023-02-26 12:11:16 -06:00
Simon Pilgrim
d91c20a0de [X86] Add additional uses tests for select(icmp(x,y),sub(x,y),sub(y,x)) -> abd(x,y) patterns 2023-02-26 18:01:05 +00:00
Simon Pilgrim
561d9cd6f4 [X86] Add vector test coverage for select(icmp(x,y),sub(x,y),sub(y,x)) -> abd(x,y) patterns 2023-02-26 17:05:46 +00:00
Simon Pilgrim
f69a0d0db6 [X86] Add scalar test coverage for select(icmp(x,y),sub(x,y),sub(y,x)) -> abd(x,y) patterns 2023-02-26 16:45:18 +00:00
Simon Pilgrim
96aa76aa71 [X86] Add test showing poor bitselect between constants on BMI targets
bitselect(52,-6553,m) -> xor(and(xor(52,-6553),m),52) folds much better than or(and(52,not(m)),and(-6553,m))
2023-02-26 15:32:04 +00:00
Simon Pilgrim
025952b00e [X86] Add PR46472 bitselect test coverage
As noted on Issue #45817 we didn't have scalar coverage for this
2023-02-26 15:19:53 +00:00
Simon Pilgrim
bbaa794704 [X86] Add i686 and fast/slow-inc test coverage to constant select tests
Extend tests for D144449 to ensure we aren't regressing code on targets with a slow INC/DEC instruction (or i686 without CMOV)
2023-02-26 14:00:22 +00:00
Kazu Hirata
86bd9c9841 [X86] Precommit a test
This patch precommits a test for:

https://github.com/llvm/llvm-project/issues/60374
2023-02-25 23:33:50 -08:00
Simon Pilgrim
7ebf9b0ca3 [AArch64] Add coverage for select(icmp(x,y),sub(x,y),sub(y,x)) -> abd(x,y) patterns 2023-02-25 21:12:32 +00:00
Simon Pilgrim
448d896519 [PowerPC] Add coverage for select(icmp_sgt(x,y),sub(x,y),sub(y,x)) -> abds(x,y) patterns 2023-02-25 21:04:16 +00:00