Skip to content

Commit

Permalink
Prevent offset access with block arrays to thwart dynamic ALA
Browse files Browse the repository at this point in the history
Signed-off-by: Engin Kayraklioglu <[email protected]>
  • Loading branch information
e-kayrakli committed Sep 11, 2024
1 parent c22e376 commit e4e661f
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/optimizations/forallOptimizations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,10 @@ static void generateDynamicCheckForAccess(ALACandidate& candidate,
offsetCheck->insertAtTail(e->copy());
}

CallExpr *staticOverride = new CallExpr(PRIM_UNARY_LNOT,
new SymExpr(staticCheckSymMap[baseSym]));
offsetCheck = new CallExpr("||", staticOverride, offsetCheck);

CallExpr* newCheck = new CallExpr("&&", offsetCheck); // we'll add curCheck
curCheck->replace(newCheck);
newCheck->insertAtTail(curCheck);
Expand Down
21 changes: 21 additions & 0 deletions test/optimizations/autoLocalAccess/blockWithOffset.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use BlockDist;


var Arr = blockDist.createArray(1..10, int);

const Inner = Arr.domain.expand(-1);

forall i in Arr.domain { // this should make Arr[i] a static candidate
if i<10 then
Arr[i] = // this must be a local access (9 total)
Arr[i+1]; // this must be a default access (9 total)
}

writeln(Arr);

forall i in Inner { // this should make Arr[i] a dynamic candidate
Arr[i] = // this must be a local access (8 total) <- this was buggy
Arr[i+1]; // this must be a default access (8 total)
}

writeln(Arr);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-slogDistArrEltAccess=true
42 changes: 42 additions & 0 deletions test/optimizations/autoLocalAccess/blockWithOffset.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

Start analyzing forall (blockWithOffset.chpl:8)
| Found loop domain (blockWithOffset.chpl:4)
| Will attempt static and dynamic optimizations (blockWithOffset.chpl:8)
|
| Start analyzing call (blockWithOffset.chpl:10)
| Can optimize: Access base is the iterator's base (blockWithOffset.chpl:10)
| This call is a static optimization candidate (blockWithOffset.chpl:10)
|
| Start analyzing call (blockWithOffset.chpl:11)
| Call has offset(s), this will require dynamic check (blockWithOffset.chpl:11)
| Can optimize: Access base is the iterator's base (blockWithOffset.chpl:11)
| This call is a static optimization candidate (blockWithOffset.chpl:11)
|
End analyzing forall (blockWithOffset.chpl:8)


Start analyzing forall (blockWithOffset.chpl:16)
| Found loop domain (blockWithOffset.chpl:6)
| Will attempt static and dynamic optimizations (blockWithOffset.chpl:16)
|
| Start analyzing call (blockWithOffset.chpl:17)
| Can't determine the domain of access base (blockWithOffset.chpl:4)
| This call is a dynamic optimization candidate (blockWithOffset.chpl:17)
|
| Start analyzing call (blockWithOffset.chpl:18)
| Call has offset(s), this will require dynamic check (blockWithOffset.chpl:18)
| Can't determine the domain of access base (blockWithOffset.chpl:4)
| This call is a dynamic optimization candidate (blockWithOffset.chpl:18)
|
End analyzing forall (blockWithOffset.chpl:16)

Static check successful. Using localAccess [static only ALA clone] (blockWithOffset.chpl:10)
Static check failed. Reverting optimization [static only ALA clone] (blockWithOffset.chpl:11)
Static check successful. Using localAccess with dynamic check (blockWithOffset.chpl:17)
Static check failed. Reverting optimization [static and dynamic ALA clone] (blockWithOffset.chpl:18)
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

Numbers collected by prediff:
localAccess was called 17 times
this was called 17 times
1 change: 1 addition & 0 deletions test/optimizations/autoLocalAccess/blockWithOffset.prediff

0 comments on commit e4e661f

Please sign in to comment.