47204 Commits

Author SHA1 Message Date
Amara Emerson
1e1f1195a8 [AArch64] Fix crash in LowerBUILD_VECTOR trying to create invalid EXTRACT_SUBVECTOR.
rdar://106096671

Differential Revision: https://reviews.llvm.org/D145185
2023-03-02 14:10:29 -08:00
Marco Elver
f693932fbe [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.

v2: Optimize copyExtraInfo() deep copy. For now we assume that only
NodeExtraInfo that have PCSections set require deep copy. Furthermore,
limit the depth of graph search while pre-populating the visited set,
assuming the to-be-replaced subgraph 'From' has limited complexity. An
assertion catches if the maximum depth needs to be increased.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D144677
2023-03-02 23:07:19 +01:00
Craig Topper
06c6b787b2 [SelectionDAG][AArch64] Constant fold in SelectionDAG::getVScale if VScaleMin==VScaleMax.
Reviewed By: paulwalker-arm

Differential Revision: https://reviews.llvm.org/D145113
2023-03-02 12:02:38 -08:00
Craig Topper
c546f13f1f [DAGCombiner] Replace LegalOperations check in visitSIGN_EXTEND with LegalTypes.
This is guarding a check for isTypeLegal so it should check is
LegalTypes.

Fixes PR61111.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D145139
2023-03-02 07:52:53 -08:00
Sander de Smalen
948ed21f12 [AArch64] NFC: Add missing CHECK lines for sme-aarch64-svcount.ll test 2023-03-02 12:42:09 +00:00
Petar Avramovic
c77bd1fe15 AMDGPU: Add more flat scratch load and store tests for 8 and 16-bit types
Add tests for more complicated scratch load and store patterns.
Includes:
- sign and zero extending loads of i8 and i16 to i32 into 32-bit register
- D16 instructions that affect only high or low 16 bits of 32-bit register
 - D16 sign and zero extending loads of i8 to i16 into high or low 16 bits
   of 32-bit register
 - D16 loads of i16 to high or low 16 bits of 32-bit register
 - D16 stores of i8 and i16 from high 16 bits of 32-bit register

Differential Revision: https://reviews.llvm.org/D145081
2023-03-02 13:20:14 +01:00
Sander de Smalen
170e7a0ec2 [AArch64][SME2] Add CodeGen support for target("aarch64.svcount").
This patch adds AArch64 CodeGen support such that the type can be passed
and returned to/from functions, and also adds support to use this type in
load/store operations and PHI nodes.

Reviewed By: paulwalker-arm

Differential Revision: https://reviews.llvm.org/D136862
2023-03-02 12:07:41 +00:00
Noah Goldstein
5705dc7606 Recommit "[X86] Add TuningPreferShiftShuffle for when Shifts are preferable to shuffles." (2nd Try)
Move the opcode checks to after we have already verified we found a
valid shift instruction (`0 < ShiftAmt`) in `matchUnaryPermuteShuffle`
and `lowerShuffleAsShift`.

Reviewed By: pengfei, RKSimon

Differential Revision: https://reviews.llvm.org/D143786
2023-03-02 02:53:37 -06:00
Marco Elver
e0bc779000 Revert "[SelectionDAG] Transitively copy NodeExtraInfo on RAUW"
This reverts commit 7f635b90e7bdf1378fd9a65fc62b99e8e07d4aaf.

The current implementation causes pathological slowdowns in certain
cases: https://github.com/llvm/llvm-project/issues/61108
2023-03-02 09:39:44 +01:00
Kazu Hirata
26b3e096fb [x86] Precommit a test
This patch precommits a test for:

https://github.com/llvm/llvm-project/issues/60802
2023-03-01 23:03:39 -08:00
Fangrui Song
52ced14098 Revert D143786 "[X86] Add TuningPreferShiftShuffle for when Shifts are preferable to shuffles."
This reverts commit a98ee27416916c3f8af4cd229e0a633423d6d9a3.
It caused MemorySanitizer use-of-uninitialized-value in matchUnaryPermuteShuffle.
2023-03-01 19:08:55 -08:00
Jun Ma
403926aefe [WebAssembly] Skip implied bitmask operation in LowerShift
This patch skips redundant explicit masks of the shift count since
it is implied inside wasm shift instruction.

Differential Revision: https://reviews.llvm.org/D144619
2023-03-02 09:37:25 +08:00
Nick Desaulniers
9cec2b246e [RegAllocFast] insert additional spills along indirect edges of INLINEASM_BR
When generating spills (stores) for values produced by INLINEASM_BR
instructions, make sure to insert one spill per indirect target.
Otherwise the reload generated may load from a stack slot that has not
yet been stored to (resulting in a load of an uninitialized stack slot).

Link: https://github.com/llvm/llvm-project/issues/53562
Fixes: https://github.com/llvm/llvm-project/issues/60855

Reviewed By: MatzeB

Differential Revision: https://reviews.llvm.org/D144907
2023-03-01 15:21:11 -08:00
Nick Desaulniers
b8f9ec6db7 precommit test for pr60855
This test demonstrates an issue with callbr outputs being used along
indirect edges when using regallocfast.

Link: https://github.com/llvm/llvm-project/issues/60855

Differential Revision: https://reviews.llvm.org/D144906
2023-03-01 15:21:11 -08:00
Leonard Chan
fa6aadd6cb [llvm] Prevent building for riscv32-unknown-fuchsia
Fuchsia is exclusively 64-bit so this throw an error when using this
triple.

Differential Revision: https://reviews.llvm.org/D144998
2023-03-01 19:42:56 +00:00
Simon Pilgrim
73cdccad55 [DAG] expandIntMINMAX - attempt to match existing SETCC node
As noticed on D144789, when we have pairs of min/max nodes we often end up with multiple comparisons which we could reuse with commuted select ops, so check to see if a suitable SETCC already exists. This also allowed us to remove a similar X86 peephole.

There are other getSETCC cases where we could safely reuse other CondCodes as well - I've been trying to think of how we could reuse this logic in SelectionDAG but haven't found anything that always works well.

An alternative would be to have a TLI callback that returns a preferred CondCode from a list of options, I've noticed this helped fpclamptosat tests on some other targets (MVE + WebAssembly), but other tests suffered.

Differential Revision: https://reviews.llvm.org/D145065
2023-03-01 19:04:03 +00:00
Anshil Gandhi
7474cd3e2e [SIAnnotateControlFlow] Use Uniformity analysis
Reviewed By: foad

Differential Revision: https://reviews.llvm.org/D145013
2023-03-01 10:19:45 -07:00
Anshil Gandhi
1b52c7be91 [AMDGPUUnifyDivergentExitNodes] Use Uniformity Analysis
Reviewed By: foad

Differential Revision: https://reviews.llvm.org/D145018
2023-03-01 10:17:11 -07:00
David Green
337215ddf9 [DAG] ABD is not reassociative
I'm not sure how I missed this in the testing, but as far as I understand
whilst ABDS and ABDU are commutive they are not associative. This patch
disables reassociateOps from visitABD, fixing the problems found in #61069.
ABDU: https://alive2.llvm.org/ce/z/eiT5QG
ABDS: https://alive2.llvm.org/ce/z/HzE29l

Differential Revision: https://reviews.llvm.org/D145064
2023-03-01 16:22:13 +00:00
Jirui Wu
3b742242a5 [ARM] Remove a redundant function fixupBTI
Since the redundant BTI instructions emitted by jump tables are now
removed in the ARMBranchTargets pass, the fixupBTI function is not needed
in the ARMConstantIslandPass. Some related tests are removed as well.

The relevant patch that removes the redundant BTI instructions:
https://reviews.llvm.org/D144470

Differential Revision: https://reviews.llvm.org/D145048
2023-03-01 15:01:38 +00:00
Nikita Popov
ddccc5ba44 [CodeGen] Always expand division larger than i128
Default MaxDivRemBitWidthSupported to 128, so that divisions larger
than 128 bits are always expanded, without requiring additional
configuration from the target.

Note that this may still emit calls to __udivti3 on 32-bit targets,
which likely don't have an implementation of that builtin. However,
I believe this is sufficient to fix
https://github.com/llvm/llvm-project/issues/60531, because Zig must
already be defining those builtins.

Differential Revision: https://reviews.llvm.org/D144871
2023-03-01 15:33:45 +01:00
David Green
83bbd3fdbd [AArch64] Load into zero vector patterns
A LDR will implicitly zero the rest of the vector, so vector_insert(zeros,
load, 0) can use a single load. This adds tablegen patterns for both scaled and
unscaled loads, detecting where we are inserting a load into the lower element
of a zero vector.

Differential Revision: https://reviews.llvm.org/D144086
2023-03-01 13:54:03 +00:00
Sjoerd Meijer
2b462eb98d [AArch64] More patterns to generate LD1R vector splats
We are missing patterns to generate vector splats using LD1R. A shuffle vector
with all 0s is a vector splat if the operands are a load and undef for which
we can generate a LD1R.

Differential Revision: https://reviews.llvm.org/D145004
2023-03-01 10:48:13 +00:00
Sjoerd Meijer
a4c828a9e2 [AArch64] Precommit tests to check more ld1r vector splat patterns in D145004. 2023-03-01 10:48:13 +00:00
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