This is an archive of the discontinued LLVM Phabricator instance.

[Polly] Ensure unique implicit reads/writes at beginning/end of ScopStmts
AbandonedPublic

Authored by Meinersbur on Oct 14 2015, 7:43 PM.

Details

Reviewers
grosser
jdoerfert
Summary

Previously, there could be a read scalar access for every use of a cross-stmt value and potentially multiple stores for a value definition. Check that such MemoryAccesses do not already exist before adding new ones. This will be used for De-LICM such that if removing a redundant read or write, there is no second variant left.

Instead of checking for each instruction individually whether it needs to be written, we can now "pull-in" a reload when required including the creation of a store of the definition which simplifies the creation of implicit MemoryAccesses a bit.

We also unify the PHI writes in non-affine subregions. Instead of writing them in the exiting block, we write them only in the subregion's exit. The former violates the requirement that implicits are not written until leaving the scop statement if the exiting block has also edges back into the subregion. In addition, generateScalarLoads and generateScalarStore do not have special versions for non-affine subregions anymore.

Diff Detail

Event Timeline

Meinersbur updated this revision to Diff 37440.Oct 14 2015, 7:43 PM
Meinersbur retitled this revision from to [Polly] Ensure unique implicit reads/writes at beginning/end of ScopStmts.
Meinersbur updated this object.
Meinersbur added reviewers: grosser, jdoerfert.
Meinersbur added a project: Restricted Project.
Meinersbur added subscribers: llvm-commits, pollydev.

Rebase to r250809; smaller changes to make the DeLICM patch smaller

Meinersbur updated this revision to Diff 38855.Nov 1 2015, 9:32 AM

Rebase to r251341

Disappearing PHIs in exit nodes requires to remember incoming nodes explicitely. Might be a separate patches:

  • Introduction of explicit EXIT_PHI origin to avoid quering whether the access instruction is a terminator
  • Storing of incoming values/block for PHI accesses
  • Unification of PHIs in sub-region exit BBs.

Alternatively, we might revive the part that ensures the existence and position of PHI nodes from D11870.

Meinersbur updated this revision to Diff 41275.Nov 26 2015, 3:14 PM

Rebase to r254150

Meinersbur updated this revision to Diff 41277.Nov 26 2015, 3:47 PM

Undo unnecessary changes in test cases

Meinersbur added inline comments.Nov 26 2015, 3:51 PM
test/Isl/CodeGen/uninitialized_scalar_memory.ll
8

Reminder to myself: Have to check why this is gone

test/ScopInfo/read-only-scalar-used-in-phi.ll
22

This is a EXIT_PHI access

test/ScopInfo/same-base-address-scalar-and-array.ll
7

The base address "out" is synthesizable (from a scop parameter) and therefore does not cause accesses. In current trunk there is still an access generated if ModelReadOnlyScalars==true and it is used by a PHI node. I am assuming this is not intentional.

There are multiple instances of this phenomenon in the tests.

Rebase to r254343

grosser edited edge metadata.Dec 5 2015, 2:10 AM

Hi Michael,

thank you for submitting this patch. I just went though it a first time and the overall direction seems good. Uniqueing implicit read/write accesses is likely to make sense by itself and as it as it is useful for DeLICM (either pre-or-post polyhedrization), this change seems well motivated.

I did not yet manage to do a full review, but already posted a couple of comments. My first impression is that the patch is mostly non-controversial, but rather large (600 LoC). To make the individual changes easier to understand (and easier to bisect in case of bugs), it seems worth to split out the independent parts and commit them one-by-one (some of them are trivial). I still need to have a more in-depth look at the actual unification, which seems mostly straightforward but includes some moved code which - in this larger patch - is not easy
to compare. Also, It seems we now keep track of the same MemoryAccess in multiple lists. I still need to understand this better as well.

include/polly/CodeGen/BlockGenerators.h
798

Is this change unrelated? Assuming it is, you can probably commit this as obvious.

include/polly/ScopInfo.h
326

This is because a scalar may be used by multiple instructions in a ScopStmt and we only want to store one memory access for all of them. This makes sense (but could probably be mentioned in this comment).

361

OK, I see that you move from multiple to just a single PHI write access for non-affine regions. I wonder if this could be a separate patch?

836

elsewhere

841

elsewhere

848

Refold lines?

1046

This is independent, no? It it is, please commit it ahead of time.

1483

This seems to be unused after the patch.

lib/Analysis/ScopInfo.cpp
753

I can remove this change without test case failure. It seems unrelated. Can you drop this one (or commit it independently if you need this for debugging).

891

This seems good, but unrelated. Can you commit this ahead of time.

2010

This function is unused. Please remove from patch.

3395

This looks good, but it seems independently useful? Could you commit this by itself?

3589

This sentence is incomplete.

3618

did not "ensure"

3628

This seems unaddressed.

3851

guaranteed

3855

Earlier we skipped the last iteration, now we do not do this any more. Why is this safe?

Also, I wonder if some of this move to the range iterator could be committed ahead of time?

3859

This change seems independent. Can this be separated out?

I think I already mentioned in a conversation that I could make two (larger) commits from this, depending on whether it makes sense:

  • Introduction of the scalar access maps ScalarLoads/ScalarWrites and uniqueing the loads per stmt.
  • Uniqueing of PHI writes for non-affine subregion statements

A drawback of this patch is that the getAccessInstructin() might be nullptr (because an access can be causes by multiple instructions) in some cases. I started the thread "Accessing the same element multiple times within one ScopStmt" on the polly-dev mailing list to discuss this.

Required for DeLICM was the collapse of PHI writes in non-affine regions because such write may only occur after exiting a stmt, but an exiting basic block can have an edge back into the non-affine region. Another way to implement this to split edges from the exiting block to the exit block (ie. insert a basic block) and create the PHI WRITE accesses there.

DeLICM naturally uniques writes because it determines for each (BB,mappable array element) what the content of the array element at the end of the BB should be.

include/polly/CodeGen/BlockGenerators.h
798

In some intermediate state, I made it return a PHINode instead of just an llvm::Value. I may have noticed that it never returns nullptr, but forgot to change the comment back.

I'll commit this separately include the type change, which IMHO makes sense.

include/polly/ScopInfo.h
1046

This was added with D13676. The explicit was added to contrast the usage of the functions introduced below

1483

This is a general accessor. Removing means that AccFuncMap is not accessible anymore from other code.

lib/Analysis/ScopInfo.cpp
753

I'll commit separately

891

is Scalar is introduced in D13676. It maybe should belong to that patch.

3395

getStmtForRegionNode was introduced in this patch

3855

It has become necessary with this patch. The terminator can be a legitimate user of a value, such as the condition. Omitting the terminator before was fine before because the terminator does not define a value itself.

3859

OK

Hi Michael,

two brief comments:

lib/Analysis/ScopInfo.cpp
891

As the two changes belong together, but are independent of anything else, I think you can just commit them directly (as obvious).

3395

As getStmtForRegionNode does not pull in other dependences, you can just commit the changes above and getStmtForRegionNode ahead of time.

Meinersbur abandoned this revision.Dec 21 2015, 5:29 PM
Meinersbur marked 15 inline comments as done.

Split into D15693, D15681, D15510, D15483, D15706 and D15687.