[PATCH] D24170: Refactor replaceDominatedUsesWith to have a flag to control whether to replace uses in BB itself.
Dehao Chen via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 1 16:32:56 PDT 2016
danielcdh created this revision.
danielcdh added reviewers: chandlerc, davidxl.
danielcdh added a subscriber: llvm-commits.
This is in preparation for LoopSink pass which calls replaceDominatedUsesWith to update after sinking.
https://reviews.llvm.org/D24170
Files:
include/llvm/Transforms/Utils/Local.h
lib/Transforms/Scalar/GVN.cpp
lib/Transforms/Utils/Local.cpp
Index: lib/Transforms/Utils/Local.cpp
===================================================================
--- lib/Transforms/Utils/Local.cpp
+++ lib/Transforms/Utils/Local.cpp
@@ -1679,15 +1679,17 @@
unsigned llvm::replaceDominatedUsesWith(Value *From, Value *To,
DominatorTree &DT,
- const BasicBlock *BB) {
+ const BasicBlock *BB,
+ bool IncludeSelf) {
assert(From->getType() == To->getType());
unsigned Count = 0;
for (Value::use_iterator UI = From->use_begin(), UE = From->use_end();
UI != UE;) {
Use &U = *UI++;
auto *I = cast<Instruction>(U.getUser());
- if (DT.properlyDominates(BB, I->getParent())) {
+ if ((IncludeSelf && BB == I->getParent()) ||
+ DT.properlyDominates(BB, I->getParent())) {
U.set(To);
DEBUG(dbgs() << "Replace dominated use of '" << From->getName() << "' as "
<< *To << " in " << *U << "\n");
Index: lib/Transforms/Scalar/GVN.cpp
===================================================================
--- lib/Transforms/Scalar/GVN.cpp
+++ lib/Transforms/Scalar/GVN.cpp
@@ -1962,7 +1962,7 @@
unsigned NumReplacements =
DominatesByEdge
? replaceDominatedUsesWith(LHS, RHS, *DT, Root)
- : replaceDominatedUsesWith(LHS, RHS, *DT, Root.getStart());
+ : replaceDominatedUsesWith(LHS, RHS, *DT, Root.getStart(), false);
Changed |= NumReplacements > 0;
NumGVNEqProp += NumReplacements;
@@ -2038,7 +2038,7 @@
DominatesByEdge
? replaceDominatedUsesWith(NotCmp, NotVal, *DT, Root)
: replaceDominatedUsesWith(NotCmp, NotVal, *DT,
- Root.getStart());
+ Root.getStart(), false);
Changed |= NumReplacements > 0;
NumGVNEqProp += NumReplacements;
}
Index: include/llvm/Transforms/Utils/Local.h
===================================================================
--- include/llvm/Transforms/Utils/Local.h
+++ include/llvm/Transforms/Utils/Local.h
@@ -326,10 +326,12 @@
/// the given edge. Returns the number of replacements made.
unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
const BasicBlockEdge &Edge);
+
/// Replace each use of 'From' with 'To' if that use is dominated by
-/// the end of the given BasicBlock. Returns the number of replacements made.
+/// the end of 'BB'. Returns the number of replacements made.
+/// Replace use of 'From' with 'To' in 'BB' if 'IncludeSelf' is true.
unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
- const BasicBlock *BB);
+ const BasicBlock *BB, bool IncludeSelf);
/// Return true if the CallSite CS calls a gc leaf function.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24170.70095.patch
Type: text/x-patch
Size: 3028 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160901/1771c657/attachment.bin>
More information about the llvm-commits
mailing list