18646 Commits

Author SHA1 Message Date
Simon Pilgrim
d1426cd484 [DAG] visitAnd - fold (and (ext (and V, c1)), c2) -> (and (ext V), (and c1, (ext c2)))
Also, move the XformToShuffleWithZero and combineCarryDiamond folds later after some of the more basic canonicalizations/combines (such as this) have had a chance to occur

Fixes the v8i1-masks.ll regression from D127115
2023-01-23 14:28:37 +00:00
Anton Bikineev
0276fa89d7 [X86][ABI] Don't preserve return regs for preserve_all/preserve_most CCs
Currently both calling conventions preserve registers that are used to
store a return value. This causes the returned value to be lost:

  define i32 @bar() {
    %1 = call preserve_mostcc i32 @foo()
    ret i32 %1
  }

  define preserve_mostcc i32 @foo() {
    ret i32 2
    ; preserve_mostcc will restore %rax,
    ; whatever it was before the call.
  }

This contradicts the current documentation (preserve_allcc "behaves
identical to the `C` calling conventions on how arguments and return
values are passed") and also breaks [[clang::preserve_most]].

This change makes CSRs be preserved iff they are not used to store a
return value (e.g. %rax for scalars, {%rax:%rdx} for __int128, %xmm0
for double). For void functions no additional registers are
preserved, i.e. the behaviour is backward compatible with existing
code.

Differential Revision: https://reviews.llvm.org/D141020
2023-01-23 13:32:17 +01:00
Simon Pilgrim
0c69cb226a [X86] Add test coverage for and(ext(and(x, c1)),c2) patterns
This shows the failure to merge to and(ext(x),and(c1,ext(c2))) if the outer and has already been folded to a clear shuffle mask

Similar to the v8i1-masks.ll from regression D127115
2023-01-23 12:05:58 +00:00
Noah Goldstein
44cac911e5 Fix FindSingleBitChange to handle NOT(V) where V is not an Instruction
Was previously buggy to assume that NOT'd Value was always an
instruction. If the NOT'd value is not an Instruction, we should just
return as its either a constant, in which can we will re-run the logic
after constant-folding, or its a type we can't evaluate anyways.

This is a follow up to: `D140939`

Reviewed By: pengfei, RKSimon

Differential Revision: https://reviews.llvm.org/D142339
2023-01-23 03:35:56 -08:00
Wang, Xin10
88eae6ef9f [DAGCombine]Expand usage of CreateBuildVecShuffle to make full use of vector ops
Now, when llc encounters the case that contains a lot of
extract_vector_elt and a BUILD_VECTOR, it will replace these to
vector_shuffle to decrease the size of code, the actions are done in
createBuildVecShuffle in DAGCombiner.cpp, but now the code cannot handle
the case that the size of source vector reg is more than twice the dest
size.

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D139685
2023-01-23 11:45:38 +08:00
Simon Pilgrim
92ce50ba21 [X86] avx2-vbroadcast.ll - use X86 check prefix instead of X32
We try to use X32 for tests on gnux32 triples
2023-01-22 15:19:23 +00:00
Simon Pilgrim
6aa43fed4c [X86] commute-3dnow.ll - use X86 check prefix instead of X32
We try to use X32 for tests on gnux32 triples
2023-01-22 14:57:06 +00:00
Simon Pilgrim
8fd6fc78ae [X86] avx-vbroadcastf128.ll - use X86 check prefix instead of X32
We try to use X32 for tests on gnux32 triples
2023-01-22 14:57:06 +00:00
Roman Lebedev
b40532ceb0
[NFC][X86] Fixup typo in blend-of-shift.ll 2023-01-22 16:14:27 +03:00
Roman Lebedev
902d0e86bd
[NFC][X86] Fixup -mattr=<> in one runline in elementwise-store-of-scalar-splat.ll 2023-01-22 16:14:27 +03:00
Roman Lebedev
005173cbb6
[X86] X86TargetLowering: override allowsMemoryAccess()
The baseline `allowsMemoryAccess()` is wrong for X86.
It assumes that aligned memory operations are always allowed,
but that is not true.

For example, We can not perform a 32-byte aligned non-temporal load
of a 32-byte vector, without AVX2 that is, yet `allowsMemoryAccess()`
will say it is allowed, so we may end up merging non-temporal loads,
only to split them up to legalize them, and here we go again.

NOTE: the test changes here are superfluous. The main effect is that without this change,
in D141777, we'd get stuck endlessly merging and splitting non-temporal stores.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D141776
2023-01-22 00:12:28 +03:00
Simon Pilgrim
0b432dfaf7 [X86] Add DAG tests showing the failure to reassociate IMINMAX nodes to fold constant operands
Test coverage for Issue #58110
2023-01-21 15:24:49 +00:00
Simon Pilgrim
c972e1c8b5 [X86] v8i1-masks.ll - add avx512 test coverage and use X86 check prefix instead of X32
We try to use X32 for tests on gnux32 triples
2023-01-21 14:14:31 +00:00
Simon Pilgrim
5a4e9aac79 [X86] avx2-vperm.ll - use X86 check prefix instead of X32
We try to use X32 for tests on gnux32 triples
2023-01-21 11:43:42 +00:00
Noah Goldstein
2e25204779 Make shouldExpandLogicAtomicRMWInIR able to match both operands.
Previous logic was buggy and erroneously asserted that I->operand(0) must
be the RMW instruction. This change fixes that and makes it so that the
RMW instruction can be used in operand 0 or 1.

Also update the tests to explicitly test RMW as operand 0/1 (no change
to codegen).

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D142166
2023-01-21 00:53:34 -08:00
Philip Reames
86eff6be68 [MachineCombiner] Use default latency model when no detailed model available
This change adjusts the cost modeling used when the target does not have a schedule model with individual instruction latencies. After this change, we use the default latency information available from TargetSchedule. The default latency information essentially ends up treating most instructions as latency 1, with a few "expensive" ones getting a higher cost.

Previously, we unconditionally applied the first legal pattern - without any consideration of profitability. As a result, this change both prevents some patterns being applied, and changes which patterns are exercised. (i.e. previously the first pattern was applied, afterwards, maybe the second one is because the first wasn't profitable.)

The motivation here is two fold.

First, this brings the default behavior in line with the behavior when -mcpu or -mtune is specified. This improves test coverage, and generally makes it less likely we will have bad surprises when providing more information to the compiler.

Second, this enables some reassociation for ILP by default. Despite being unconditionally enabled, the prior code tended to "reassociate" repeatedly through an entire chain and simply moving the first operand to the end. The result was still a serial chain, just a different one. With this change, one of the intermediate transforms is unprofitable and we end up with a partially flattened tree.

Note that the resulting code diffs show significant room for improvement in the basic algorithm. I am intentionally excluding those from this patch.

For the test diffs, I don't seen any concerning regressions. I took a fairly close look at the RISCV ones, but only skimmed the x86 (particularly vector x86) changes.

Differential Revision: https://reviews.llvm.org/D141017
2023-01-20 09:28:20 -08:00
Roman Lebedev
1eecf03919
[X86] LowerBUILD_VECTOR(): fix all-UNDEF detection
The original check was trying to avoid checking UndefMask itself,
and deduce it via simpler means, but checking `NonZeroMask`
does not, e.g., check `ZeroMask`.

Fixes https://github.com/llvm/llvm-project/issues/60168
2023-01-20 20:21:26 +03:00
OCHyams
3cbc72ef63 [Assignment Tracking] Fix tests for buildbot failure
Follow-up for 4ece50737d5385fb80cfa23f5297d1111f8eed39 (D142027).

Assignment Tracking Analysis now always runs and is skipped internally if
assignment tracking is disabled. Update these tests to expect to see the
pass run.

Buildbot failure: https://lab.llvm.org/buildbot/#/builders/216/builds/16085
2023-01-20 15:19:41 +00:00
Jannik Silvanus
76677173ec [X86] Fix i8 alignment in datalayout of lit test
A lit test used overaligned i8, apparently due to an old copy-paste
error, intending to specify i32 alignment.

Change the datalayout string to use naturally aligned i8.
2023-01-20 15:52:07 +01:00
Jeremy Morse
9f8544713a [DebugInfo] Store instr-ref mode of MachineFunction in member
Add a flag state (and a MIR key) to MachineFunctions indicating whether they
contain instruction referencing debug-info or not. Whether DBG_VALUEs or
DBG_INSTR_REFs are used needs to be determined by LiveDebugValues at least, and
using the current optimisation level as a proxy is proving unreliable.

Test updates are purely adding the flag to tests, in a couple of cases it
involves separating out VarLocBasedLDV/InstrRefBasedLDV tests into separate
files, as they can no longer share the same input.

Differential Revision: https://reviews.llvm.org/D141387
2023-01-20 14:47:11 +00:00
Craig Topper
f4fa34c359 Revert "[X86][WIP] Change precision control to FP80 during u64->fp32 conversion on Windows."
This reverts commit 928a1764d6bdf84073c9d85875f45c1716d6ff12.

Committed accidentally
2023-01-20 00:41:14 -08:00
Craig Topper
928a1764d6 [X86][WIP] Change precision control to FP80 during u64->fp32 conversion on Windows.
This is an alternative to D141074 to fix the problem by adjusting
the precision control dynamically.

This isn't quite complete yet. I want to support fadd with an load
folded into it too. That's the code we will usually generate.

Posting for early review so we can do some testing of this solution.

Differential Revision: https://reviews.llvm.org/D142178
2023-01-20 00:34:05 -08:00
Craig Topper
1692dff0b3 Revert "[X86] Avoid converting u64 to f32 using x87 on Windows"
This reverts commit a6e3027db7ebe6863e44bafcfeaacc16bdc88a3f.

Chrome and Halide are both reporting issues with importing builtins.

Maybe the better direction is to manually adjust FPCW for the inline
sequence on Windows.
2023-01-19 21:36:07 -08:00
Alex Brachet
67bd3c58c0 [X86] Add register definitions for cfi directives
Add {e,r}flags, {g,f}s.base registers so they can be referenced in cfi
directives,. They are not otherwise useable in any instructions,
but can be implicitly pushed to the stack like with pushf for
{e,r}flags.

Differential Revision: https://reviews.llvm.org/D141879
2023-01-19 14:10:31 +00:00
Amaury Séchet
7e5681cf29 [DAG] Peek through ZEXT/TRUNC in foldAddSubMasked1
Fix a regression in D141883

Depends on D141883

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D141884
2023-01-19 13:23:42 +00:00
Amaury Séchet
2826869d7b [DAG] Do not combine any_ext when we combine and into zext.
This transofrm loses information that can be useful for other transforms.

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D141883
2023-01-19 12:37:05 +00:00
icedrocket
a6e3027db7 [X86] Avoid converting u64 to f32 using x87 on Windows
The code below currently prints less accurate values only on Windows 32-bit. On Windows, the default precision control on x87 is only 53-bit, and FADD triggers rounding with that precision, so the final result may be less accurate. This revision avoids less accurate conversions by using library calls instead.

```

int main() {
    int64_t n = 0b0000000000111111111111111111111111011111111111111111111111111111;
    printf("%lld, %.0f, %.0f", n, (float)n, (float)(uint64_t)n);

    return 0;
}
```

Reviewed By: craig.topper, lebedev.ri

Differential Revision: https://reviews.llvm.org/D141074
2023-01-18 22:41:34 -08:00
Paul Kirth
557a5bc336 [codegen] Add StackFrameLayoutAnalysisPass
Issue #58168 describes the difficulty diagnosing stack size issues
identified by -Wframe-larger-than. For simple code, its easy to
understand the stack layout and where space is being allocated, but in
more complex programs, where code may be heavily inlined, unrolled, and
have duplicated code paths, it is no longer easy to manually inspect the
source program and understand where stack space can be attributed.

This patch implements a machine function pass that emits remarks with a
textual representation of stack slots, and also outputs any available
debug information to map source variables to those slots.

The new behavior can be used by adding `-Rpass-analysis=stack-frame-layout`
to the compiler invocation. Like other remarks the diagnostic
information can be saved to a file in a machine readable format by
adding -fsave-optimzation-record.

Fixes: #58168

Reviewed By: nickdesaulniers, thegameg

Differential Revision: https://reviews.llvm.org/D135488
2023-01-19 01:51:14 +00:00
Roman Lebedev
7460842fb2
[DAGCombiner] combineShuffleOfSplatVal(): don't assert that shuffle is non-undef
As per the test case from Steven Johnson in https://reviews.llvm.org/rGf8d9097168b7#1165311
we can indeed encounter such shuffles, that produce all-undef after folding,
before something else manages to optimize them away.
2023-01-18 18:45:08 +03:00
Nikita Popov
9ed2f14c87 [AsmParser] Remove typed pointer auto-detection
IR is now always parsed in opaque pointer mode, unless
-opaque-pointers=0 is explicitly given. There is no automatic
detection of typed pointers anymore.

The -opaque-pointers=0 option is added to any remaining IR tests
that haven't been migrated yet.

Differential Revision: https://reviews.llvm.org/D141912
2023-01-18 09:58:32 +01:00
Rahman Lavaee
3d6841b2b1 [Propeller] Use Fixed MBB ID instead of volatile MachineBasicBlock::Number.
Let Propeller use specialized IDs for basic blocks, instead of MBB number.

This allows optimizations not just prior to asm-printer, but throughout the entire codegen.
This patch only implements the functionality under the new `LLVM_BB_ADDR_MAP` version, but the old version is still being used. A later patch will change the used version.

####Background
Today Propeller uses machine basic block (MBB) numbers, which already exist, to map native assembly to machine IR.  This is done as follows.
    - Basic block addresses are captured and dumped into the `LLVM_BB_ADDR_MAP` section just before the AsmPrinter pass which writes out object files. This ensures that we have a mapping that is close to assembly.
    - Profiling mapping works by taking a virtual address of an instruction and looking up the `LLVM_BB_ADDR_MAP` section to find the MBB number it corresponds to.
    - While this works well today, we need to do better when we scale Propeller to target other Machine IR optimizations like spill code optimization.  Register allocation happens earlier in the Machine IR pipeline and we need an annotation mechanism that is valid at that point.
    - The current scheme will not work in this scenario because the MBB number of a particular basic block is not fixed and changes over the course of codegen (via renumbering, adding, and removing the basic blocks).
    - In other words, the volatile MBB numbers do not provide a one-to-one correspondence throughout the lifetime of Machine IR.  Profile annotation using MBB numbers is restricted to a fixed point; only valid at the exact point where it was dumped.
    - Further, the object file can only be dumped before AsmPrinter and cannot be dumped at an arbitrary point in the Machine IR pass pipeline.  Hence, MBB numbers are not suitable and we need something else.
####Solution
We propose using fixed unique incremental MBB IDs for basic blocks instead of volatile MBB numbers. These IDs are assigned upon the creation of machine basic blocks. We modify `MachineFunction::CreateMachineBasicBlock` to assign the fixed ID to every newly created basic block.  It assigns `MachineFunction::NextMBBID` to the MBB ID and then increments it, which ensures having unique IDs.

 To ensure correct profile attribution, multiple equivalent compilations must generate the same Propeller IDs. This is guaranteed as long as the MachineFunction passes run in the same order. Since the `NextBBID` variable is scoped to `MachineFunction`, interleaving of codegen for different functions won't cause any inconsistencies.

The new encoding is generated under the new version number 2 and we keep backward-compatibility with older versions.

####Impact on Size of the `LLVM_BB_ADDR_MAP` Section
Emitting the Propeller ID results in a 23% increase in the size of the `LLVM_BB_ADDR_MAP` section for the clang binary.

Reviewed By: tmsriram

Differential Revision: https://reviews.llvm.org/D100808
2023-01-17 15:25:29 -08:00
Noah Goldstein
ca5d11751e Add additional tests for ctlz{_zero_undef} to test folding with xor; NFC
Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D141549
2023-01-17 11:04:26 -08:00
Noah Goldstein
0b74e34938 Transform AtomicRMW logic operations to BT{R|C|S} if only changing/testing a single bit.
This is essentially expanding on the optimizations added on: D120199
but applies the optimization to cases where the bit being changed /
tested is not am IMM but is a provable power of 2.

The only case currently added for cases like:
`__atomic_fetch_xor(p, 1 << c, __ATOMIC_RELAXED) & (1 << c)`

Which instead of using a `cmpxchg` loop can be done with `btcl; setcc; shl`.

There are still a variety of missed cases that could/should be
addressed in the future. This commit documents many of those
cases with Todos.

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D140939
2023-01-16 22:05:47 -08:00
Noah Goldstein
282d5a5b06 Add tests for BMI patterns across non-adjacent and assosiative instructions.
I.e for blsi match (and (sub 0, x), x) but we currently miss valid
patterns like (and (and (sub 0, x), y), x).

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D141178
2023-01-16 22:05:47 -08:00
James Y Knight
06210d50c0 ExceptionHandling documentation tweaks.
Delete mention of the llvm.eh.begincatch/llvm.eh.endcatch intrinsics,
and remove them from a few remaining test-cases. These intrinsics were
from a previous attempt at implementing Windows exception-handling,
but were removed from LLVM in 2015.

Also mention that dynamic exception specifications ("throw filters")
were removed from the spec in C++17.
2023-01-16 20:36:09 -05:00
Luo, Yuanke
159cac50cf [X86] Don't fold select for vXi1 on X86 target.
Since there is no mask instruction for vXi1 with avx512f in X86 target.
Folding select for vXi1 doesn't help to reduce instructions.

Differential Revision: https://reviews.llvm.org/D141782
2023-01-17 08:00:41 +08:00
Freddy Ye
db711f79ef [X86] Prefer fpext(splat(X)) to splat(fpext(x)).
This patch is to fix regression of D122875. X86 has fpext instructions
supporting rmb form, which takes advantage of fpext(fplat(X)) than
splat(fpext(X)).

Reviewed By: RKSimon, skan

Differential Revision: https://reviews.llvm.org/D141657
2023-01-16 22:48:30 +08:00
Luo, Yuanke
659e1b7bb0 [X86] Add more test case for folding select on vXi1 2023-01-16 22:25:59 +08:00
Amaury Séchet
396ad408fd [DAG] Recombine (binop (shift x y))
This helps address regressions in D127115 .

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D141809
2023-01-16 02:20:29 +00:00
Freddy Ye
2d73295c43 [X86] Add AVX512FP16 test coverage to splat(fpext) tests. 2023-01-16 10:19:19 +08:00
Roman Lebedev
0069255976
[NFC][X86] Improve test coverage for shuffles-of-shifts 2023-01-16 02:07:19 +03:00
Roman Lebedev
e8e5ec1612
[NFC][X86] Add tests for splat-in-disguise of shift-by-imm of splat 2023-01-16 00:02:20 +03:00
Roman Lebedev
f8d9097168
[DAGCombiner] combineShuffleOfSplatVal(): try to canonicalize to a splat shuffle
As noted in https://reviews.llvm.org/D141778#inline-1369900,
we fail to produce splat shuffles from certain sequences
of shuffles, that may have non-shuffles in the middle of seq.

There is a big pitfail to avoid here: just because `isSplatValue()`
says that all demanded elements are splat, we can't pick any random
one of them, because some of them could be undef! We must ignore those!
2023-01-15 21:11:33 +03:00
Roman Lebedev
1500e55910
[NFC][X86] Ensure we don't manage to produce broadcast-from-mem in subvec splat-store tests
https://godbolt.org/z/jfx8jvPba
2023-01-15 17:22:55 +03:00
Roman Lebedev
83f66e2d81
[NFC][X86] Add subvector splat-store tests
https://godbolt.org/z/oGn7KqrKs
2023-01-15 16:51:23 +03:00
Luo, Yuanke
d8a2b29529 [X86] Add test case for folding select on vXi1 2023-01-15 13:12:01 +08:00
Roman Lebedev
a64846bee0
[NFC][X86][Codegen] Extend tests for splat-storing the same scalar to memory
Looking at the changes, we might or might not care about the vector width

https://godbolt.org/z/7zfzThnYG
2023-01-15 04:34:37 +03:00
Roman Lebedev
0810af7208
[NFC][X86][Codegen] Add tests for splat-storing the same scalar to memory 2023-01-15 03:50:13 +03:00
Simon Pilgrim
471facf546 [X86] Add absolute-difference vector tests
X86 doesn't have absdiff instructions, but we should be able to canonicalize to avoid unnecessary scalarization/extensions/selects
2023-01-14 21:33:58 +00:00
Simon Pilgrim
c9e23187cb [X86] Add absolute-difference scalar tests
X86 doesn't have absdiff instructions, but we should be able to canonicalize to avoid unnecessary extensions/selects
2023-01-14 21:33:58 +00:00