Skip to content
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

Prevent offset access with block arrays to thwart dynamic ALA #25933

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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