18994 Commits

Author SHA1 Message Date
Craig Topper
df017ba9d3 [TargetLowering] Don't use ISD::SELECT_CC in expandFP_TO_INT_SAT.
This function gets called for vectors and ISD::SELECT_CC was never
intended to support vectors. Some updates were made to support
it when this function started getting used for vectors.

Overall, using separate ISD::SETCC and ISD::SELECT looks like an
improvement even for scalar.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D149481
2023-04-29 10:23:08 -07:00
Matt Arsenault
bc37be1855 LangRef: Add "dynamic" option to "denormal-fp-math"
This is stricter than the default "ieee", and should probably be the
default. This patch leaves the default alone. I can change this in a
future patch.

There are non-reversible transforms I would like to perform which are
legal under IEEE denormal handling, but illegal with flushing zero
behavior. Namely, conversions between llvm.is.fpclass and fcmp with
zeroes.

Under "ieee" handling, it is legal to translate between
llvm.is.fpclass(x, fcZero) and fcmp x, 0.

Under "preserve-sign" handling, it is legal to translate between
llvm.is.fpclass(x, fcSubnormal|fcZero) and fcmp x, 0.

I would like to compile and distribute some math library functions in
a mode where it's callable from code with and without denormals
enabled, which requires not changing the compares with denormals or
zeroes.

If an IEEE function transforms an llvm.is.fpclass call into an fcmp 0,
it is no longer possible to call the function from code with denormals
enabled, or write an optimization to move the function into a denormal
flushing mode. For the original function, if x was a denormal, the
class would evaluate to false. If the function compiled with denormal
handling was converted to or called from a preserve-sign function, the
fcmp now evaluates to true.

This could also be of use for strictfp handling, where code may be
changing the denormal mode.

Alternative name could be "unknown".

Replaces the old AMDGPU custom inlining logic with more conservative
logic which tries to permit inlining for callees with dynamic handling
and avoids inlining other mismatched modes.
2023-04-29 08:44:59 -04:00
Luo, Yuanke
40222ddcf8 [X86] Fix the vnni machine combine issue.
The previous patch (D148980) didn't set the InstrIdxForVirtReg correctly
in genAlternativeDpCodeSequence(). It causes vnni lit test failure when
LLVM_ENABLE_EXPENSIVE_CHECKS is on.
2023-04-29 13:51:08 +08:00
Luo, Yuanke
8f7f9d86a7 [X86] Machine combine vnni instruction.
"vpmaddwd + vpaddd" can be combined to vpdpwssd and the latency is
reduced after combination. However when vpdpwssd is in a critical path
the combination get less ILP. It happens when vpdpwssd is in a loop, the
vpmaddwd can be executed in parallel in multi-iterations while vpdpwssd
has data dependency for each iterations. If vpaddd is in a critical path
while vpmaddwd is not, it is profitable to split vpdpwssd into "vpmaddwd
+ vpaddd".
This patch is based on the machine combiner framework to acheive decision
on "vpmaddwd + vpaddd" combination. The typical example code is as
below.
```
__m256i foo(int cnt, __m256i c, __m256i b, __m256i *p) {

    for (int i = 0; i < cnt; ++i) {
        __m256i a = p[i];
        __m256i m = _mm256_madd_epi16 (b, a);
        c = _mm256_add_epi32(m, c);
    }

    return c;
}
```

Differential Revision: https://reviews.llvm.org/D148980
2023-04-27 16:42:04 +08:00
Noah Goldstein
ddfee6d0b6 [X86] Support X86ISD::PCMPEQ and X86ISD::PCMPGT in ComputeKnownBits
These functions where missing support but are used enough that it
makes sense to track them.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D148963
2023-04-26 23:48:24 -05:00
Simon Pilgrim
ee52af74d8 [X86] Handle multiple use freeze(undef) in LowerAVXCONCAT_VECTORS as zero vectors
Replacement for D144903

If we're concatenating freeze(undef) subvector ops with multiple uses then we can't treat them as a wider freeze(undef), but we can replace them with a zero subvector, which is cheap on AVX

Differential Revision: https://reviews.llvm.org/D149249
2023-04-26 12:33:06 +01:00
Simon Pilgrim
ae0f41d186 [X86] LowerBUILD_VECTOR - fold build_vector(undef,freeze(undef),zero) -> zero vector
426db6b4eb2e9298598 added the build_vector(undef,freeze(undef)) -> freeze(undef) fold, but failed to account for cases where the scalar freeze(undef) had multiple uses, in those cases we can only only safely fold to a zero vector

https://alive2.llvm.org/ce/z/87jG8K
2023-04-26 10:44:58 +01:00
Han Zhu
075202d126 [X86 isel] Fix permute mask calculation in lowerShuffleAsUNPCKAndPermute
This fixes [issue 62242](https://github.com/llvm/llvm-project/issues/62242)

This code block can potentially swap the order of V1 and V2 in Ops and therefore
also in the unpck instruction generated.
```
SDValue &Op = Ops[Elt & 1];
if (M < NumElts && (Op.isUndef() || Op == V1))
  Op = V1;
else if (NumElts <= M && (Op.isUndef() || Op == V2)) {
  Op = V2;
  NormM -= NumElts;
} else
  return SDValue();
```
But the permute mask is calculated assuming the first operand being V1 and
second V2, therefore causing a mis-compile.

First check if the input operands are swapped, and then calculate the permute
mask based on that.

Differential Revision: https://reviews.llvm.org/D148843
2023-04-24 13:54:37 -07:00
Simon Pilgrim
be93256655 [VP] Add IR expansion for fneg
Followup to D149052, it wasn't worthwhile to add general support for unary opcodes
2023-04-24 16:14:06 +01:00
Simon Pilgrim
0b7f53efec [VP] IR expansion for fabs/fsqrt/fma/fmadd
Add basic handling for VP ops that can expand to FP intrinsics

Fixes #60464

Differential Revision: https://reviews.llvm.org/D149052
2023-04-24 15:20:07 +01:00
Simon Pilgrim
1746c7838e [X86] Add DAG test coverage for Issue #59867 patterns 2023-04-23 18:44:46 +01:00
Simon Pilgrim
e9f9467da0 [X86] X86FixupInstTunings - add VPERMILPDri -> VSHUFPDrri mapping
Similar to the original VPERMILPSri -> VSHUFPSrri mapping added in D143787, replacing VPERMILPDri -> VSHUFPDrri should never be any slower and saves an encoding byte.

The sibling VPERMILPDmi -> VPSHUFDmi mapping is trickier as we need the same shuffle mask in every lane (and it needs to be adjusted) - I haven't attempted that yet but we can investigate it in the future if there's interest.

Fixes #61060

Differential Revision: https://reviews.llvm.org/D148999
2023-04-23 11:48:50 +01:00
Luo, Yuanke
ce98cb9c64 [X86] Precommit test case for D148980. 2023-04-23 17:27:15 +08:00
Noah Goldstein
ee0d46ae55 [X86] Transform (cmp eq/ne trunc(X), C) -> (cmp eq/ne X, Zext(C))
This previously existed for `C == 0`, but is mostly beneficial for any
`C`.

There is a slight codesize cost as we get more imm32 (as opposed to
imm8) constants in some cases. But the benefit is was get less imm16
constants (LCP stalls) and save instructions in some vec -> scalar
codegen.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D148594
2023-04-23 02:26:11 -05:00
Simon Pilgrim
c3bf6d20ac [X86] Fold PSHUF(VSHIFT(X,Y)) -> VSHIFT(PSHUF(X),Y)
PSHUFD/PSHUFLW/PSHUFHW can act as a vector move / folded load, notably helping simplify pre-AVX cases in particular.

This is a much milder alternative to refactoring canonicalizeShuffleWithBinOps to support SSE shifts nodes.
2023-04-22 20:02:27 +01:00
Simon Pilgrim
f639a17892 [X86] Add PERMILPD tuning test coverage for Issue #61060 2023-04-22 17:49:51 +01:00
Simon Pilgrim
bc81f5a973 [X86] combineSetCCMOVMSK - fold allof movmskps/movmskpd -> testps/testpd
Fixes #60007
2023-04-22 17:00:35 +01:00
Simon Pilgrim
aa84981224 [X86] LowerBUILD_VECTOR - narrow 256/512-bit vector containing undef/freeze(undef)/zero in the upper half
Fixes #62286
2023-04-22 15:30:50 +01:00
Simon Pilgrim
426db6b4eb [X86] LowerBUILD_VECTOR - fold build_vector(undef,freeze(undef)) -> freeze(undef)
Noticed while triaging #62286
2023-04-22 15:30:50 +01:00
Luo, Yuanke
104448f9c5 [X86] Precommit test case for D148980.
There is no cross-loop dependency for this case.
2023-04-22 20:11:47 +08:00
Luo, Yuanke
66ba85b9c5 [X86] Precommit test case for D148980. 2023-04-22 15:40:38 +08:00
Alexis Engelke
5368c1065f [X86][FastISel] Handle CRC32 intrinsics
Some applications make heavy use of the crc32 operation (e.g., as part
of a hash function), so having a FastISel path avoids fallbacks to
SelectionDAG and improves compile times, in our case by ~1.5%.

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D148023
2023-04-21 13:40:48 +02:00
Serguei Katkov
aa5cc39b6d [BreakFalseDeps] Respect dead blocks.
The pass uses ReachingDefAnalysis which has no information about
instructions in dead blocks.
So do not process them.

Reviewed By: pengfei
Differential Revision: https://reviews.llvm.org/D148329
2023-04-21 12:17:04 +07:00
Xiang1 Zhang
f50059b04f [X86] combineConcatVectorOps - remove FADD/FSUB/FMUL handling
Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D147996
2023-04-20 10:37:46 +08:00
Fangrui Song
d14460d00e [AsmPrinter] Fix placement of function entry comments
The placement is currently wrong in the presence of function entry related
instrumentations (prefixdata, -fpatchable-function-entry=, -fsanitize=kcfi,
etc).
2023-04-18 15:01:36 -07:00
Bing1 Yu
dd3eb53275 [X86] Create all-one vector(v8i32) for TESTC(X,~X) == TESTC(X,-1) if X is v8f32
getAllOnesConstant can only take v8i32 instead of v8f32

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D148608
2023-04-19 01:27:56 +08:00
Serguei Katkov
4e9ae7255b [MachineCSE] Add a test with mutiple blocks between instructions.
Due to limitation that we consider only one alone predecessor
we cannot generate the code like
ucomiss
jp
ja
jne
2023-04-18 15:32:50 +07:00
Brad Smith
b71f2fcd46 [Android] Use ELF TLS for Android API level 29+
Use ELF TLS by default instead of emulated TLS for Android build targets when
the API level is >= 29.

Android Q features full TLS support. See release notes
(https://developer.android.com/preview/features#elf-tls) and implementation details
(https://android.googlesource.com/platform/bionic/+/master/docs/elf-tls.md#Workaround_Use-Variant-2-on-arm32_arm64).

Reviewed By: rprichard, danalbert

Differential Revision: https://reviews.llvm.org/D147849
2023-04-17 19:32:29 -04:00
Pavel Kosov
c3ec3ed2a1 [LLVM][OHOS] Use emulated TLS for OHOS platform
Both Linux and LiteOS for all OpenHarmony targets use emulated TLS

~~~

Huawei RRI, OS Lab

Reviewed By: DavidSpickett, jrtc27, MaskRay

Differential Revision: https://reviews.llvm.org/D145224
2023-04-17 17:35:22 +03:00
Simon Pilgrim
722cf542da [X86] combinePTESTCC - fold TESTZ(OR(LO(X),HI(X)),OR(LO(Y),HI(Y))) -> TESTZ(X,Y) for TESTPS/TESTPD ops
Followup to the fix for #62171, adding support for TESTPS/TESTPD opcodes
2023-04-17 14:10:01 +01:00
Simon Pilgrim
f2d03a2533 [X86] combinePTESTCC - only fold TESTZ(OR(LO(X),HI(X)),OR(LO(Y),HI(Y))) -> TESTZ(X,Y) for TESTP ops
Stop value type mismatch assertions, we can add TESTPS/TESTPD support to this in the future.

Fixes #62171
2023-04-17 11:43:00 +01:00
Nikita Popov
fe4dbbb467 [DAGCombiner] Fold add (mul x, C), x to mul x, C+1
While this is normally non-canonical IR, this pattern can appear
during SDAG lowering if the add is actually a getelementptr, as
illustrated in `@test_ptr`. This pattern comes up when doing
provenance-aware high-bit pointer tagging.

Proof: https://alive2.llvm.org/ce/z/DLoEcs

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

Differential Revision: https://reviews.llvm.org/D148341
2023-04-17 12:33:46 +02:00
Simon Pilgrim
3a0c1d5ab9 [X86] combineSetCCMOVMSK - fold anyof/noneof movmskps/movmskpd -> testps/testpd
Another part of Issue #60007
2023-04-14 15:37:40 +01:00
Nikita Popov
d4a58442b1 [X86] Add additional add of mul test (NFC) 2023-04-14 16:28:21 +02:00
Nikita Popov
d3a2436b82 [X86] Add test for foldable add of mul (NFC) 2023-04-14 15:57:30 +02:00
Simon Pilgrim
6523e2f4f9 [X86] SimplifyDemandedBitsForTargetNode - improve TESTPS/TESTPD handling for duplicated operands
We often repeat the vector operand in TESTPS(X,X)/TESTPD(X,X) for anyof comparisons - ensure we still only demand the sign bits when the TESTP is the only user of that operand
2023-04-14 12:03:38 +01:00
Simon Pilgrim
7025c2f226 [X86] Add AVX2 test coverage to TESTPS/TESTPD combines 2023-04-14 11:29:24 +01:00
Simon Pilgrim
4fae304d45 [X86] Add TESTPS/TESTPD test coverage showing failure to simplify demanded sign bit when the operands has multiple uses 2023-04-14 11:29:24 +01:00
Simon Pilgrim
7ea34403f3 [X86] Only fold PTEST->TESTP on AVX targets
While PTEST is a SSE41 instruction, TESTPS/TESTPD was only added for AVX
2023-04-13 19:39:47 +01:00
Simon Pilgrim
33cc733bc4 [X86] Split 128 and 256-bit PTEST combines
We are missing SSE41 test coverage (and in fact have a bug with a PTEST->TESTP fold that is only valid on AVX).
2023-04-13 19:36:53 +01:00
Nick Desaulniers
fc4494dffa [StackProtector] don't check stack protector before calling nounwind functions
https://reviews.llvm.org/rGd656ae28095726830f9beb8dbd4d69f5144ef821
introduced a additional checks before calling noreturn functions in
response to this security paper related to Catch Handler Oriented
Programming (CHOP):
https://download.vusec.net/papers/chop_ndss23.pdf
See also:
https://bugs.chromium.org/p/llvm/issues/detail?id=30

This causes stack canaries to be inserted in C code which was
unexpected; we noticed certain Linux kernel trees stopped booting after
this (in functions trying to initialize the stack canary itself).
https://github.com/ClangBuiltLinux/linux/issues/1815

There is no point checking the stack canary like this when exceptions
are disabled (-fno-exceptions or function is marked noexcept) or for C
code.  The GCC patch for this issue does something similar:
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=a25982ada523689c8745d7fb4b1b93c8f5dab2e7

Android measured a 2% regression in RSS as a result of d656ae280957 and
undid it globally:
https://android-review.googlesource.com/c/platform/build/soong/+/2524336

Reviewed By: xiangzhangllvm

Differential Revision: https://reviews.llvm.org/D147975
2023-04-13 09:37:06 -07:00
sgokhale
bb5befefc6 Revert "[CodeGen][ShrinkWrap] Split restore point"
This reverts commit 5f0bccc3d1a74111458c71f009817c9995f4bf83.

An issue has been reported here: https://github.com/ClangBuiltLinux/linux/issues/1833
2023-04-13 10:52:28 +05:30
Han Zhu
ef38880ce0 [X86 isel] Remove lane requirement from lowerShuffleAsUNPCKAndPermute
`lowerShuffleAsUNPCKAndPermute` requires the shuffle mask element to be
in the same lane in both the input and output vectors. This prevents it from
matching certain patterns for example in [GHI
61964](https://github.com/llvm/llvm-project/issues/61964). Removing the lane
requirement fixes the issue.

The change I'm targeting is in the test llvm/test/CodeGen/X86/pr61964.ll. The
codegen has improved notably with this patch. Otherwise, looks like some
broadcast instructions are replaced with unpck and perm. To check if there's
any other performance change, I ran llvm-test-suite benchmarks from the
SingleSource, MultiSource, and MicroBenchmarks directories:
```
Tests: 2665
Short Running: 2009 (filtered out)
Same hash: 140 (filtered out)
In Blacklist: 513 (filtered out)
Remaining: 3
Metric: exec_time

Program                                                                exec_time
                                                                       lhs       rhs    diff
 test-suite :: MultiSource/Benchmarks/ASCI_Purple/SMG2000/smg2000.test   1.64      1.64  0.1%
      test-suite :: SingleSource/Benchmarks/Adobe-C++/loop_unroll.test   1.06      1.06  0.0%
          test-suite :: MultiSource/Applications/JM/lencod/lencod.test   5.25      5.25  0.0%
                                                    Geomean difference    nan       nan  0.0%
      exec_time
l/r         lhs       rhs      diff
count  3.000000  3.000000  3.000000
mean   2.648300  2.649100  0.000462
std    2.269035  2.268849  0.000415
min    1.055500  1.055900  0.000095
25%    1.349300  1.350250  0.000237
50%    1.643100  1.644600  0.000379
75%    3.444700  3.445700  0.000646
max    5.246300  5.246800  0.000913
```
The patch only hits three cases and the result is neutral. (The 513 blacklisted
benchmarks are the ones under MicroBenchmarks, which `--filter-hash` does
not work and I manually verified their code did not change).

Differential Revision: https://reviews.llvm.org/D147668
2023-04-12 17:11:18 -07:00
Simon Pilgrim
d514382795 [X86] combinePTESTCC - attempt to use TESTPS/TESTPD instead of MOVMSKPS/MOVMSKPD for all-of cases with all-sign values.
We can probably be more aggressive with TESTPS/TESTPD (instead of relying on the SimplifyMultipleUseDemandedBits call) - I've updated an existing TODO to suggest this for now.

Part of Issue #60007
2023-04-12 15:33:12 +01:00
Simon Pilgrim
1e155ce9cd [X86] SimplifyDemandedBitsForTargetNode - add TESTPS/TESTPD support
We only need the sign bits from these nodes

Another step towards Issue #60007
2023-04-12 11:54:23 +01:00
Simon Pilgrim
a11523a0c1 [X86] Add test coverage for TESTPS/TESTPD showing the failure to demand only the sign bits
Part of Issue #60007
2023-04-12 11:37:41 +01:00
Simon Pilgrim
20b929b297 [X86] widen-load-of-small-alloca tests - use X86 check prefix for i686 triples
We try to use X32 just for gnux32 triples
2023-04-11 18:01:50 +01:00
Amaury Séchet
91105df3df [DAG] Peek through zext/trunc when matching (or (and X, (not Y)), Y).
This shows up in the wild, notably as a regression in D127115 .

Depends on D147821

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D147827
2023-04-11 13:48:22 +00:00
Simon Pilgrim
aeb4626b39 [X86] Remove unnecessary OneUse limit from combineToExtendBoolVectorInReg (vXi1 bitcast(iX Cond)) select expansion
We already allow multiple uses when calling from combineSext/combineZext - adding hasOneUse seems to have been a copy+paste from some of the similar AVX512 vselect folds.

Fixes #62014
2023-04-11 14:18:50 +01:00
Amaury Séchet
e529cda970 [NFC] Add test cases for D147827 2023-04-11 13:14:10 +00:00