[PATCH] D98082: [gvn] Precisely propagate equalities to phi operands
Philip Reames via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 8 08:59:21 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG97a7bc583115: [gvn] Precisely propagate equalities to phi operands (authored by reames).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D98082/new/
https://reviews.llvm.org/D98082
Files:
llvm/include/llvm/IR/Dominators.h
llvm/lib/IR/Dominators.cpp
llvm/lib/Transforms/Utils/Local.cpp
llvm/test/Transforms/GVN/phi.ll
Index: llvm/test/Transforms/GVN/phi.ll
===================================================================
--- llvm/test/Transforms/GVN/phi.ll
+++ llvm/test/Transforms/GVN/phi.ll
@@ -37,10 +37,8 @@
; CHECK: untaken:
; CHECK-NEXT: br label [[MERGE]]
; CHECK: merge:
-; CHECK-NEXT: [[PHI1:%.*]] = phi i64 [ [[A]], [[TAKEN]] ], [ [[B:%.*]], [[UNTAKEN]] ]
-; CHECK-NEXT: [[PHI2:%.*]] = phi i64 [ 0, [[TAKEN]] ], [ [[B]], [[UNTAKEN]] ]
-; CHECK-NEXT: [[RET:%.*]] = sub i64 [[PHI1]], [[PHI2]]
-; CHECK-NEXT: ret i64 [[RET]]
+; CHECK-NEXT: [[PHI1:%.*]] = phi i64 [ 0, [[TAKEN]] ], [ [[B:%.*]], [[UNTAKEN]] ]
+; CHECK-NEXT: ret i64 0
;
br i1 %c, label %taken, label %untaken
taken:
@@ -134,8 +132,7 @@
; CHECK: untaken:
; CHECK-NEXT: br label [[MERGE]]
; CHECK: merge:
-; CHECK-NEXT: [[PHI:%.*]] = phi i64 [ [[A]], [[TAKEN]] ], [ 0, [[UNTAKEN]] ]
-; CHECK-NEXT: ret i64 [[PHI]]
+; CHECK-NEXT: ret i64 0
;
br i1 %c, label %taken, label %untaken
taken:
@@ -159,8 +156,7 @@
; CHECK: untaken:
; CHECK-NEXT: br label [[MERGE]]
; CHECK: merge:
-; CHECK-NEXT: [[PHI:%.*]] = phi i64 [ [[A]], [[TAKEN]] ], [ 0, [[UNTAKEN]] ]
-; CHECK-NEXT: ret i64 [[PHI]]
+; CHECK-NEXT: ret i64 0
;
br i1 %c, label %taken, label %untaken
taken:
Index: llvm/lib/Transforms/Utils/Local.cpp
===================================================================
--- llvm/lib/Transforms/Utils/Local.cpp
+++ llvm/lib/Transforms/Utils/Local.cpp
@@ -2683,11 +2683,10 @@
unsigned llvm::replaceDominatedUsesWith(Value *From, Value *To,
DominatorTree &DT,
const BasicBlock *BB) {
- auto ProperlyDominates = [&DT](const BasicBlock *BB, const Use &U) {
- auto *I = cast<Instruction>(U.getUser())->getParent();
- return DT.properlyDominates(BB, I);
+ auto Dominates = [&DT](const BasicBlock *BB, const Use &U) {
+ return DT.dominates(BB, U);
};
- return ::replaceDominatedUsesWith(From, To, BB, ProperlyDominates);
+ return ::replaceDominatedUsesWith(From, To, BB, Dominates);
}
bool llvm::callsGCLeafFunction(const CallBase *Call,
Index: llvm/lib/IR/Dominators.cpp
===================================================================
--- llvm/lib/IR/Dominators.cpp
+++ llvm/lib/IR/Dominators.cpp
@@ -112,6 +112,16 @@
PAC.preservedSet<CFGAnalyses>());
}
+bool DominatorTree::dominates(const BasicBlock *BB, const Use &U) const {
+ Instruction *UserInst = cast<Instruction>(U.getUser());
+ if (auto *PN = dyn_cast<PHINode>(UserInst))
+ // A phi use using a value from a block is dominated by the end of that
+ // block. Note that the phi's parent block may not be.
+ return dominates(BB, PN->getIncomingBlock(U));
+ else
+ return properlyDominates(BB, UserInst->getParent());
+}
+
// dominates - Return true if Def dominates a use in User. This performs
// the special checks necessary if Def and User are in the same basic block.
// Note that Def doesn't dominate a use in Def itself!
Index: llvm/include/llvm/IR/Dominators.h
===================================================================
--- llvm/include/llvm/IR/Dominators.h
+++ llvm/include/llvm/IR/Dominators.h
@@ -165,6 +165,9 @@
// Ensure base-class overloads are visible.
using Base::dominates;
+ /// Return true if the (end of the) basic block BB dominates the use U.
+ bool dominates(const BasicBlock *BB, const Use &U) const;
+
/// Return true if value Def dominates use U, in the sense that Def is
/// available at U, and could be substituted as the used value without
/// violating the SSA dominance requirement.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98082.329039.patch
Type: text/x-patch
Size: 3691 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210308/730f0cc9/attachment.bin>
More information about the llvm-commits
mailing list