This is an archive of the discontinued LLVM Phabricator instance.

[LV] Fix PR36983. For a given recurrence, fix all phis in exit block
ClosedPublic

Authored by roman.shirokiy on Jun 5 2018, 9:44 AM.

Details

Summary

There could be several identical PHIs in exit block using same loop recurrence.

For example, we have a following 2 phis in the loop, both %local_2_23 and %local_4_25 values are not used inside the loop.

loop:
 %local_2_23 = phi i32 [ %iv.rem, %loop ], [ %43, %preheader ]
 %local_4_25 = phi i32 [ %iv.rem, %loop ], [ -25, %preheader ]

LCSSA will produce two corresponding phis in exit block.

loop.exit:
%local_2_23.lcssa = phi i32 [ %local_2_23, %loop ]
%local_4_25.lcssa = phi i32 [ %local_4_25, %loop ]

Further passes may deduce that these depend only on iv value hence we may end up with the identical phi nodes in loop exit block.

 loop:
 %iv.rem185 = phi i32 [ 7, %preheader ], [ %iv.rem, %loop ]
 ...

loop_exit:
 %local_2_23.lcssa = phi i32 [ %iv.rem185, %loop ]
 %local_4_25.lcssa = phi i32 [ %iv.rem185, %loop ]

When LV is fixing recurrence users, only the first phi is handled.

Diff Detail

Event Timeline

roman.shirokiy created this revision.Jun 5 2018, 9:44 AM
hsaito accepted this revision.Jun 7 2018, 5:38 PM

Given that there can be more than one users, the fix makes sense to me. LGTM.

This revision is now accepted and ready to land.Jun 7 2018, 5:38 PM
This revision was automatically updated to reflect the committed changes.