Skip to content

Commit a124beb

Browse files
Diogo Sampaiozmodem
authored andcommitted
[ARM] Fix non-determenistic behaviour
Summary: ARM Type Promotion pass does not clear the container that defines if one variable was visited or not, missing optimization opportunities by luck when two llvm:Values from different functions are allocated at the same memory address. Also fixes a comment and uses existing method to pop and obtain last element of the worklist. Reviewers: samparker Reviewed By: samparker Subscribers: kristof.beyls, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D73970 (cherry picked from commit 8ba2b62)
1 parent 4ea0b39 commit a124beb

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

llvm/lib/CodeGen/TypePromotion.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -847,8 +847,7 @@ bool TypePromotion::TryToPromote(Value *V, unsigned PromotedWidth) {
847847

848848
// Iterate through, and add to, a tree of operands and users in the use-def.
849849
while (!WorkList.empty()) {
850-
Value *V = WorkList.back();
851-
WorkList.pop_back();
850+
Value *V = WorkList.pop_back_val();
852851
if (CurrentVisited.count(V))
853852
continue;
854853

@@ -917,7 +916,7 @@ bool TypePromotion::TryToPromote(Value *V, unsigned PromotedWidth) {
917916
++ToPromote;
918917
}
919918

920-
// DAG optimisations should be able to handle these cases better, especially
919+
// DAG optimizations should be able to handle these cases better, especially
921920
// for function arguments.
922921
if (ToPromote < 2 || (Blocks.size() == 1 && (NonFreeArgs > SafeWrap.size())))
923922
return false;
@@ -941,6 +940,9 @@ bool TypePromotion::runOnFunction(Function &F) {
941940
if (!TPC)
942941
return false;
943942

943+
AllVisited.clear();
944+
SafeToPromote.clear();
945+
SafeWrap.clear();
944946
bool MadeChange = false;
945947
const DataLayout &DL = F.getParent()->getDataLayout();
946948
const TargetMachine &TM = TPC->getTM<TargetMachine>();
@@ -998,6 +1000,10 @@ bool TypePromotion::runOnFunction(Function &F) {
9981000
if (MadeChange)
9991001
LLVM_DEBUG(dbgs() << "After TypePromotion: " << F << "\n");
10001002

1003+
AllVisited.clear();
1004+
SafeToPromote.clear();
1005+
SafeWrap.clear();
1006+
10011007
return MadeChange;
10021008
}
10031009

0 commit comments

Comments
 (0)