aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorNuno Lopes <nuno.lopes@tecnico.ulisboa.pt>2022-01-26 10:10:22 +0000
committerNuno Lopes <nuno.lopes@tecnico.ulisboa.pt>2022-01-26 10:19:18 +0000
commit24a49e99f386432fc6fa46faf6e2ba91cfaed2df (patch)
tree00c5928341af30990408cfcea8799d14befcbecf /llvm/lib
parent66c602be25c15ca69f6c3a618427ba0237c0d4a9 (diff)
downloadllvm-24a49e99f386432fc6fa46faf6e2ba91cfaed2df.zip
llvm-24a49e99f386432fc6fa46faf6e2ba91cfaed2df.tar.gz
llvm-24a49e99f386432fc6fa46faf6e2ba91cfaed2df.tar.bz2
[NewGVN] FIx phi-of-ops in the presence of memory read operations
The phi-of-ops functionality has a function OpIsSafeForPHIOfOps to determine when it's safe to create the new phi. But this function only checks for the obvious dominator conditions and ignores memory. This patch takes the conservative approach and disables phi-of-ops whenever there's a load that doesn't dominate the phi, as its value may be affected by a store inside the loop. This can be improved later to check aliasing between the load/stores. Fixes https://llvm.org/PR53277 Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D117999
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/NewGVN.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp
index 6890ad38..2476e6c4 100644
--- a/llvm/lib/Transforms/Scalar/NewGVN.cpp
+++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp
@@ -2587,6 +2587,15 @@ bool NewGVN::OpIsSafeForPHIOfOpsHelper(
}
auto *OrigI = cast<Instruction>(V);
+ // When we hit an instruction that reads memory (load, call, etc), we must
+ // consider any store that may happen in the loop. For now, we assume the
+ // worst: there is a store in the loop that alias with this read.
+ // The case where the load is outside the loop is already covered by the
+ // dominator check above.
+ // TODO: relax this condition
+ if (OrigI->mayReadFromMemory())
+ return false;
+
for (auto *Op : OrigI->operand_values()) {
if (!isa<Instruction>(Op))
continue;