[PATCH] D80319: [LICM] Allow movement of calls that at most only write to memory
Dominic Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 20 22:34:00 PDT 2020
ddcc added a comment.
In D80319#2048052 <https://reviews.llvm.org/D80319#2048052>, @asbirlea wrote:
> 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.
The intention is that given a function which only writes the values of its inputs elsewhere in memory without aliasing, calls to that function can be hoisted because they will still execute at least once. But, I was missing some `noalias` checks on the arguments, which are now fixed, because not reading through the argument doesn't mean that the underlying memory can't be otherwise accessed.
In this testcase, `foo2c` (now `foo2d`) may only write to `str` because of the `writeonly` attribute, but it can't be hoisted because it may read elsewhere from memory.
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