From 39bbe179aa895bc63f1c26604e9cfcd92e60254c Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Tue, 7 Aug 2018 13:27:33 +0000 Subject: [PATCH] [GVN,NewGVN] Move patchReplacementInstruction to Utils/Local.h This function is shared between both implementations. I am not sure if Utils/Local.h is the best place though. Reviewers: davide, dberlin, efriedma, xbolva00 Reviewed By: efriedma, xbolva00 Differential Revision: https://reviews.llvm.org/D47337 llvm-svn: 339138 --- llvm/include/llvm/Transforms/Utils/Local.h | 4 +++ llvm/lib/Transforms/Scalar/GVN.cpp | 31 ---------------------- llvm/lib/Transforms/Scalar/NewGVN.cpp | 31 ---------------------- llvm/lib/Transforms/Utils/Local.cpp | 31 ++++++++++++++++++++++ 4 files changed, 35 insertions(+), 62 deletions(-) diff --git a/llvm/include/llvm/Transforms/Utils/Local.h b/llvm/include/llvm/Transforms/Utils/Local.h index b85ecaaee6a4..a5a0ca07a538 100644 --- a/llvm/include/llvm/Transforms/Utils/Local.h +++ b/llvm/include/llvm/Transforms/Utils/Local.h @@ -393,6 +393,10 @@ void combineMetadata(Instruction *K, const Instruction *J, ArrayRef Kn /// Unknown metadata is removed. void combineMetadataForCSE(Instruction *K, const Instruction *J); +/// Patch the replacement so that it is not more restrictive than the value +/// being replaced. +void patchReplacementInstruction(Instruction *I, Value *Repl); + // Replace each use of 'From' with 'To', if that use does not belong to basic // block where 'From' is defined. Returns the number of replacements made. unsigned replaceNonLocalUsesWith(Instruction *From, Value *To); diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp index 2b6d951344aa..d87c8e9b31ee 100644 --- a/llvm/lib/Transforms/Scalar/GVN.cpp +++ b/llvm/lib/Transforms/Scalar/GVN.cpp @@ -1444,37 +1444,6 @@ bool GVN::processAssumeIntrinsic(IntrinsicInst *IntrinsicI) { return Changed; } -static void patchReplacementInstruction(Instruction *I, Value *Repl) { - auto *ReplInst = dyn_cast(Repl); - if (!ReplInst) - return; - - // Patch the replacement so that it is not more restrictive than the value - // being replaced. - // Note that if 'I' is a load being replaced by some operation, - // for example, by an arithmetic operation, then andIRFlags() - // would just erase all math flags from the original arithmetic - // operation, which is clearly not wanted and not needed. - if (!isa(I)) - ReplInst->andIRFlags(I); - - // FIXME: If both the original and replacement value are part of the - // same control-flow region (meaning that the execution of one - // guarantees the execution of the other), then we can combine the - // noalias scopes here and do better than the general conservative - // answer used in combineMetadata(). - - // In general, GVN unifies expressions over different control-flow - // regions, and so we need a conservative combination of the noalias - // scopes. - static const unsigned KnownIDs[] = { - LLVMContext::MD_tbaa, LLVMContext::MD_alias_scope, - LLVMContext::MD_noalias, LLVMContext::MD_range, - LLVMContext::MD_fpmath, LLVMContext::MD_invariant_load, - LLVMContext::MD_invariant_group}; - combineMetadata(ReplInst, I, KnownIDs); -} - static void patchAndReplaceAllUsesWith(Instruction *I, Value *Repl) { patchReplacementInstruction(I, Repl); I->replaceAllUsesWith(Repl); diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp index 3e47e9441d15..4dfde3a22a0f 100644 --- a/llvm/lib/Transforms/Scalar/NewGVN.cpp +++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp @@ -3697,37 +3697,6 @@ void NewGVN::convertClassToLoadsAndStores( } } -static void patchReplacementInstruction(Instruction *I, Value *Repl) { - auto *ReplInst = dyn_cast(Repl); - if (!ReplInst) - return; - - // Patch the replacement so that it is not more restrictive than the value - // being replaced. - // Note that if 'I' is a load being replaced by some operation, - // for example, by an arithmetic operation, then andIRFlags() - // would just erase all math flags from the original arithmetic - // operation, which is clearly not wanted and not needed. - if (!isa(I)) - ReplInst->andIRFlags(I); - - // FIXME: If both the original and replacement value are part of the - // same control-flow region (meaning that the execution of one - // guarantees the execution of the other), then we can combine the - // noalias scopes here and do better than the general conservative - // answer used in combineMetadata(). - - // In general, GVN unifies expressions over different control-flow - // regions, and so we need a conservative combination of the noalias - // scopes. - static const unsigned KnownIDs[] = { - LLVMContext::MD_tbaa, LLVMContext::MD_alias_scope, - LLVMContext::MD_noalias, LLVMContext::MD_range, - LLVMContext::MD_fpmath, LLVMContext::MD_invariant_load, - LLVMContext::MD_invariant_group}; - combineMetadata(ReplInst, I, KnownIDs); -} - static void patchAndReplaceAllUsesWith(Instruction *I, Value *Repl) { patchReplacementInstruction(I, Repl); I->replaceAllUsesWith(Repl); diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index ab4170d1a9d2..9734e4ae18c1 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -2354,6 +2354,37 @@ void llvm::combineMetadataForCSE(Instruction *K, const Instruction *J) { combineMetadata(K, J, KnownIDs); } +void llvm::patchReplacementInstruction(Instruction *I, Value *Repl) { + auto *ReplInst = dyn_cast(Repl); + if (!ReplInst) + return; + + // Patch the replacement so that it is not more restrictive than the value + // being replaced. + // Note that if 'I' is a load being replaced by some operation, + // for example, by an arithmetic operation, then andIRFlags() + // would just erase all math flags from the original arithmetic + // operation, which is clearly not wanted and not needed. + if (!isa(I)) + ReplInst->andIRFlags(I); + + // FIXME: If both the original and replacement value are part of the + // same control-flow region (meaning that the execution of one + // guarantees the execution of the other), then we can combine the + // noalias scopes here and do better than the general conservative + // answer used in combineMetadata(). + + // In general, GVN unifies expressions over different control-flow + // regions, and so we need a conservative combination of the noalias + // scopes. + static const unsigned KnownIDs[] = { + LLVMContext::MD_tbaa, LLVMContext::MD_alias_scope, + LLVMContext::MD_noalias, LLVMContext::MD_range, + LLVMContext::MD_fpmath, LLVMContext::MD_invariant_load, + LLVMContext::MD_invariant_group}; + combineMetadata(ReplInst, I, KnownIDs); +} + template static unsigned replaceDominatedUsesWith(Value *From, Value *To, const RootType &Root,