-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NFCI][PromoteMem2Reg] Don't handle the first successor out of order #142464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NFCI][PromoteMem2Reg] Don't handle the first successor out of order #142464
Conversation
Created using spr 1.3.6
Created using spr 1.3.6 [skip ci]
@llvm/pr-subscribers-llvm-transforms Author: Vitaly Buka (vitalybuka) ChangesAdditionally handler successors in regular order, so that two successors Additionally reverse order here results in more Full diff: https://github.com/llvm/llvm-project/pull/142464.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
index d84b07bd1457c..62995e57b917c 100644
--- a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -1215,24 +1215,22 @@ void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred,
}
// 'Recurse' to our successors.
- succ_iterator I = succ_begin(BB), E = succ_end(BB);
- if (I == E)
- return;
// Keep track of the successors so we don't visit the same successor twice
SmallPtrSet<BasicBlock *, 8> VisitedSuccs;
- // Handle the first successor after the rest, to mimic legacy behaviour.
- // FIXME: Handle them in regular order.
- VisitedSuccs.insert(*I);
- ++I;
-
- for (; I != E; ++I)
- if (VisitedSuccs.insert(*I).second)
- Worklist.emplace_back(*I, BB, IncomingVals, IncomingLocs);
-
- Worklist.emplace_back(*succ_begin(BB), BB, std::move(IncomingVals),
- std::move(IncomingLocs));
+ for (BasicBlock *S : reverse(successors(BB)))
+ if (VisitedSuccs.insert(S).second) {
+ if (VisitedSuccs.size() == 1) {
+ // Let the first successor to own allocated arrays.
+ Worklist.emplace_back(S, BB, std::move(IncomingVals),
+ std::move(IncomingLocs));
+ } else {
+ // Other successors have to make a copy.
+ Worklist.emplace_back(S, BB, Worklist.back().Values,
+ Worklist.back().Locations);
+ }
+ }
}
void llvm::PromoteMemToReg(ArrayRef<AllocaInst *> Allocas, DominatorTree &DT,
diff --git a/llvm/test/Transforms/InstCombine/2009-02-20-InstCombine-SROA.ll b/llvm/test/Transforms/InstCombine/2009-02-20-InstCombine-SROA.ll
index b532c81556738..ef414885bf809 100644
--- a/llvm/test/Transforms/InstCombine/2009-02-20-InstCombine-SROA.ll
+++ b/llvm/test/Transforms/InstCombine/2009-02-20-InstCombine-SROA.ll
@@ -215,7 +215,7 @@ define ptr @_Z3fooRSt6vectorIiSaIiEE(ptr %X) {
; IC_SROA-NEXT: [[TMP27:%.*]] = getelementptr i8, ptr [[__FIRST_ADDR_I_I_SROA_0_0]], i32 4
; IC_SROA-NEXT: br label [[BB18_I_I]]
; IC_SROA: bb18.i.i:
-; IC_SROA-NEXT: [[__FIRST_ADDR_I_I_SROA_0_1:%.*]] = phi ptr [ [[TMP27]], [[BB17_I_I]] ], [ [[__FIRST_ADDR_I_I_SROA_0_0]], [[BB13_I_I]] ]
+; IC_SROA-NEXT: [[__FIRST_ADDR_I_I_SROA_0_1:%.*]] = phi ptr [ [[__FIRST_ADDR_I_I_SROA_0_0]], [[BB13_I_I]] ], [ [[TMP27]], [[BB17_I_I]] ]
; IC_SROA-NEXT: [[TMP28:%.*]] = load i32, ptr [[__FIRST_ADDR_I_I_SROA_0_1]], align 4
; IC_SROA-NEXT: [[TMP29:%.*]] = icmp eq i32 [[TMP28]], 42
; IC_SROA-NEXT: br i1 [[TMP29]], label [[BB20_I_I:%.*]], label [[BB21_I_I:%.*]]
@@ -225,7 +225,7 @@ define ptr @_Z3fooRSt6vectorIiSaIiEE(ptr %X) {
; IC_SROA-NEXT: [[TMP30:%.*]] = getelementptr i8, ptr [[__FIRST_ADDR_I_I_SROA_0_1]], i32 4
; IC_SROA-NEXT: br label [[BB22_I_I]]
; IC_SROA: bb22.i.i:
-; IC_SROA-NEXT: [[__FIRST_ADDR_I_I_SROA_0_2:%.*]] = phi ptr [ [[TMP30]], [[BB21_I_I]] ], [ [[__FIRST_ADDR_I_I_SROA_0_0]], [[BB13_I_I]] ]
+; IC_SROA-NEXT: [[__FIRST_ADDR_I_I_SROA_0_2:%.*]] = phi ptr [ [[__FIRST_ADDR_I_I_SROA_0_0]], [[BB13_I_I]] ], [ [[TMP30]], [[BB21_I_I]] ]
; IC_SROA-NEXT: [[TMP31:%.*]] = load i32, ptr [[__FIRST_ADDR_I_I_SROA_0_2]], align 4
; IC_SROA-NEXT: [[TMP32:%.*]] = icmp eq i32 [[TMP31]], 42
; IC_SROA-NEXT: br i1 [[TMP32]], label [[BB24_I_I:%.*]], label [[BB25_I_I:%.*]]
|
Additionally handler successors in regular order, so that two successors cases are handled exactly as before, so we need to less tests. Additionally reverse order here results in more natural 'phi' arguments list order. Pull Request: llvm#142464
Additionally handler successors in regular order, so that two successors cases are handled exactly as before, so we need to less tests. Additionally reverse order here results in more natural 'phi' arguments list order. Pull Request: llvm#142464
Additionally handler successors in regular order, so that two successors cases are handled exactly as before, so we need to less tests. Additionally reverse order here results in more natural 'phi' arguments list order. Pull Request: llvm#142464
Additionally handler successors in regular order, so that two successors cases are handled exactly as before, so we need to less tests. Additionally reverse order here results in more natural 'phi' arguments list order. Pull Request: llvm#142464
Created using spr 1.3.6 [skip ci]
Created using spr 1.3.6
Created using spr 1.3.6 [skip ci]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Created using spr 1.3.6 [skip ci]
Additionally handler successors in regular order, so that two successors cases are handled exactly as before, so we need to less tests. Additionally reverse order here results in more natural 'phi' arguments list order. Pull Request: llvm#142464
…lvm#142464) Just for consistency, to avoid confusing conditions. `reverse` helps to avoid tests updates as nothing is changing for for successors count <=2. For llvm#142461
…lvm#142464) Just for consistency, to avoid confusing conditions. `reverse` helps to avoid tests updates as nothing is changing for for successors count <=2. For llvm#142461
Just for consistency, to avoid confusing conditions.
reverse
helps to avoid tests updates as nothing ischanging for for successors count <=2.
For #142461