aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
authorluxufan <luxufan@iscas.ac.cn>2023-02-01 14:10:57 +0800
committerluxufan <luxufan@iscas.ac.cn>2023-02-02 14:25:13 +0800
commit232698dc171ed7e3639db4a18e6d1abfba89f68b (patch)
treebf399b70978eb8752758ab6c67169dd4464179d6 /llvm/lib/Transforms/Utils/Local.cpp
parentd6f1c85edb36e789307ceebcba6e096bd7f958a7 (diff)
downloadllvm-232698dc171ed7e3639db4a18e6d1abfba89f68b.zip
llvm-232698dc171ed7e3639db4a18e6d1abfba89f68b.tar.gz
llvm-232698dc171ed7e3639db4a18e6d1abfba89f68b.tar.bz2
[Local][InstCombine][GVN] Handle !noundef metadata in combineMetadata
Handle !noundef metadata in comhineMetadata. The behavior of violating !noundef metadata is undefined behavior. So if K dominates J, we can preserve it uncontionally, otherwise, we preserve it if both K and J have !noundef metadata been set. This patch also makes !noundef metadata added in KnownIDs when doing instruction combine for phi node or global value numbering for loads. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D142801
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index b6c6c5a..624907a 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -2713,6 +2713,11 @@ void llvm::combineMetadata(Instruction *K, const Instruction *J,
case LLVMContext::MD_preserve_access_index:
// Preserve !preserve.access.index in K.
break;
+ case LLVMContext::MD_noundef:
+ // If K does move, keep noundef if it is present in both instructions.
+ if (DoesKMove)
+ K->setMetadata(Kind, JMD);
+ break;
}
}
// Set !invariant.group from J if J has it. If both instructions have it
@@ -2819,7 +2824,8 @@ void llvm::patchReplacementInstruction(Instruction *I, Value *Repl) {
LLVMContext::MD_noalias, LLVMContext::MD_range,
LLVMContext::MD_fpmath, LLVMContext::MD_invariant_load,
LLVMContext::MD_invariant_group, LLVMContext::MD_nonnull,
- LLVMContext::MD_access_group, LLVMContext::MD_preserve_access_index};
+ LLVMContext::MD_access_group, LLVMContext::MD_preserve_access_index,
+ LLVMContext::MD_noundef};
combineMetadata(ReplInst, I, KnownIDs, false);
}