18841 Commits

Author SHA1 Message Date
Matt Arsenault
cd60bff329 CodeGen: Add some additional is_fpclass lowering tests
Cover more cases in preparation for making greater use
of fcmp based lowerings. Also add more tests for the inverted
cases. Test iszero | isnan test masks. We should probably just
generate every combination of test masks.
2023-03-15 01:13:08 -04:00
Simon Pilgrim
cb47e254e5 [X86] Add test coverage for D137388
Issue #58914 reported an example of the TwoAddressInstruction crash that was fixed (without test case) in D137388
2023-03-14 15:26:39 +00:00
Simon Pilgrim
da570ef1b4 [DAG] Match select(icmp(x,y),sub(x,y),sub(y,x)) -> abd(x,y) patterns
Pulled out of PowerPC, and added ABDS support as well (hence the additional v4i32 PPC matches)

Differential Revision: https://reviews.llvm.org/D144789
2023-03-14 15:10:30 +00:00
Simon Pilgrim
f652bfeba5 [X86] Fix typo in vXi64 ABDS/ABDU test cases
The select operands were commuted preventing D144789 from folding
2023-03-14 14:32:19 +00:00
Nabeel Omer
2ebbcfa07e [X86] Fix encoding for ATOMIC_LOGIC_OP
Fixes PR#61384.

Differential Revision: https://reviews.llvm.org/D145930
2023-03-14 11:39:43 +00:00
Nabeel Omer
d8c2a10297 [X86] Add negative test for D145930
This patch adds a negative test for the issue discovered in D145930.

Differential Revision: https://reviews.llvm.org/D145933
2023-03-14 11:29:38 +00:00
Phoebe Wang
7ff0b9735d [X86] Use llvm::Align for passing the alignment
This should be a typo in `emitConstantSizeRepmov`. Both its caller and
callee store the alignment in a 64-bit variables, no reason to truncate
it to 32-bit. It results in alignment turns into 0 when larger than
0x100000000.

Fixes #61348

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D145863
2023-03-14 00:06:21 +08:00
Felipe de Azevedo Piovezan
6e861d818a [MachineCombiner] Preserve debug instruction number
Each target's `TargetInstrInfo` is responsible for announcing which code
patterns it is able to transform during the MachineCombiner pass.
Currently, these patterns are applied without preserving the debug
instruction number required by the InstrRef implementation of
LiveDebugValues. As such, we've seen a number of examples where debug
information is dropped for variables in InstrRef mode that were
otherwise available in VarLoc mode. This has been observed both in X86
and AArch examples.

This commit is an initial attempt at preserving said numbers by changing
the general (target agnostic) implementation of TargetInstrInfo: the
reassociation pattern must keep the debug number of the "top level"
instruction, i.e., the instruction whose value represents the final
value of the arithmetic expression. Intermediate values must have their
debug number dropped, as they have no equivalent value in the
unoptimized code.

Future work is required to update each target's
`TargetInstrInfo::genAlternativeCodeSequence` method.

Differential Revision: https://reviews.llvm.org/D145759
2023-03-13 09:29:30 -04:00
Phoebe Wang
afdcf219ea [X86] Pre-commit test for #61271 2023-03-13 16:39:08 +08:00
Chen Zheng
4f0ed16a46 Reland rGf35a09daebd0a90daa536432e62a2476f708150d and rG63854f91d3ee1056796a5ef27753648396cac6ec
[DAGCombiner] handle more store value forwarding

When lowering calls on target like PPC, some stack loads
will be generated for by value parameters. Node CALLSEQ_START
prevents such loads from being combined.

Suggested by @RolandF, this patch removes the unnecessary
loads for the byval parameter by extending ForwardStoreValueToDirectLoad

Reviewed By: nemanjai, RolandF

Differential Revision: https://reviews.llvm.org/D138899
2023-03-12 21:59:18 -04:00
Simon Pilgrim
b53ea2b9c5 [DAG] visitAND - fold (and (any_ext V), c) -> (zero_ext (and (trunc V), c)) if profitable.
Try to more aggressively narrow masks of extended values.

This is mainly for cases where the mask is trying to zero out any_extended upper bits, assuming we can zext/trunc the values for free.

This catches a few actual missed folds, as well as helps canonicalize a number of other cases which were being caught in isel etc.

Differential Revision: https://reviews.llvm.org/D145866
2023-03-12 13:25:23 +00:00
Simon Pilgrim
84547ec401 [X86] and-shift.ll - add gnux32 test coverage to ensure the X32 ABI correctly narrows the i64 shifts 2023-03-12 13:11:21 +00:00
Simon Pilgrim
47208f8d34 [X86] matchAddressRecursively - support zext(and(shl(x,c1)),c2) -> shl(zext(and(x, c2 >> c1),c1)
This came about while investigating ways to handle D145468 in a more generic manner, which involves trying harder to fold and(zext(x),c) -> zext(and(x,c))

Alive2: https://alive2.llvm.org/ce/z/7fXtDt (generic fold)

Differential Revision: https://reviews.llvm.org/D145855
2023-03-12 09:49:11 +00:00
Simon Pilgrim
772aa05452 [X86] Add tests showing the failure to merge SHL/ADD through AND masks into LEA 2023-03-11 18:43:49 +00:00
Simon Pilgrim
fad852efe4 [DAG] combineShiftAnd1ToBitTest - improve support for peeking through truncations
Allows us to handle shift amounts that exceed the original bitwidth
2023-03-11 16:37:47 +00:00
Simon Pilgrim
e554cec49a [DAG] Add test showing combineShiftAnd1ToBitTest failing to peek through a truncation 2023-03-11 14:25:47 +00:00
Luo, Yuanke
91f7153965 [X86] Add unwind for base pointer test case. 2023-03-11 11:41:51 +08:00
Luo, Yuanke
b7021a3bed [X86] Add regcall CC test case for base pointer register. 2023-03-11 11:06:27 +08:00
ManuelJBrito
6a02cd45a5 Revert "[X86] Drop single use check for freeze(undef) in LowerAVXCONCAT_VECTORS"
This reverts commit 1a4d0eb866be909fe16da5ebffe4122aa0693d8c.
2023-03-10 22:24:01 +00:00
Rong Xu
ebe09e2a95 [FSAFDO] Improve FS discriminator encoding
This change improves FS discriminators in the following ways:
(1) use call-stack debug information in the the to generate
discriminators: the same (src/line) DILs can now have same
discriminator value if they come from different call-stacks.
This effectively increases the usable discriminator values
for each round of FS discriminator pass.
(2) don't generate the FS discriminator for meta instructions
(i.e. instructions not emitted). This reduces the number
discriminators conflicts (for the case we run out of discriminator
bits for that pass).
(3) use less expensive hashing of xxHash64.

These improvements should bring better performance for FSAFDO
and they should be used by default. But this change creates
incompatible FS discriminators. For the iterative profile users,
they might see a performance drop in the first release with
this change (due to the fact that the profiles have the old
discriminators and the compiler uses the new discriminator).
We have measured that this is not more than 1.5% on several
benchmarks. Note the degradation should be gone in the second
release and one should expect a performance gain over the binary
without this change.

One possible solution to the iterative profile issue would be
separating discriminators for profile-use and the ones emitted to
the binary. This would require a mechanism to allow two sets of
discriminators to be maintained and then phasing out the first
approach. This is too much churn in the compiler and the
performance implications do not seem to be worth the effort.

Instead, we put the changes under an option so iterative profile
users can do a gradual rollout of this change. We will make the
option default value to true in a later patch and eventually
purge this option from the code base.

Differential Revision: https://reviews.llvm.org/D145171
2023-03-09 23:18:48 -08:00
ManuelJBrito
1a4d0eb866 [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/D144903
2023-03-09 14:32:30 +00:00
Simon Pilgrim
8d4998b478 [X86] combineConcatVectorOps - add basic TRUNCATE handling on AVX512 targets
This really should be in shuffle combining, but we're still struggling to handle mismatched vector sizes
2023-03-09 12:32:20 +00:00
Simon Pilgrim
faea1c5ccc [X86] Add test case showing failure to fold concat_v32i8(trunc_v16i16(x),trunc_v16i16(y)) -> trunc_v32i16(concat_v16i16(x,y))
We have similar tests but nothing that should only fold on BWI targets
2023-03-09 12:10:51 +00:00
ManuelJBrito
85e6617b60 Revert "[X86] Drop single use check for freeze(undef) in LowerAVXCONCAT_VECTORS"
This reverts commit e2817933fdd4417673eb7f96a2842ae2dca8fc59.
2023-03-09 11:56:08 +00:00
Simon Pilgrim
da92c120ca [X86] combineConcatVectorOps - add ADD/SUB/MUL handling 2023-03-09 11:19:07 +00:00
ManuelJBrito
e2817933fd [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/D144903
2023-03-09 11:01:09 +00:00
Simon Pilgrim
95bc01dbec [X86] Regenerate memset-vs-memset-inline.ll
Check we write to the entire memory span of the inlined memset

Simplifies future update_llc_test_checks regenerations
2023-03-08 21:00:38 +00:00
Noah Goldstein
8ac8c579e2 [X86] Add masked predicate execution variants for instructions in X86FixupInstTuning
Masked variants of UNPCKLPD, UNPCKHPD, and PERMILPS were missing and
be transformed with the same logic as their non-masked counterparts.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D144763
2023-03-08 11:57:41 -06:00
Noah Goldstein
6b29a6f27d [X86] Add support for using Sched/Codesize information to X86FixupInstTuning Pass.
Use this to handle new transform: `{v}unpck{l|h}pd` -> `{v}shufps`. We
need the sched information here as `{v}shufps` is 1 more byte of code
size, so we only want to make this transformation if `{v}shufps` is
actually faster.

Differential Revision: https://reviews.llvm.org/D144570
2023-03-08 11:57:38 -06:00
Noah Goldstein
6dbf894b80 [X86] Add ICX target in unpckpd tuning tests; NFC
Differential Revision: https://reviews.llvm.org/D145531
2023-03-08 11:57:31 -06:00
Simon Pilgrim
a6dd2ce375 [X86] umax.ll - remove unused arguments. NFC. 2023-03-08 15:01:16 +00:00
Chen Zheng
fc26ab36a2 [DAGCombiner] don't use the pointer info for widen store
The merged store touches memory for other underlying objects, so mapping
the merged store to the first underlying object is not correct. For example
in https://github.com/llvm/llvm-project/issues/60744, the merged store is
not correctly analyzed as dependent with memory operations which are also
part of the merged store.

Fixes #60744

Reviewed By: foad

Differential Revision: https://reviews.llvm.org/D144711
2023-03-07 20:31:09 -05:00
Chen Zheng
a8c630ea5b [DAGCombiner] add testcase for issue #60744; NFC 2023-03-07 20:31:01 -05:00
Simon Pilgrim
7709480219 [X86] Lower vector umax(x,1) -> sub(x,cmpeq(x,0))
With suitable BooleanContent handling we could move this to TargetLowering::expandIntMINMAX, but this is good enough for X86

Fixes #61225
2023-03-07 15:38:53 +00:00
Simon Pilgrim
f04a859e41 [X86] Add umax(x,1) vector test coverage for Issue #61225 2023-03-07 14:34:03 +00:00
Kazu Hirata
3a0d5d846a [X86] Precommit a test
This patch precommits a test for:

https://github.com/llvm/llvm-project/issues/61073
2023-03-06 19:45:34 -08:00
Noah Goldstein
c1ecd0a3f4 [DAGCombiner] Add fold for ~x + x -> -1
This is generally done by the InstCombine, but can be emitted as an
intermediate step and is cheap to handle.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D145177
2023-03-06 20:30:27 -06:00
Noah Goldstein
d4b24b4a55 [DAGCombiner] Add fold for ~x & x -> 0
This is generally done by the InstCombine, but can be emitted as an
intermediate step and is cheap to handle.

Differential Revision: https://reviews.llvm.org/D145143
2023-03-06 20:30:20 -06:00
Noah Goldstein
c622c1383a [X86] Add test for ~x & x -> 0 and ~x + x -> -1 in DAG Lowering; NFC
Differential Revision: https://reviews.llvm.org/D145142
2023-03-06 20:30:09 -06:00
Simon Pilgrim
e0cd60f1d5 [X86] combineBitcastvxi1/checkBitcastSrcVectorSize - sign-extend select(i1,vXi1,vXi1) patterns
Fixes #61104
2023-03-06 18:22:42 +00:00
Kazu Hirata
a21a7ddf5a [X86] Optimize umax(X,1) (NFC)
Without this patch:

  %cond = call i32 @llvm.umax.i32(i32 %X, i32 1)

is compiled as:

  83 ff 02                   cmp    $0x2,%edi
  b8 01 00 00 00             mov    $0x1,%eax
  0f 43 c7                   cmovae %edi,%eax

With this patch, the compiler generates:

  89 f8                      mov    %edi,%eax
  83 ff 01                   cmp    $0x1,%edi
  83 d0 00                   adc    $0x0,%eax

saving 3 bytes.  We should be able to save 5 bytes in larger functions
where the mov is unnecessary.

This patch converts the specific cmov pattern to cmp $1 followed by
adc $0.

This patch partially fixes:

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

The LLVM IR optimizer is yet to canonicalize max expressions to
actual @llvm.umax.

Differential Revision: https://reviews.llvm.org/D144451
2023-03-06 10:18:57 -08:00
Simon Pilgrim
0e2b967282 [X86] Add Issue #61104 test case
Shows the failure of combineBitcastvxi1 to sign-extend a select(i1,vXi1,vXi1) pattern
2023-03-06 18:00:35 +00:00
Marco Elver
bdb4353ae0 [SelectionDAG] Optimize copyExtraInfo deep copy
It turns out that there are relatively trivial, albeit rare, cases that
require a MaxDepth of more than 16 (see added test). However, we want to
avoid having to rely on a large fixed MaxDepth.

Since these cases are relatively rare, apply the following strategy:

  1. Start with a low MaxDepth of 16 - if the entry node was not
     reached, we can return (the common case).

  2. If the entry node was reached, exponentially increase MaxDepth up
     to some large limit that should cover all cases and guard against
     stack exhaustion.

This retains the better performance with a low MaxDepth in the common
case, and in complex cases backs off and retries. On a whole, this is
preferable vs. starting with a large MaxDepth which would unnecessarily
penalize the common case where a low MaxDepth is sufficient.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D145386
2023-03-06 17:29:53 +01:00
Simon Pilgrim
7b54a29c2e [X86] combineBitcastvxi1/checkBitcastSrcVectorSize - sign-extend vXi1 allones vselect operands
Minor fix to Issue #61104
2023-03-06 16:14:05 +00:00
Simon Pilgrim
6103147fb4 [X86] Add Issue #61104 test case
Shows the failure of combineBitcastvxi1 to sign-extend a vXi1 allones vselect operand

There's a number of other problems in Issue #61104 still to address, but this one has an easy quick fix
2023-03-06 16:14:05 +00:00
Simon Pilgrim
5c2716b87a [X86] vector-shuffle-avx512.ll - update to use attributes instead of hard coded cpu targets
Similar to most of the other vector-shuffle-* test files

Avoids some codegen deltas due to upcoming changes for no-costs domain switching between shuffle types
2023-03-06 14:50:28 +00:00
Kazu Hirata
e7d591c7c5 [X86] Precommit tests
This patch precommits more tests for:

https://github.com/llvm/llvm-project/issues/60802
2023-03-05 00:48:53 -08:00
Kazu Hirata
ccc849e0b1 [X86] Add non-BMI tests to bit_ceil.ll 2023-03-04 12:20:04 -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
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