2014-05-29 14:47:23 +08:00
|
|
|
; RUN: opt < %s -loop-unroll -indvars -disable-output
|
|
|
|
|
|
|
|
@b = external global i32, align 4
|
|
|
|
|
2015-10-03 03:21:49 +08:00
|
|
|
; Test that LoopUnroll does not break LCSSA form.
|
|
|
|
;
|
|
|
|
; In this function we have a following CFG:
|
|
|
|
; ( entry )
|
|
|
|
; |
|
|
|
|
; v
|
|
|
|
; ( outer.header ) <--
|
|
|
|
; | \
|
|
|
|
; v |
|
|
|
|
; --> ( inner.header ) |
|
|
|
|
; / / \ |
|
|
|
|
; \ / \ |
|
|
|
|
; \ v v /
|
|
|
|
; ( inner.latch ) ( outer.latch )
|
|
|
|
; |
|
|
|
|
; v
|
|
|
|
; ( exit )
|
|
|
|
;
|
|
|
|
; When the inner loop is unrolled, we inner.latch block has only one
|
|
|
|
; predecessor and one successor, so it can be merged with exit block.
|
|
|
|
; During the merge, however, we remove an LCSSA definition for
|
|
|
|
; %storemerge1.lcssa, breaking LCSSA form for the outer loop.
|
|
|
|
|
2014-05-29 14:47:23 +08:00
|
|
|
; Function Attrs: nounwind uwtable
|
|
|
|
define void @fn1() #0 {
|
|
|
|
entry:
|
2015-10-03 03:21:49 +08:00
|
|
|
br label %outer.header
|
2014-05-29 14:47:23 +08:00
|
|
|
|
2015-10-03 03:21:49 +08:00
|
|
|
outer.header: ; preds = %outer.latch, %entry
|
|
|
|
%storemerge1 = phi i32 [ 0, %entry ], [ %inc9, %outer.latch ]
|
|
|
|
br label %inner.header
|
2014-05-29 14:47:23 +08:00
|
|
|
|
2015-10-03 03:21:49 +08:00
|
|
|
inner.header: ; preds = %inner.latch, %outer.header
|
|
|
|
%storemerge = phi i32 [ %add, %inner.latch ], [ 0, %outer.header ]
|
2014-05-29 14:47:23 +08:00
|
|
|
%cmp = icmp slt i32 %storemerge, 1
|
2015-10-03 03:21:49 +08:00
|
|
|
br i1 %cmp, label %inner.latch, label %outer.latch
|
2014-05-29 14:47:23 +08:00
|
|
|
|
2015-10-03 03:21:49 +08:00
|
|
|
inner.latch: ; preds = %inner.header
|
2014-05-29 14:47:23 +08:00
|
|
|
%tobool4 = icmp eq i32 %storemerge, 0
|
|
|
|
%add = add nsw i32 %storemerge, 1
|
2015-10-03 03:21:49 +08:00
|
|
|
br i1 %tobool4, label %inner.header, label %exit
|
2014-05-29 14:47:23 +08:00
|
|
|
|
2015-10-03 03:21:49 +08:00
|
|
|
exit: ; preds = %inner.latch
|
|
|
|
%storemerge1.lcssa = phi i32 [ %storemerge1, %inner.latch ]
|
|
|
|
store i32 %storemerge1.lcssa, i32* @b, align 4
|
2014-05-29 14:47:23 +08:00
|
|
|
ret void
|
|
|
|
|
2015-10-03 03:21:49 +08:00
|
|
|
outer.latch: ; preds = %inner.header
|
2014-05-29 14:47:23 +08:00
|
|
|
%inc9 = add nsw i32 %storemerge1, 1
|
2015-10-03 03:21:49 +08:00
|
|
|
br label %outer.header
|
2014-05-29 14:47:23 +08:00
|
|
|
}
|
2015-10-03 03:21:52 +08:00
|
|
|
|
|
|
|
; This case is similar to the previous one, and has the same CFG.
|
|
|
|
; The difference is that loop unrolling doesn't remove any LCSSA definition,
|
|
|
|
; yet breaks LCSSA form for the outer loop. It happens because before unrolling
|
|
|
|
; block inner.latch was inside outer loop (and consequently, didn't require
|
|
|
|
; LCSSA definition for %x), but after unrolling it occurs out of the outer
|
|
|
|
; loop, so we need to insert an LCSSA definition to keep LCSSA.
|
|
|
|
|
|
|
|
; Function Attrs: nounwind uwtable
|
|
|
|
define void @fn2() {
|
|
|
|
entry:
|
|
|
|
br label %outer.header
|
|
|
|
|
|
|
|
outer.header:
|
|
|
|
br label %inner.header
|
|
|
|
|
|
|
|
inner.header:
|
|
|
|
%x = load i32, i32* undef, align 4
|
|
|
|
br i1 true, label %outer.latch, label %inner.latch
|
|
|
|
|
|
|
|
inner.latch:
|
|
|
|
%inc6 = add nsw i32 %x, 1
|
|
|
|
store i32 %inc6, i32* undef, align 4
|
|
|
|
br i1 false, label %inner.header, label %exit
|
|
|
|
|
|
|
|
exit:
|
|
|
|
ret void
|
|
|
|
|
|
|
|
outer.latch:
|
|
|
|
br label %outer.header
|
|
|
|
}
|