summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2019-03-07 06:38:03 +0000
committerFangrui Song <maskray@google.com>2019-03-07 06:38:03 +0000
commitb0f764c73732958745f13e5310131d0e7c3fa400 (patch)
treeafc613d03a28ac1d00ed62026c307ae84defdc43 /llvm/lib/Transforms
parent3acc4236b8717bf493b81905194a10e71f526702 (diff)
downloadbcm5719-llvm-b0f764c73732958745f13e5310131d0e7c3fa400.tar.gz
bcm5719-llvm-b0f764c73732958745f13e5310131d0e7c3fa400.zip
[BDCE] Optimize find+insert with early insert
llvm-svn: 355583
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/BDCE.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Scalar/BDCE.cpp b/llvm/lib/Transforms/Scalar/BDCE.cpp
index 7ada9f5ab7f..9bd387c33e8 100644
--- a/llvm/lib/Transforms/Scalar/BDCE.cpp
+++ b/llvm/lib/Transforms/Scalar/BDCE.cpp
@@ -41,14 +41,17 @@ static void clearAssumptionsOfUsers(Instruction *I, DemandedBits &DB) {
"Trivializing a non-integer value?");
// Initialize the worklist with eligible direct users.
+ SmallPtrSet<Instruction *, 16> Visited;
SmallVector<Instruction *, 16> WorkList;
for (User *JU : I->users()) {
// If all bits of a user are demanded, then we know that nothing below that
// in the def-use chain needs to be changed.
auto *J = dyn_cast<Instruction>(JU);
if (J && J->getType()->isIntOrIntVectorTy() &&
- !DB.getDemandedBits(J).isAllOnesValue())
+ !DB.getDemandedBits(J).isAllOnesValue()) {
+ Visited.insert(J);
WorkList.push_back(J);
+ }
// Note that we need to check for non-int types above before asking for
// demanded bits. Normally, the only way to reach an instruction with an
@@ -61,7 +64,6 @@ static void clearAssumptionsOfUsers(Instruction *I, DemandedBits &DB) {
}
// DFS through subsequent users while tracking visits to avoid cycles.
- SmallPtrSet<Instruction *, 16> Visited;
while (!WorkList.empty()) {
Instruction *J = WorkList.pop_back_val();
@@ -72,13 +74,11 @@ static void clearAssumptionsOfUsers(Instruction *I, DemandedBits &DB) {
// 1. llvm.assume demands its operand, so trivializing can't change it.
// 2. range metadata only applies to memory accesses which demand all bits.
- Visited.insert(J);
-
for (User *KU : J->users()) {
// If all bits of a user are demanded, then we know that nothing below
// that in the def-use chain needs to be changed.
auto *K = dyn_cast<Instruction>(KU);
- if (K && !Visited.count(K) && K->getType()->isIntOrIntVectorTy() &&
+ if (K && Visited.insert(K).second && K->getType()->isIntOrIntVectorTy() &&
!DB.getDemandedBits(K).isAllOnesValue())
WorkList.push_back(K);
}
OpenPOWER on IntegriCloud