[PATCH] D80319: [LICM] Allow movement of calls that at most only write to memory

Alina Sbirlea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 20 17:40:51 PDT 2020


asbirlea requested changes to this revision.
asbirlea added a comment.
This revision now requires changes to proceed.

Please check failing tests.

The idea does not seem right. If a call can only write and not read, it cannot necessarily be moved.

Your `test2()` example looks incorrect. If `foo2b` writes to `str` and `foo2c` reads from it and writes to it, then `foo2c` should read the value written inside the loop, which can be overwritten on different iterations.

Example:

- `foo2b` writes value 2 to str.
- `foo2c` reads value from `str`, increments by 1 and writes back.
- loop runs 3 times.

With `foo2b` inside the loop, final value in `str` is 3.
With `foo2b` outside the loop, final value in `str` is 5.

I did not look at `test1()`.



================
Comment at: llvm/lib/Transforms/Scalar/LICM.cpp:1178
       return true;
-    if (AliasAnalysis::onlyReadsMemory(Behavior)) {
+    } else if (AliasAnalysis::onlyReadsMemory(Behavior)) {
       // A readonly argmemonly function only reads from memory pointed to by
----------------
No reason to add the `else` when the `if` returns.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80319/new/

https://reviews.llvm.org/D80319





More information about the llvm-commits mailing list