[ScopBuilder] Skip getting leader when merging statements to close holes.
commit94c4b649622ba97cf2eebb5b8905592e595db879
authorMichael Kruse <llvm@meinersbur.de>
Fri, 13 Sep 2019 01:04:38 +0000 (13 01:04 +0000)
committerMichael Kruse <llvm@meinersbur.de>
Fri, 13 Sep 2019 01:04:38 +0000 (13 01:04 +0000)
treea14db61631baad0f716ff5845e29f32e94d0fd87
parente4b9b1e0476e8c8cd649d5f0b70c827db31d625d
[ScopBuilder] Skip getting leader when merging statements to close holes.

Function joinOrderedInstructions merges instructions when a leader is encountered twice.
It also notices that leaders in SeenLeaders may lose their leadership in previous merging,
and tries to handle the case using following code:

    Instruction *PrevLeader = UnionFind.getLeaderValue(SeenLeaders.back());

However, this is wrong because it always gets leader for the last element of SeenLeaders,
and I believe it's wrong even we get leader for Prev here.  As a result, Statements in cases
like the one in patch aren't merged as expected.  After investigation, I believe it's
unnecessary to get leader instruction at all.  This is based on fact: Although leaders in
SeenLeaders could lose leadership, they only lose to others in SeenLeaders, in other words,
one existing leader will be chosen as new leader of merged equivalent statements.  We can
take advantage of this and simply check if current leader equals to Prev and break merging
if it does.

The patch also adds a new test.

Patch by bin.narwal <bin.narwal@gmail.com>

Differential Revision: https://reviews.llvm.org/D67007

git-svn-id: https://llvm.org/svn/llvm-project/polly/trunk@371801 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/ScopBuilder.cpp
test/ScopInfo/granularity_scalar-indep_ordered-2.ll [new file with mode: 0644]