forked from OSchip/llvm-project
[Test] One more elaborate test with selects for loop deletion
This commit is contained in:
parent
9eedde705f
commit
8840c94a33
|
@ -725,8 +725,8 @@ failure:
|
|||
}
|
||||
|
||||
; TODO: We can break the backedge here.
|
||||
define i32 @test_switch(i32 %limit) {
|
||||
; CHECK-LABEL: @test_switch(
|
||||
define i32 @test_select(i32 %limit) {
|
||||
; CHECK-LABEL: @test_select(
|
||||
; CHECK-NEXT: entry:
|
||||
; CHECK-NEXT: [[LOOP_GUARD:%.*]] = icmp sgt i32 [[LIMIT:%.*]], 0
|
||||
; CHECK-NEXT: br i1 [[LOOP_GUARD]], label [[LOOP_PREHEADER:%.*]], label [[FAILURE:%.*]]
|
||||
|
@ -766,3 +766,51 @@ done: ; preds = %backedge
|
|||
failure:
|
||||
unreachable
|
||||
}
|
||||
|
||||
; TODO: We can break the backedge here.
|
||||
define i32 @test_select_const(i32 %x) {
|
||||
; CHECK-LABEL: @test_select_const(
|
||||
; CHECK-NEXT: entry:
|
||||
; CHECK-NEXT: br label [[LOOP:%.*]]
|
||||
; CHECK: loop:
|
||||
; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[SUM_NEXT:%.*]], [[BACKEDGE:%.*]] ]
|
||||
; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
|
||||
; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
|
||||
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[IS_POSITIVE]], i32 [[SUB]], i32 [[X:%.*]]
|
||||
; CHECK-NEXT: [[SEL_COND:%.*]] = icmp sgt i32 [[SEL]], 0
|
||||
; CHECK-NEXT: br i1 [[SEL_COND]], label [[BACKEDGE]], label [[IF_FALSE:%.*]]
|
||||
; CHECK: if.false:
|
||||
; CHECK-NEXT: br label [[BACKEDGE]]
|
||||
; CHECK: backedge:
|
||||
; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[LOOP]] ]
|
||||
; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[MERGE_PHI]]
|
||||
; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
|
||||
; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[DONE:%.*]]
|
||||
; CHECK: done:
|
||||
; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
|
||||
; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
|
||||
;
|
||||
entry:
|
||||
br label %loop
|
||||
|
||||
loop: ; preds = %backedge, %entry
|
||||
%sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
|
||||
%sub = sub i32 4, %sum
|
||||
%is.positive = icmp sgt i32 %sub, 0
|
||||
%sel = select i1 %is.positive, i32 %sub, i32 %x
|
||||
%sel.cond = icmp sgt i32 %sel, 0
|
||||
br i1 %sel.cond, label %backedge, label %if.false
|
||||
|
||||
if.false: ; preds = %loop
|
||||
br label %backedge
|
||||
|
||||
backedge: ; preds = %if.false, %loop
|
||||
%merge.phi = phi i32 [ 0, %if.false ], [ %sub, %loop ]
|
||||
%sum.next = add i32 %sum, %merge.phi
|
||||
%loop.cond = icmp ne i32 %sum.next, 4
|
||||
br i1 %loop.cond, label %loop, label %done
|
||||
|
||||
done: ; preds = %backedge
|
||||
%sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
|
||||
ret i32 %sum.next.lcssa
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue