312 Commits

Author SHA1 Message Date
Paul Walker
900bea9b1c [LLVM][test] Convert remaining instances of ConstantExpr based splats to use splat().
This is mostly NFC but some output does change due to consistently
inserting into poison rather than undef and using i64 as the index
type for inserts.
2024-02-27 13:37:23 +00:00
Nikita Popov
2d69827c5c [Transforms] Convert tests to opaque pointers (NFC) 2024-02-05 11:57:34 +01:00
Philip Reames
42d6eb5475
[MemCpyOpt] Handle scalable aggregate types in memmove/memset formation (#80487)
Without this change, the included test cases crash the compiler. I
believe this is fallout from the homogenous scalable struct work from a
while back; I think we just forgot to update this case.

Likely to fix https://github.com/llvm/llvm-project/issues/80463.
2024-02-02 18:47:18 -08:00
Shilei Tian
7e956ca88a [NFC][AMDGPU] Require x86-registered-target for llvm/test/Transforms/MemCpyOpt/no-libcalls.ll
The test sets `-mtriple=x86_64` but doesn't require it. This can cause issue on
non-x86 system.
2024-01-09 14:42:38 -05:00
Nikita Popov
bf5d96c96c
[IR] Add dead_on_unwind attribute (#74289)
Add the `dead_on_unwind` attribute, which states that the caller will
not read from this argument if the call unwinds. This allows eliding
stores that could otherwise be visible on the unwind path, for example:

```
declare void @may_unwind()

define void @src(ptr noalias dead_on_unwind %out) {
    store i32 0, ptr %out
    call void @may_unwind()
    store i32 1, ptr %out
    ret void
}

define void @tgt(ptr noalias dead_on_unwind %out) {
    call void @may_unwind()
    store i32 1, ptr %out
    ret void
}
```

The optimization is not valid without `dead_on_unwind`, because the `i32
0` value might be read if `@may_unwind` unwinds.

This attribute is primarily intended to be used on sret arguments. In
fact, I previously wanted to change the semantics of sret to include
this "no read after unwind" property (see D116998), but based on the
feedback there it is better to keep these attributes orthogonal (sret is
an ABI attribute, dead_on_unwind is an optimization attribute). This is
a reboot of that change with a separate attribute.
2023-12-14 09:58:14 +01:00
Wang Pengcheng
6aa6ef73ec
[MemCpyOpt] Don't perform call slot opt if alloc type is scalable (#75027)
This fixes #75010.
2023-12-11 19:45:13 +08:00
Jeremy Morse
d2d9dc8eb4
[DebugInfo][RemoveDIs] Make debugify pass convert to/from RemoveDIs mode (#73251)
Debugify is extremely useful as a testing and debugging tool, and a good
number of LLVM-IR transform tests use it. We need it to support "new"
non-instruction debug-info to get test coverage, but it's not important
enough to completely convert right now (and it'd be a large
undertaking). Thus: convert to/from dbg.value/DPValue mode on entry and
exit of the pass, which gives us the functionality without any further
work. The cost is compile-time, but again this is only happening during
tests.

Tested by: the large set of debugify tests enabled here. Note the
InstCombine test (cast-mul-select.ll) that hasn't been fully enabled:
this is because there's a debug-info sinking piece of code there that
hasn't been instrumented.
2023-11-29 13:19:50 +00:00
Nikita Popov
369c9b791b
[MemCpyOpt] Require writable object during call slot optimization (#71542)
Call slot optimization may introduce writes to the destination object
that occur earlier than in the original function. We currently already
check that that the destination is dereferenceable and aligned, but we
do not make sure that it is writable. As such, we might introduce a
write to read-only memory, or introduce a data race.

Fix this by checking that the object is writable. For arguments, this is
indicated by the new writable attribute. Tests using
sret/dereferenceable are updated to use it.
2023-11-09 15:55:44 +01:00
Nikita Popov
5c3beb7b1e [MemCpyOpt] Handle memcpy marked as memory(none)
Fixes #71183.
2023-11-03 15:20:21 +01:00
DianQK
0c4f326d8b
[MemCpyOpt] Combine alias metadatas when replacing byval arguments (#70580)
Fixes #70578.
2023-10-29 16:07:55 +08:00
Alex Richardson
e39f6c1844 [opt] Infer DataLayout from triple if not specified
There are many tests that specify a target triple/CPU flags but no
DataLayout which can lead to IR being generated that has unusual
behaviour. This commit attempts to use the default DataLayout based
on the relevant flags if there is no explicit override on the command
line or in the IR file.

One thing that is not currently possible to differentiate from a missing
datalayout `target datalayout = ""` in the IR file since the current
APIs don't allow detecting this case. If it is considered useful to
support this case (instead of passing "-data-layout=" on the command
line), I can change IR parsers to track whether they have seen such a
directive and change the callback type.

Differential Revision: https://reviews.llvm.org/D141060
2023-10-26 12:07:37 -07:00
Kai Yan
df116d1dc4
[MemCpyOpt] Fix the invalid code modification for GEP (#68479)
Relocate the GEP modification to a later stage of the function
performCallSlotOptzn(), ensuring that the code remains unchanged if the
optimization fails.

Co-authored-by: aklkaiyan <aklkaiyan@tencent.com>
2023-10-09 12:54:16 +02:00
Craig Topper
689ace53a5
[MemCpyOptimizer] Support scalable vectors in performStackMoveO… (#67632)
…ptzn.

This changes performStackMoveOptzn to take a TypeSize instead of
uint64_t to avoid an implicit conversion when called from
processStoreOfLoad.

performStackMoveOptzn has been updated to allow scalable types in the
rest of its code.
2023-09-28 12:25:38 -07:00
DianQK
4e6e476329
[MemCpyOpt] Merge alias metadatas when replacing arguments (#67539)
Alias metadata may no longer be valid after replacing the call argument.
Fix this by merging it with the memcpy alias metadata.

This fixes a miscompilation encountered in
https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Failing.20tests.20when.20rustc.20is.20compiled.20with.201.20CGU.
2023-09-28 10:13:21 +02:00
Nikita Popov
d5c8b23b1e [MemCpyOpt] Add test for #67539 (NFC) 2023-09-28 09:44:05 +02:00
Kohei Asano
2a207128a7
[MemCpyOpt] move SrcAlloca to the entry if transformation is performed (#67226)
This is fixup for
https://github.com/llvm/llvm-project/pull/66618#discussion_r1328523770 .
This transformation checks whether allocas are static, if the
transformation is performed. This patch moves the SrcAlloca to the entry
of the BB when the optimization performed.
2023-09-26 16:27:34 +09:00
Kohei Asano
baf031a853
[MemCpyOpt] fix miscompile for non-dominated use of src alloca for stack-move optimization (#66618)
Stack-move optimization, the optimization that merges src and dest
alloca of the full-size copy, replaces all uses of the dest alloca with
src alloca. For safety, we needed to check all uses of the dest alloca
locations are dominated by src alloca, to be replaced. This PR adds the
check for that.

Fixes #65225
2023-09-18 21:29:10 +09:00
Nikita Popov
07460b6666 [MemCpyOpt] Avoid infinite loop in processMemSetMemCpyDependence (PR54983)
This adds an additional transform to drop zero-size memcpys, also in
the case where the size is only zero after instruction simplification.
The motivation is the case from PR54983 where the size is non-trivially
zero, and processMemSetMemCpyDependence() keeps trying to reduce the
memset size by zero bytes.

This fix it's not really principled. It only works on the premise that
if InstSimplify doesn't realize the size is zero, then AA also won't.

The principled approach would be to instead add a isKnownNonZero()
guard to the processMemSetMemCpyDependence() transform, but I
suspect that would render that optimization mostly useless (at least
it breaks all the existing test coverage -- worth noting that the
constant size case is also handled by DSE, so I think this transform
is primarily about the dynamic size case).

Fixes https://github.com/llvm/llvm-project/issues/54983.
Fixes https://github.com/llvm/llvm-project/issues/64886.

Differential Revision: https://reviews.llvm.org/D124078
2023-09-15 09:10:15 +02:00
khei4
7f3610ac69 Reapply "Revert "[MemCpyOpt] implement multi BB stack-move optimization"
This reverts commit efe8aa2e618122e8050af10cc5d6ad83f24ef557.

Differential Revision: https://reviews.llvm.org/D155406
2023-09-14 19:42:36 +09:00
Vitaly Buka
efe8aa2e61 Revert "Reapply "Revert "[MemCpyOpt] implement multi BB stack-move optimization""
Suspecting incorrect lifetime markers.

This reverts commit 3a1409f93da32bf626f76257e0aac71716f2f67e.
2023-09-07 11:14:19 -07:00
khei4
c4d37c35e1 [MemCpyOpt] fix false negative case and add it as a true positive case(NFC) 2023-08-30 11:18:26 +09:00
khei4
3a1409f93d Reapply "Revert "[MemCpyOpt] implement multi BB stack-move optimization"
This reverts commit e0f9cc71cb6f4eb2e1566177e05425c497759dc6.
Differential Revision: https://reviews.llvm.org/D155406
2023-08-29 19:40:29 +09:00
khei4
c652987dd9 [MemCpyOpt] remove test noises (NFC) 2023-08-29 17:24:36 +09:00
khei4
5a9a7f5303 [MemCpyOpt] add tests for unreachable cycles for post dominators(NFC) 2023-08-29 14:07:45 +09:00
khei4
98d1b0eb64 [MemCpyOpt] add tests for unreachable block before calculating common dominator(NFC) 2023-08-28 14:44:41 +09:00
Vitaly Buka
e0f9cc71cb Revert "Reapply "Revert "[MemCpyOpt] implement multi BB stack-move optimization"""
Breaks multiple bots. e.g. https://lab.llvm.org/buildbot/#/builders/19/builds/18856

This reverts commit ac0072602c9d01fc031a2d0acb418f7191480ef0.
2023-08-26 19:24:50 -07:00
khei4
ac0072602c Reapply "Revert "[MemCpyOpt] implement multi BB stack-move optimization""
This reverts commit 3bb32c61b2f1f5d14dd056dd198dc898dce5a44e.

Use InsertionPt for DT to handle non-memory access dominators

Differential Revision: https://reviews.llvm.org/D155406
2023-08-27 06:50:19 +09:00
khei4
fe285ae091 [NFC][MemCpyOpt] add test for MemoryAccess crash on D155406 2023-08-25 01:00:29 +09:00
khei4
3bb32c61b2 Revert "[MemCpyOpt] implement multi BB stack-move optimization"
This reverts commit ef867d2ea10e8246be20c608160e07a54eb2ed14.

crash on sanitizer build https://lab.llvm.org/buildbot/#/builders/70/builds/42861/steps/10/logs/stdio
2023-08-24 22:56:39 +09:00
khei4
ef867d2ea1 [MemCpyOpt] implement multi BB stack-move optimization
Differential Revision: https://reviews.llvm.org/D155406
2023-08-24 22:19:01 +09:00
khei4
e0911b98d1 [MemCpyOpt] precommit test for D155406 (NFC)
Differential Revision: https://reviews.llvm.org/D155422
2023-08-24 22:19:01 +09:00
khei4
ca68a7f956 Reapply: [MemCpyOpt] implement single BB stack-move optimization which unify the static unescaped allocas
This reverts commit 207718029e1e62d82145b479f6349941b6384045.
2023-08-15 22:13:09 +09:00
khei4
0b4f8c9fc4 (NFC)[MemCpyOpt] add a test to avoid crash for last memory use 2023-08-15 20:20:57 +09:00
Vitaly Buka
207718029e Revert "Reapply: [MemCpyOpt] implement single BB stack-move optimization which unify the static unescaped allocas"
Fails on https://lab.llvm.org/buildbot/#/builders/85/builds/18296

This reverts commit 43698c1ddc179ccd97b3f3b2bb03f4a3fe9556f3.
2023-08-13 16:29:39 -07:00
khei4
43698c1ddc Reapply: [MemCpyOpt] implement single BB stack-move optimization which unify the static unescaped allocas
Differential Revision: https://reviews.llvm.org/D153453

This reverts commit 00653889883f2d818536efcb21c6c8b739f0888b.
2023-08-13 21:38:00 +09:00
Matt Arsenault
25bc999d1f Intrinsics: Add type overload to stacksave and stackstore
This allows use with non-0 address space stacks. llvm_ptr_ty should
never be used. This could use some more percolation up through mlir,
but this is enough to fix existing tests.

https://reviews.llvm.org/D156666
2023-08-09 18:33:11 -04:00
khei4
90ecb9d5b0 [MemCpyOpt][test] add memssa verification on stack-move tests(NFC) 2023-08-08 18:56:59 +09:00
Vitaly Buka
df0b1df99c [test][MemCpyOpt] Update D153453 test 2023-08-02 23:05:32 -07:00
Vitaly Buka
2772c267ea [test][MemCpyOpt] Update D153453 test 2023-08-02 22:52:43 -07:00
Vitaly Buka
6ee9de7a67 [test][MemCpyOpt] Regression test for D153453 2023-08-02 13:48:27 -07:00
Vitaly Buka
0065388988 Revert "Reapply: [MemCpyOpt] implement single BB stack-move optimization which unify the static unescaped allocas"""
Breaks Asan and LTO.

This reverts commit ea72b5137eb72391ad192dbb01084c21b9fe8b71.
2023-08-02 12:32:35 -07:00
khei4
ea72b5137e Reapply: [MemCpyOpt] implement single BB stack-move optimization which unify the static unescaped allocas""
This reverts commit c9d419c1df72b0160e374f8d0b9f30508b3b98a7.
Differential Revision: https://reviews.llvm.org/D153453
2023-07-24 10:16:49 +09:00
khei4
d878916c21 [MemCpyOpt] add noalias metadata on lifetime intrinsic test case for stack-move optimization(NFC) 2023-07-23 00:18:33 +09:00
khei4
c9d419c1df Revert "Reapply: [MemCpyOpt] implement single BB stack-move optimization which unify the static unescaped allocas"
revert because crash on chrome windows https://reviews.llvm.org/D153453#4524256

This reverts commit 569769b64858fd38f41267db41b461d3163aa754.
2023-07-22 13:08:12 +09:00
khei4
569769b648 Reapply: [MemCpyOpt] implement single BB stack-move optimization which unify the static unescaped allocas
This reverts commit 8f3864ba4323a253bcf29825d23cd325b52c4106.
Differential Revision: https://reviews.llvm.org/D153453
2023-07-19 18:26:04 +09:00
khei4
bdc9a6b1e9 [MemCpyOpt] add terminator user test for D153453(NFC)
Differential Revision: https://reviews.llvm.org/D155571
2023-07-19 18:26:04 +09:00
khei4
8f3864ba43 Revert "Revert "Revert "[MemCpyOpt] implement single BB stack-move optimization which unify the static unescaped allocas"""
This reverts commit b02d349cbfaa81c9bbc928c4de46b12d976c1882.
2023-07-18 18:42:36 +09:00
khei4
b02d349cbf Revert "Revert "[MemCpyOpt] implement single BB stack-move optimization which unify the static unescaped allocas""
This reverts commit 36a6eb7d12a9f827bf3d5d4e5fdc68b8a62807b2.

[MemCpyOpt] check that load/store and dest/src alloca are all in the same bb

Differential Revision: https://reviews.llvm.org/D153453
Co-authored-by: serge-sans-paille <sguelton@mozilla.com>
2023-07-15 16:27:38 +09:00
khei4
a92e197114 [MemCpyOpt] precommit tests to add multi-BB stack-move optimization to check crash for D153453 (NFC)
Differential Revision: https://reviews.llvm.org/D155179
Co-authored-by: serge-sans-paille <sguelton@mozilla.com>
2023-07-15 16:27:38 +09:00
khei4
36a6eb7d12 Revert "[MemCpyOpt] implement single BB stack-move optimization which unify the static unescaped allocas"
This reverts commit 96ae0851c26237378fa1280b0a9ad713e1b72bdb.
2023-07-13 18:04:49 +09:00