Fwd: [PATCH] Fix for LoopUnroll pass was breaking LCSSA form while completely removing loop [PR18861]

Dinesh Dwivedi dinesh.d at samsung.com
Wed Mar 5 05:19:09 PST 2014


This is what I have come up to fix LCSSA while detaching exit block from loop nest [as I mentioned in previous mail].
I have written this without much understanding of complete picture, so this might be totally wrong.

I have assumed few things.
1. As block was part of loop getting unrolled, it will have predecessor which is part of loop nest. 
2. If any value used as instruction operand in the block whose parent is out side the loop getting unrolled, we have 
to add PHI node from all predecessor of the block for it to maintain LCSSA.

This patch fixes PR18861.

I will appreciate any comment or pointer to right direction.

Regards
Dinesh Dwivedi

------- Original Message -------
Sender : Dinesh Dwivedi<dinesh.d at samsung.com>  Chief Engineer/SRI-Bangalore-Native Framework/Samsung Electronics
Date   : Feb 26, 2014 13:40 (GMT+05:30)
Title  : [PATCH] Fix for LoopUnroll pass was breaking LCSSA form while completely removing loop [PR18861]

I have attached patch to fix PR18861. I am still looking in to this issue. Here is my analysis.

If LoopUnroll pass decides to completely unroll a loop, before deleting it [deleteLoopFromQueue()] from the loop list,
it updates parent loop for all blocks in the loop to be unrolled [updateUnloop()->updateBlockParents()]. Candidate for 
parent loop is based on finding nearest parent loop among the block successors [getNearestLoop()], and returns null if 
a block does not have any successor [e.g. exit blocks having return statement, not sure if this may happen in other 
cases]. This causes the block to come out of loop nest. Now if this block is using some variable assigned inside loop 
nest, then it breaks LCSSA form.

In test case for this bug, value assigned in top loop was used in inner-most loop's exit block. Unrolling this inner-most 
loop was putting the exit block outside loop resulting ill-formed LCSSA.

I am working on the solution for reforming LCSSA for basic blocks when the come out of the loop nest. This requires iterating
through all values used in the block and then find loop that assigns them and adding PHI nodes from all predecessors of the block.
I am new to this and still need to understand how to add phi nodes, replace all the uses in the current block with this new variable,
if I have to check relation between block predecessors and loop that assigns values etc.

Regards
Dinesh Dwivedi<p> </p><p> </p>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PR18861.diff
Type: application/octet-stream
Size: 4804 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140305/6f3a2cf4/attachment.obj>


More information about the llvm-commits mailing list