[llvm] r241809 - Don't rely on the DepCands iteration order when constructing checking pointer groups
Silviu Baranga
silviu.baranga at arm.com
Thu Jul 9 08:18:25 PDT 2015
Author: sbaranga
Date: Thu Jul 9 10:18:25 2015
New Revision: 241809
URL: http://llvm.org/viewvc/llvm-project?rev=241809&view=rev
Log:
Don't rely on the DepCands iteration order when constructing checking pointer groups
Summary:
The checking pointer group construction algorithm relied on the iteration on DepCands.
We would need the same leaders across runs and the same iteration order over the underlying std::set for determinism.
This changes the algorithm to process the pointers in the order in which they were added to the runtime check, which is deterministic.
We need to update the tests, since the order in which pointers appear has changed.
No new tests were added, since it is impossible to test for non-determinism.
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D11064
Modified:
llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp
llvm/trunk/test/Analysis/LoopAccessAnalysis/number-of-memchecks.ll
llvm/trunk/test/Analysis/LoopAccessAnalysis/unsafe-and-rt-checks.ll
Modified: llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp?rev=241809&r1=241808&r2=241809&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp Thu Jul 9 10:18:25 2015
@@ -222,18 +222,40 @@ void LoopAccessInfo::RuntimePointerCheck
for (unsigned Pointer = 0; Pointer < Pointers.size(); ++Pointer)
PositionMap[Pointers[Pointer]] = Pointer;
+ // We need to keep track of what pointers we've already seen so we
+ // don't process them twice.
+ SmallSet<unsigned, 2> Seen;
+
// Go through all equivalence classes, get the the "pointer check groups"
- // and add them to the overall solution.
- for (auto DI = DepCands.begin(), DE = DepCands.end(); DI != DE; ++DI) {
- if (!DI->isLeader())
+ // and add them to the overall solution. We use the order in which accesses
+ // appear in 'Pointers' to enforce determinism.
+ for (unsigned I = 0; I < Pointers.size(); ++I) {
+ // We've seen this pointer before, and therefore already processed
+ // its equivalence class.
+ if (Seen.count(I))
continue;
+ MemoryDepChecker::MemAccessInfo Access(Pointers[I], IsWritePtr[I]);
+
SmallVector<CheckingPtrGroup, 2> Groups;
+ auto LeaderI = DepCands.findValue(DepCands.getLeaderValue(Access));
- for (auto MI = DepCands.member_begin(DI), ME = DepCands.member_end();
+ SmallVector<unsigned, 2> MemberIndices;
+
+ // Get all indeces of the members of this equivalence class and sort them.
+ // This will allow us to process all accesses in the order in which they
+ // were added to the RuntimePointerCheck.
+ for (auto MI = DepCands.member_begin(LeaderI), ME = DepCands.member_end();
MI != ME; ++MI) {
unsigned Pointer = PositionMap[MI->getPointer()];
+ MemberIndices.push_back(Pointer);
+ }
+ std::sort(MemberIndices.begin(), MemberIndices.end());
+
+ for (unsigned Pointer : MemberIndices) {
bool Merged = false;
+ // Mark this pointer as seen.
+ Seen.insert(Pointer);
// Go through all the existing sets and see if we can find one
// which can include this pointer.
Modified: llvm/trunk/test/Analysis/LoopAccessAnalysis/number-of-memchecks.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/LoopAccessAnalysis/number-of-memchecks.ll?rev=241809&r1=241808&r2=241809&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/LoopAccessAnalysis/number-of-memchecks.ll (original)
+++ llvm/trunk/test/Analysis/LoopAccessAnalysis/number-of-memchecks.ll Thu Jul 9 10:18:25 2015
@@ -82,29 +82,29 @@ for.end:
; CHECK: Run-time memory checks:
; CHECK-NEXT: Check 0:
; CHECK-NEXT: Comparing group 0:
-; CHECK-NEXT: %arrayidxA1 = getelementptr inbounds i16, i16* %a, i64 %add
-; CHECK-NEXT: %arrayidxA = getelementptr inbounds i16, i16* %a, i64 %ind
-; CHECK-NEXT: Against group 2:
-; CHECK-NEXT: %arrayidxC1 = getelementptr inbounds i16, i16* %c, i64 %store_ind_inc
; CHECK-NEXT: %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %store_ind
-; CHECK-NEXT: Check 1:
-; CHECK-NEXT: Comparing group 1:
-; CHECK-NEXT: %arrayidxB = getelementptr inbounds i16, i16* %b, i64 %ind
-; CHECK-NEXT: Against group 2:
; CHECK-NEXT: %arrayidxC1 = getelementptr inbounds i16, i16* %c, i64 %store_ind_inc
+; CHECK-NEXT: Against group 1:
+; CHECK-NEXT: %arrayidxA = getelementptr inbounds i16, i16* %a, i64 %ind
+; CHECK-NEXT: %arrayidxA1 = getelementptr inbounds i16, i16* %a, i64 %add
+; CHECK-NEXT: Check 1:
+; CHECK-NEXT: Comparing group 0:
; CHECK-NEXT: %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %store_ind
+; CHECK-NEXT: %arrayidxC1 = getelementptr inbounds i16, i16* %c, i64 %store_ind_inc
+; CHECK-NEXT: Against group 2:
+; CHECK-NEXT: %arrayidxB = getelementptr inbounds i16, i16* %b, i64 %ind
; CHECK-NEXT: Grouped accesses:
; CHECK-NEXT: Group 0:
+; CHECK-NEXT: (Low: %c High: (78 + %c))
+; CHECK-NEXT: Member: {%c,+,4}
+; CHECK-NEXT: Member: {(2 + %c),+,4}
+; CHECK-NEXT: Group 1:
; CHECK-NEXT: (Low: %a High: (40 + %a))
-; CHECK-NEXT: Member: {(2 + %a),+,2}
; CHECK-NEXT: Member: {%a,+,2}
-; CHECK-NEXT: Group 1:
+; CHECK-NEXT: Member: {(2 + %a),+,2}
+; CHECK-NEXT: Group 2:
; CHECK-NEXT: (Low: %b High: (38 + %b))
; CHECK-NEXT: Member: {%b,+,2}
-; CHECK-NEXT: Group 2:
-; CHECK-NEXT: (Low: %c High: (78 + %c))
-; CHECK-NEXT: Member: {(2 + %c),+,4}
-; CHECK-NEXT: Member: {%c,+,4}
define void @testg(i16* %a,
i16* %b,
@@ -154,29 +154,29 @@ for.end:
; CHECK: Run-time memory checks:
; CHECK-NEXT: Check 0:
; CHECK-NEXT: Comparing group 0:
-; CHECK-NEXT: %arrayidxA1 = getelementptr i16, i16* %a, i64 %add
-; CHECK-NEXT: %arrayidxA = getelementptr i16, i16* %a, i64 %ind
-; CHECK-NEXT: Against group 2:
-; CHECK-NEXT: %arrayidxC1 = getelementptr inbounds i16, i16* %c, i64 %store_ind_inc
; CHECK-NEXT: %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %store_ind
-; CHECK-NEXT: Check 1:
-; CHECK-NEXT: Comparing group 1:
-; CHECK-NEXT: %arrayidxB = getelementptr i16, i16* %b, i64 %ind
-; CHECK-NEXT: Against group 2:
; CHECK-NEXT: %arrayidxC1 = getelementptr inbounds i16, i16* %c, i64 %store_ind_inc
+; CHECK-NEXT: Against group 1:
+; CHECK-NEXT: %arrayidxA = getelementptr i16, i16* %a, i64 %ind
+; CHECK-NEXT: %arrayidxA1 = getelementptr i16, i16* %a, i64 %add
+; CHECK-NEXT: Check 1:
+; CHECK-NEXT: Comparing group 0:
; CHECK-NEXT: %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %store_ind
+; CHECK-NEXT: %arrayidxC1 = getelementptr inbounds i16, i16* %c, i64 %store_ind_inc
+; CHECK-NEXT: Against group 2:
+; CHECK-NEXT: %arrayidxB = getelementptr i16, i16* %b, i64 %ind
; CHECK-NEXT: Grouped accesses:
; CHECK-NEXT: Group 0:
+; CHECK-NEXT: (Low: %c High: (78 + %c))
+; CHECK-NEXT: Member: {%c,+,4}
+; CHECK-NEXT: Member: {(2 + %c),+,4}
+; CHECK-NEXT: Group 1:
; CHECK-NEXT: (Low: %a High: (40 + %a))
-; CHECK-NEXT: Member: {(2 + %a),+,2}
; CHECK-NEXT: Member: {%a,+,2}
-; CHECK-NEXT: Group 1:
+; CHECK-NEXT: Member: {(2 + %a),+,2}
+; CHECK-NEXT: Group 2:
; CHECK-NEXT: (Low: %b High: (38 + %b))
; CHECK-NEXT: Member: {%b,+,2}
-; CHECK-NEXT: Group 2:
-; CHECK-NEXT: (Low: %c High: (78 + %c))
-; CHECK-NEXT: Member: {(2 + %c),+,4}
-; CHECK-NEXT: Member: {%c,+,4}
define void @testh(i16* %a,
i16* %b,
Modified: llvm/trunk/test/Analysis/LoopAccessAnalysis/unsafe-and-rt-checks.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/LoopAccessAnalysis/unsafe-and-rt-checks.ll?rev=241809&r1=241808&r2=241809&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/LoopAccessAnalysis/unsafe-and-rt-checks.ll (original)
+++ llvm/trunk/test/Analysis/LoopAccessAnalysis/unsafe-and-rt-checks.ll Thu Jul 9 10:18:25 2015
@@ -15,14 +15,14 @@ target triple = "x86_64-apple-macosx10.1
; CHECK: Run-time memory checks:
; CHECK-NEXT: 0:
; CHECK-NEXT: Comparing group
-; CHECK-NEXT: %arrayidxA = getelementptr inbounds i16, i16* %a, i64 %storemerge3
; CHECK-NEXT: %arrayidxA_plus_2 = getelementptr inbounds i16, i16* %a, i64 %add
+; CHECK-NEXT: %arrayidxA = getelementptr inbounds i16, i16* %a, i64 %storemerge3
; CHECK-NEXT: Against group
; CHECK-NEXT: %arrayidxB = getelementptr inbounds i16, i16* %b, i64 %storemerge3
; CHECK-NEXT: 1:
; CHECK-NEXT: Comparing group
-; CHECK-NEXT: %arrayidxA = getelementptr inbounds i16, i16* %a, i64 %storemerge3
; CHECK-NEXT: %arrayidxA_plus_2 = getelementptr inbounds i16, i16* %a, i64 %add
+; CHECK-NEXT: %arrayidxA = getelementptr inbounds i16, i16* %a, i64 %storemerge3
; CHECK-NEXT: Against group
; CHECK-NEXT: %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %storemerge3
More information about the llvm-commits
mailing list