[PATCH] D80319: [LICM] Allow movement of non-aliasing calls that at most only write to memory
Alina Sbirlea via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 20 23:58:56 PDT 2020
asbirlea added a comment.
Let's take the examples below, same scenario.
If `@foo2e` writes 2 to str, and `@foo2f` reads, increments by 1 and writes back, and the loop runs 3 times.
Code below gives result 3. When `@foo2e` is hoisted, the result is 5.
At the very least you need to check `pointerInvalidatedByLoop` for all call args.
declare void @foo2e(i8*) argmemonly writeonly nounwind
declare void @foo2f(i8*) nounwind
entry:
%mem = call noalias i8* @malloc()
%str = getelementptr inbounds [4 x i8], [4 x i8]* @str, i64 0, i64 0
br label %loop
loop:
call void @foo2e(i8* %mem)
call void @foo2f(i8* %mem)
br i1 %c, label %loop, label %out
out:
ret void
For inaccessible memory, if two of the calls inside the loop write to that same inaccessible memory location, and one meets the condition to hoist, while the other also reads, then it's legal to hoist one of them?
`@foo2e` always writes 2 to that location.
`@foo2f` reads that location, increments by 1 and writes it back.
With an iteration count of 3, the original code will hold 3 at that location. After hoisting it will hold 5.
declare void @foo2e() inaccessiblemem writeonly nounwind
declare void @foo2f() nounwind
entry:
%mem = call noalias i8* @malloc()
%str = getelementptr inbounds [4 x i8], [4 x i8]* @str, i64 0, i64 0
br label %loop
loop:
call void @foo2e()
call void @foo2f()
br i1 %c, label %loop, label %out
out:
ret void
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