19270 Commits

Author SHA1 Message Date
Simon Pilgrim
e9caa37e9c [DAG] Move lshr narrowing from visitANDLike to SimplifyDemandedBits
Inspired by some of the cases from D145468

Let SimplifyDemandedBits handle the narrowing of lshr to half-width if we don't require the upper bits, the narrowed shift is profitable and the zext/trunc are free.

A future patch will propose the equivalent shl narrowing combine.

Differential Revision: https://reviews.llvm.org/D146121
2023-07-17 15:50:09 +01:00
Amaury Séchet
a23d6c760c [NFC] Add test case for D154533. 2023-07-17 14:19:15 +00:00
Simon Pilgrim
fd2de54920 [X86] Canonicalize vXi64 SIGN_EXTEND_INREG vXi1 to use v2Xi32 splatted shifts instead
If somehow a vXi64 bool sign_extend_inreg pattern has been lowered to vector shifts (without PSRAQ support), then try to canonicalize to vXi32 shifts to improve likelihood of value tracking being able to fold them away.

Using a PSLLQ and bitcasted PSRAD node make it very difficult for later fold to recover from this.
2023-07-17 10:18:03 +01:00
Serge Pavlov
be794e3d92 [X86][FPEnv] Lowering of {get,set,reset}_fpenv
The change implements lowering of `get_fpenv`, `set_fpenv` and
`reset_fpenv`.

Differential Revision: https://reviews.llvm.org/D81833
2023-07-14 22:10:53 +07:00
Serge Pavlov
25a81a1871 Precommit tests on lowering *_fpenv on X86 2023-07-14 22:10:12 +07:00
Simon Pilgrim
720debcf64 [X86] Fold PACKSS(NOT(X),NOT(Y)) -> NOT(PACKSS(X,Y)) 2023-07-14 10:36:21 +01:00
XinWang10
2d6a5ab5eb [X86]Recommit D154193 - Remove TEST in AND32ri+TEST16rr in peephole-opt
Previously we remove a pattern like:
  %reg = and32ri %in_reg, 5
  ...                         // EFLAGS not changed.
  %src_reg = subreg_to_reg 0, %reg, %subreg.sub_index
  test64rr %src_reg, %src_reg, implicit-def $eflags
We can remove test64rr since it has same functionality as and subreg_to_reg avoid the opt in previous code, so we handle this case specially.
And this case is also can be opted for the same reason, like:
  %reg = and32ri %in_reg, 5
  ...                         // EFLAGS not changed.
  %src_reg = copy %reg.sub_16bit:gr32
  test16rr %src_reg, %src_reg, implicit-def $eflags
The COPY from gr32 to gr16 prevent the opt in previous code too, just handle it specially as what we did for test64rr.

Reviewed By: skan

Differential Revision: https://reviews.llvm.org/D154193
2023-07-14 03:42:42 -04:00
Amara Emerson
432338a673 Don't assert on a non-pointer value being used for a "p" inline asm constraint.
GCC and existing codebases allow the use of integral values to be used
with this constraint. A recent change D133914 in this area started causing asserts.
Removing the assert is enough as the rest of the code works fine.

rdar://109675485

Differential Revision: https://reviews.llvm.org/D155023
2023-07-13 10:45:56 -07:00
Simon Pilgrim
c660a2f0ab [X86] Fold ANDNP(X,NOT(Y)) -> NOT(OR(X,Y))
Removing the x86-specific node helps further folding and improves commutativity
2023-07-13 16:56:20 +01:00
Simon Pilgrim
8d598531b3 Revert rGf269877dc30777354be8a512e871aba1b1f9fd7a "[X86] canonicalizeShuffleMaskWithHorizOp - fold permute(pack(x,y)) -> pack(shuffle(x,y),undef) iff we only demand the lower elements"
This appears to be causing some infinite loops (and is particularly bad when D152928 is applied).
2023-07-13 14:11:54 +01:00
Nikita Popov
7025ac81f0 [X86] Don't elide argument copies for scalarized vectors (PR63475)
When eliding argument copies, the memory layout between a plain
store of the type and the layout of the argument lowering on the
stack must match. For multi-part argument lowerings, this is not
necessarily the case.

The code already tried to prevent this optimization for "scalarized
and extended" vectors, but the check for "extends" was incomplete.
While a scalarized vector of i32s stores i32 values on the stack,
these are stored in 8 byte stack slots (on x86_64), so effectively
have padding.

Rather than trying to add more special cases to handle this (which
is not straightforward), I'm going in the other direction and
exclude scalarized vectors from this optimization entirely. This
seems like a rare case that is not worth the hassle -- the complete
lack of test coverage is not reassuring either.

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

Differential Revision: https://reviews.llvm.org/D154078
2023-07-13 14:49:48 +02:00
Nikita Popov
f78a06ef11 [X86] Remove out of range extract in test (NFC)
As pointed out in https://reviews.llvm.org/D154078#inline-1500915.
2023-07-13 14:46:29 +02:00
Maurice Heumann
d1fc8f7211 [X86] Prevent infinite loop in SelectionDAG when lowering negations
In certain cases, lowering negations can cause an infinite loop in SelectionDAG on X86.

The following snippet shows that behaviour:
https://godbolt.org/z/5hP45T4hY

What happens is that ADD(XOR(..., -1), 1) is detected as the two's complement and transformed into SUB(0, ...)
However, immediates can not be encoded as the LHS of a SUB on X86.
Therefore it is transformed back into an ADD/XOR pair, which is then again transformed into a SUB and so on.

In that specific case, I still think it is valid to display this as a SUB(0,...) , because it should eventually be lowered as a NEG.
Which seems better than an ADD/XOR pair.

Adding an exception to the X86 specific handling for SUBs with 0 LHS operand fixes this infinite loop.

Differential Revision: https://reviews.llvm.org/D154575
2023-07-13 12:20:44 +01:00
Simon Pilgrim
451af63551 [X86] Remove combineVectorTruncation and delay general vector trunc to lowering
Stop folding vector truncations to PACKSS/PACKUS patterns prematurely - another step towards Issue #63710. We still prematurely fold to PACKSS/PACKUS if there are sufficient signbits, that will be addressed in a later patch when we remove combineVectorSignBitsTruncation.

This required ReplaceNodeResults to extend handling of sub-128-bit results to SSSE3 (or later) cases, which has allowed us to improve vXi32->vXi16 truncations to use PSHUFB.

I also tweaked LowerTruncateVecPack to recognise widened truncation source operands so the upper elements remain UNDEF (otherwise truncateVectorWithPACK* will constant fold them to allzeros/allones values).
2023-07-13 11:29:21 +01:00
Simon Pilgrim
228442a14c [X86] canonicalizeShuffleMaskWithHorizOp - fold 256-bit permute(hop(x,y)) -> hop(extract(x),extract(x)) iff we only demand the lower elements
Attempt to recognise when we can narrow a 256-bit hop to a lower 128-bit hop by extracting the requested subvectors (and then widening back)
2023-07-13 10:37:08 +01:00
Simon Pilgrim
f269877dc3 [X86] canonicalizeShuffleMaskWithHorizOp - fold permute(pack(x,y)) -> pack(shuffle(x,y),undef) iff we only demand the lower elements
Help expose undef elements for further shuffle combines

Noticed while trying to improve truncation packss/packus patterns for sub-128-bit results.
2023-07-13 10:37:08 +01:00
Noah Goldstein
a4c461c063 [SelectionDAG] Fill in some more cases in isKnownNeverZero
This mostly copies cases that already exist in ValueTracking, although
it skips the more complex ones. Those can be filled in as needed.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D149199
2023-07-12 17:17:53 -05:00
Noah Goldstein
24f752ed2e [X86] Add tests for checking isKnownNeverZero; NFC
Differential Revision: https://reviews.llvm.org/D149299
2023-07-12 17:17:53 -05:00
Noah Goldstein
74f0ec5e24 [DAGCombiner] Make it so that udiv can be folded with (select c, NonZero, 1)
This is done by allowing speculation of `udiv` if we can prove the
denominator is non-zero.

https://alive2.llvm.org/ce/z/VNCt_q

Differential Revision: https://reviews.llvm.org/D149198
2023-07-12 17:17:53 -05:00
Noah Goldstein
eccb454177 [X86] Add tests for div/rem %x, (select c, <const>, 1); NFC
Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D149197
2023-07-12 17:17:52 -05:00
Jingu Kang
33e60484d7 [MachineLICM] Handle Subloops
MachineLICM pass handles inner loops only when outmost loop does not have unique
predecessor. If the loop has preheader and there is loop invariant code, the
invariant code can be hoisted to the preheader in general. This patch makes the
pass handle inner loops in general.

Differential Revision: https://reviews.llvm.org/D154205
2023-07-12 16:32:14 +01:00
Marco Elver
de79233b2e [X86] Complete preservation of !pcsections in X86ISelLowering
https://reviews.llvm.org/D130883 introduced MIMetadata to simplify
metadata propagation (DebugLoc and PCSections).

However, we're currently still permitting implicit conversion of
DebugLoc to MIMetadata, to allow for a gradual transition and let the
old code work as-is.

This manifests in lost !pcsections metadata for X86-specific lowerings.
For example, 128-bit atomics.

Fix the situation for X86ISelLowering by converting all BuildMI() calls
to use an explicitly constructed MIMetadata.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D154986
2023-07-12 15:09:31 +02:00
Nikita Popov
edb2fc6dab [llvm] Remove explicit -opaque-pointers flag from tests (NFC)
Opaque pointers mode is enabled by default, no need to explicitly
enable it.
2023-07-12 14:35:55 +02:00
Nikita Popov
d69033d245 [SCEVExpander] Fix GEP IV inc reuse logic for opaque pointers
Instead of checking the pointer type, check the element type of
the GEP.

Previously we ended up reusing GEP increments that were not in
expanded form, thus not respecting LSRs choice of representation.

The change in 2011-10-06-ReusePhi.ll recovers a regression that
appeared when converting that test to opaque pointers.

Changes in various Thumb tests now compute the step outside the
loop instead of using add.w inside the loop, which is LSR's
preferred representation for this target.
2023-07-12 11:32:13 +02:00
Han Shen
65ef4d4357 [CodeGen] Part II of "Fine tune MachineFunctionSplitPass (MFS) for FSAFDO".
This CL adds a new discriminator pass. Also adds a new sample profile
loading pass when MFS is enabled.

Differential Revision: https://reviews.llvm.org/D152577
2023-07-11 22:40:25 -07:00
Matt Arsenault
b59022b42e DAG: Handle lowering of unordered fcZero|fcSubnormal to fcmp 2023-07-11 18:30:15 -04:00
Simon Pilgrim
72fddda8af [X86] ReplaceNodeResults - widen vector truncate nodes on pre-SSSE3 targets
Building on the support for wider input vector types from D154592, try to more aggressively widen inputs instead of scalarizing them.
2023-07-11 17:21:20 +01:00
Phoebe Wang
db8b624de1 [X86][FP16] Fix mis-combination from FMULC to FCMULC
The combination was designed to combine a negative imaginary value
rather then a full negative complex value.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D154213
2023-07-11 22:26:20 +08:00
Simon Pilgrim
6656c8d01f [X86] shuffle-vs-trunc-256.ll - move comment outside test. NFC. 2023-07-11 14:31:50 +01:00
Simon Pilgrim
77b3f890cc [X86] combineAndMaskToShift - match constant splat with X86::isConstantSplat
Using X86::isConstantSplat instead of ISD::isConstantSplatVector allows us to detect constant masks after they've been lowered to constant pool loads.

Addresses regression from D154592
2023-07-11 11:25:34 +01:00
Simon Pilgrim
842a6728d9 [X86] LowerTRUNCATE - improve handling during type legalization to PACKSS/PACKUS patterns
Extend coverage for lowering wide vector types during type legalization to allow us to use PACKSS/PACKUS patterns instead of dropping down to shuffle lowering.

First step towards avoiding premature folds of TRUNCATE to PACKSS/PACKUS nodes as described on Issue #63710 - which causes a large number of regressions on D152928 - we will next need to tweak the TRUNCATE widening in ReplaceNodeResults

Differential Revision: https://reviews.llvm.org/D154592
2023-07-11 10:39:44 +01:00
Nabeel Omer
e148899ad9 [X86] Preserve volatile ATOMIC_LOAD_OR nodes
Fixes #63692.

In reference to volatile memory accesses, the langref says:
> the backend should never split or merge target-legal volatile load/store instructions.

Differential Revision: https://reviews.llvm.org/D154609
2023-07-11 08:05:38 +00:00
Matt Arsenault
1d92b68ead DAG: Correct chain management for frexp libcalls
We need to replace the other uses of the call chain with the new load
chain.

Fixes not preserving the return def with unused x86_fp80
results. Regression reported here:
https://reviews.llvm.org/rGb15bf305ca3e9ce63aaef7247d32fb3a75174531#1224999
2023-07-10 21:39:15 -04:00
Han Shen
8df75969ae [CodeGen] Fine tune MachineFunctionSplitPass (MFS) for FSAFDO.
The original MFS work D85368 shows good performance improvement with
Instrumented FDO. However, AutoFDO or Flow-Sensitive AutoFDO (FSAFDO)
does not show performance gain. This is mainly caused by a less
accurate profile compared to the iFDO profile.

For the past few months, we have been working to improve FSAFDO
quality, like in D145171. Taking advantage of this improvement, MFS
now shows performance improvements over FSAFDO profiles.

That being said, 2 minor changes need to be made, 1) An FS-AutoFDO
profile generation pass needs to be added right before MFS pass and an
FSAFDO profile load pass is needed when FS-AutoFDO is enabled and the
MFS flag is present. 2) MFS only applies to hot functions, because we
believe (and experiment also shows) FS-AutoFDO is more accurate about
functions that have plenty of samples than those with no or very few
samples.

With this improvement, we see a 1.2% performance improvement in clang
benchmark, 0.9% QPS improvement in our internal search benchmark, and
3%-5% improvement in internal storage benchmark.

This is #1 of the two patches that enables the improvement.

Reviewed By: wenlei, snehasish, xur

Differential Revision: https://reviews.llvm.org/D152399
2023-07-10 16:00:30 -07:00
Simon Pilgrim
1ab442464b [X86] Regenerate or-address.ll test checks 2023-07-10 16:55:52 +01:00
Nabeel Omer
862e5dcb7e [X86] Pre-commit test for lowerAtomicArith
Test for https://reviews.llvm.org/D154609
2023-07-10 14:21:20 +00:00
Wang, Xin10
284a059b33 Revert "[X86]Remove TEST in AND32ri+TEST16rr in peephole-opt"
This reverts commit 2c64226d84174dd1d9f93e1884c1b0bd432f89b5.

revert first due to buildbot fail https://lab.llvm.org/buildbot/#/builders/85/builds/17571
2023-07-10 03:20:11 -04:00
XinWang10
2c64226d84 [X86]Remove TEST in AND32ri+TEST16rr in peephole-opt
Previously we remove a pattern like:
  %reg = and32ri %in_reg, 5
  ...                         // EFLAGS not changed.
  %src_reg = subreg_to_reg 0, %reg, %subreg.sub_index
  test64rr %src_reg, %src_reg, implicit-def $eflags
We can remove test64rr since it has same functionality as and subreg_to_reg avoid the opt in previous code, so we handle this case specially.
And this case is also can be opted for the same reason, like:
  %reg = and32ri %in_reg, 5
  ...                         // EFLAGS not changed.
  %src_reg = copy %reg.sub_16bit:gr32
  test16rr %src_reg, %src_reg, implicit-def $eflags
The COPY from gr32 to gr16 prevent the opt in previous code too, just handle it specially as what we did for test64rr.

Reviewed By: skan

Differential Revision: https://reviews.llvm.org/D154193
2023-07-09 23:21:32 -04:00
Simon Pilgrim
7428739ea8 [X86] matchAddressRecursively - peek through ZEXT nodes to match foldMaskAndShiftToExtract
Handle (zero_extend (and (srl X, C1), C2)) patterns to allow foldMaskAndShiftToExtract to match h-register extractions from smaller types

Ideally matchAddressRecursively needs to be able to recurse through ZEXT/SEXT nodes generally but for now we should just handle specific cases when they occur

Addresses regressions in D146121
2023-07-09 15:41:38 +01:00
Simon Pilgrim
848f6abfdb [X86] Add tests showing failure by matchAddressRecursively to peek through ZEXT nodes to match foldMaskAndShiftToExtract
Test coverage for a similar regression in D146121
2023-07-09 15:41:38 +01:00
Yashwant Singh
b7836d8562 [CodeGen]Allow targets to use target specific COPY instructions for live range splitting
Replacing D143754. Right now the LiveRangeSplitting during register allocation uses
TargetOpcode::COPY instruction for splitting. For AMDGPU target that creates a
problem as we have both vector and scalar copies. Vector copies perform a copy over
a vector register but only on the lanes(threads) that are active. This is mostly sufficient
however we do run into cases when we have to copy the entire vector register and
not just active lane data. One major place where we need that is live range splitting.

Allowing targets to use their own copy instructions(if defined) will provide a lot of
flexibility and ease to lower these pseudo instructions to correct MIR.

- Introduce getTargetCopyOpcode() virtual function and use if to generate copy in Live range
 splitting.
- Replace necessary MI.isCopy() checks with TII.isCopyInstr() in register allocator pipeline.

Reviewed By: arsenm, cdevadas, kparzysz

Differential Revision: https://reviews.llvm.org/D150388
2023-07-07 22:29:50 +05:30
Matt Arsenault
64df9573a7 DAG: Handle inversion of fcSubnormal | fcZero
There are a number of more test combinations here that
can be done together and reduce the number of instructions.

https://reviews.llvm.org/D143191
2023-07-06 21:19:44 -04:00
Matt Arsenault
61820f8b5d CodeGen: Optimize lowering of is.fpclass fcZero|fcSubnormal
Combine the two checks into a check if the exponent bits are 0. The
inverted case isn't reachable until a future change, and GlobalISel
currently doesn't attempt the inversion optimization.

https://reviews.llvm.org/D143182
2023-07-06 13:03:57 -04:00
Matt Arsenault
1588e18b2d DAG: Check isCondCodeLegal in is_fpclass expansion to fcmp eq 0
Results in some x86 codegen diffs. Some look better, some look worse.

https://reviews.llvm.org/D152094
2023-07-06 13:00:52 -04:00
Simon Pilgrim
a69ffd6c73 [X86] isTargetShuffleEquivalent - ensure the reference operands are vector types
Fixes #63700
2023-07-06 15:38:01 +01:00
Simon Pilgrim
c63be92fc8 [GlobalISel][X86] Regenerate add/sub legalization tests 2023-07-06 14:09:11 +01:00
Simon Pilgrim
3f7470c33d [X86] Fold BITOP(PACKSS(X,Z),PACKSS(Y,W)) --> PACKSS(BITOP(X,Y),BITOP(Z,W)) (REAPPLIED)
Fold allsignbits pack patterns to make better use of cheap (and commutable) logic ops

Reapplied after a32d14fd4c0a / 156913cb7764 with bitcast fix
2023-07-06 10:56:07 +01:00
Simon Pilgrim
bb65e5b881 [X86] Add base SSE2 i686 test coverage to vector bitlogic reduction tests 2023-07-06 10:56:07 +01:00
Simon Pilgrim
819d070e0e [X86] Add base SSE2 i686 test coverage to vector bool reduction tests 2023-07-06 10:56:06 +01:00
Arthur Eubanks
156913cb77 Revert "[X86] Fold BITOP(PACKSS(X,Z),PACKSS(Y,W)) --> PACKSS(BITOP(X,Y),BITOP(Z,W))"
This reverts commit a32d14fd4c0a43c154f251df1ccfe57e8b0a711a.

Causes crashes, see https://reviews.llvm.org/rGa32d14fd4c0a43c154f251df1ccfe57e8b0a711a.
2023-07-05 14:52:57 -07:00