296 Commits

Author SHA1 Message Date
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
khei4
96ae0851c2 [MemCpyOpt] implement single BB stack-move optimization which unify the static unescaped allocas
Differential Revision: https://reviews.llvm.org/D153453
2023-07-13 14:52:30 +09:00
khei4
393215649b [MemCpyOpt] precommit test to add single BB stack-move optimization (NFC)
Differential Revision: https://reviews.llvm.org/D152277
2023-07-13 14:52:30 +09: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
khei4
361464c027 [MemCpyOpt] Use memcpy source directly if dest is known to be immutable from attributes
Differential Revision: https://reviews.llvm.org/D150970
2023-06-10 15:46:32 +09:00
khei4
f0d97c30e9 [MemCpyOpt] precommit test for memcpy removal for immutable arguments from attributes (NFC)
Differential Revision: https://reviews.llvm.org/D150967
2023-06-10 15:46:32 +09:00
khei4
0ad88c156e [MemCpyOpt] remove byval from memcpy size crtical test(NFC)
Differential Revision: https://reviews.llvm.org/D151626
Reviewed By: nikic
2023-05-29 16:56:07 +09:00
Bjorn Pettersson
198e0a12f6 [MemCpyOpt] Fix up debug loc for simplified memset in processMemSetMemCpyDependence
Make sure the code comments in processMemSetMemCpyDependence match
with the actual transform. They indicated that the memset being
rewritten was sunk to after a memcpy, while it actually is inserted
just before the memcpy.

Also make sure we use the debug location of the original memset
when creating the new simplified memset. In the past we've been
using the debug location for the memcpy which could be a bit
confusing.

Differential Revision: https://reviews.llvm.org/D135574
2023-05-16 16:54:51 +02:00
Mikhail Maltsev
ab8150acc5 [MemCpyOpt] Don't fold memcpy.inline into memmove
The llvm.memcpy.inline intrinsic must be expanded into code that
does not contain any function calls because it is intended for
the implementation of low-level functions like memcpy. Currently the
MemCpyOpt might covert llvm.memcpy.inline into llvm.memmove in
certain circumstances. This patch fixes the issue.

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

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D147162
2023-03-30 13:14:59 +01:00
Owen Anderson
8256ddf78c Resolve a long-standing FIXME in memcpyopt.
Inspecting the downstream use of the cpyAlign, it is clear that
`performCallSlotOptzn` is expecting it to represent the alignment
of the copy destination, not the minimum of the src and dest
alignments. This patch renames the parameter to make this more
obvious.

I believe this change is NFC, because the downstream code has
alignment checks such that it all works out in the end. I have not
been able to construct a test case that actually triggers a change
in output.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D140603
2022-12-23 16:15:24 -07:00
Bjorn Pettersson
a11faeed44 [test] Switch to use -passes syntax in various test cases 2022-12-01 21:25:59 +01:00
Nikita Popov
4d33cf4166 [MemCpyOpt] Avoid moving lifetime marker above def (PR58903)
This is unlikely to happen with opaque pointers, so just bail out
of the transform, rather than trying to move bitcasts/etc as well.

Fixes https://github.com/llvm/llvm-project/issues/58903.
2022-11-11 15:06:34 +01:00
Nikita Popov
9a45e4beed [MemCpyOpt] Move lifetime marker before call to enable call slot optimization
Currently call slot optimization may be prevented because the
lifetime markers for the destination only start after the call.
In this case, rather than aborting the transform, we should move
the lifetime.start before the call to enable the transform.

Differential Revision: https://reviews.llvm.org/D135886
2022-11-07 15:26:00 +01:00
Bjorn Pettersson
211cf8a384 [test] Use -passes in more Transforms tests
Another step towards getting rid of dependencies to the legacy
pass manager.

Primary change here is to just do -passes=foo instead of -foo in
simple situations (when running a single transform pass). But also
updated a few test running multiple passes.

Also removed some "duplicated" RUN lines in a few tests that where
using both -foo and -passes=foo syntax. No need to do the same kind
of testing twice.
2022-10-21 17:02:02 +02:00
Nikita Popov
f386f7690d [MemCpyOpt] Add additional tests with lifetime intrinsics (NFC) 2022-10-13 17:29:59 +02:00
Nikita Popov
19aa1aab2e [MemCpyOpt] Don't run full pipeline in test (NFC)
Just memcpyopt is enough for this test.
2022-10-13 17:03:44 +02:00
Arthur Eubanks
f3a928e233 [opt] Don't translate legacy -analysis flag to require<analysis>
Tests relying on this should explicitly use -passes='require<analysis>,foo'.
2022-10-07 14:54:34 -07:00