mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 04:02:41 +01:00
d2d01d1984
When eliminating or merging almost empty basic blocks, the existence of non-trivial PHI nodes is currently used to recognize potential loops of which the block is the header and keep the block. However, the current algorithm fails if the loops' exit condition is evaluated only with volatile values hence no PHI nodes in the header. Especially when such a loop is an outer loop of a nested loop, the loop is collapsed into a single loop which prevent later optimizations from being applied (e.g., transforming nested loops into simplified forms and loop vectorization). The patch augments the existing PHI node-based check by adding a pre-test if the BB actually belongs to a set of loop headers and not eliminating it if yes. llvm-svn: 264697
78 lines
2.9 KiB
LLVM
78 lines
2.9 KiB
LLVM
;RUN: opt -loop-unswitch -simplifycfg -S < %s | FileCheck %s
|
|
|
|
define i32 @foo(i32 %a, i32 %b) {
|
|
;CHECK-LABEL: foo
|
|
entry:
|
|
br label %for.body.lr.ph
|
|
|
|
for.body.lr.ph: ; preds = %entry
|
|
%cmp0 = icmp sgt i32 %b, 0
|
|
br i1 %cmp0, label %for.body, label %for.cond.cleanup
|
|
|
|
for.body: ; preds = %for.inc, %for.body.lr.ph
|
|
%inc.i = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
|
|
%mul.i = phi i32 [ 3, %for.body.lr.ph ], [ %mul.p, %for.inc ]
|
|
%add.i = phi i32 [ %a, %for.body.lr.ph ], [ %add.p, %for.inc ]
|
|
%cmp1 = icmp eq i32 %a, 12345
|
|
br i1 %cmp1, label %if.then, label %if.else, !prof !0
|
|
; CHECK: %cmp1 = icmp eq i32 %a, 12345
|
|
; CHECK-NEXT: br i1 %cmp1, label %for.body.us, label %for.body, !prof !0
|
|
if.then: ; preds = %for.body
|
|
; CHECK: for.body.us:
|
|
; CHECK: add nsw i32 %{{.*}}, 123
|
|
; CHECK: %exitcond.us = icmp eq i32 %inc.us, %b
|
|
; CHECK: br i1 %exitcond.us, label %for.cond.cleanup, label %for.body.us
|
|
%add = add nsw i32 %add.i, 123
|
|
br label %for.inc
|
|
|
|
if.else: ; preds = %for.body
|
|
%mul = mul nsw i32 %mul.i, %b
|
|
br label %for.inc
|
|
; CHECK: for.body:
|
|
; CHECK: %mul = mul nsw i32 %mul.i, %b
|
|
; CHECK: %inc = add nuw nsw i32 %inc.i, 1
|
|
; CHECK: %exitcond = icmp eq i32 %inc, %b
|
|
; CHECK: br i1 %exitcond, label %for.cond.cleanup, label %for.body
|
|
for.inc: ; preds = %if.then, %if.else
|
|
%mul.p = phi i32 [ %b, %if.then ], [ %mul, %if.else ]
|
|
%add.p = phi i32 [ %add, %if.then ], [ %a, %if.else ]
|
|
%inc = add nuw nsw i32 %inc.i, 1
|
|
%exitcond = icmp eq i32 %inc, %b
|
|
br i1 %exitcond, label %for.cond.cleanup, label %for.body
|
|
|
|
for.cond.cleanup: ; preds = %for.inc, %for.body.lr.ph
|
|
%t2 = phi i32 [ %b, %for.body.lr.ph ], [ %mul.p, %for.inc ]
|
|
%t1 = phi i32 [ %a, %for.body.lr.ph ], [ %add.p, %for.inc ]
|
|
%add3 = add nsw i32 %t2, %t1
|
|
ret i32 %add3
|
|
}
|
|
|
|
define void @foo_swapped(i32 %a, i32 %b) {
|
|
;CHECK-LABEL: foo_swapped
|
|
entry:
|
|
br label %for.body
|
|
;CHECK: entry:
|
|
;CHECK-NEXT: %cmp1 = icmp eq i32 1, 2
|
|
;CHECK-NEXT: br i1 %cmp1, label %for.body, label %for.cond.cleanup.split, !prof !1
|
|
;CHECK: for.body:
|
|
for.body: ; preds = %for.inc, %entry
|
|
%inc.i = phi i32 [ 0, %entry ], [ %inc, %if.then ]
|
|
%add.i = phi i32 [ 100, %entry ], [ %add, %if.then ]
|
|
%inc = add nuw nsw i32 %inc.i, 1
|
|
%cmp1 = icmp eq i32 1, 2
|
|
br i1 %cmp1, label %if.then, label %for.cond.cleanup, !prof !0
|
|
|
|
if.then: ; preds = %for.body
|
|
%add = add nsw i32 %a, %add.i
|
|
|
|
%exitcond = icmp eq i32 %inc, %b
|
|
br i1 %exitcond, label %for.cond.cleanup, label %for.body
|
|
|
|
for.cond.cleanup: ; preds = %for.inc, %for.body.lr.ph, %for.body
|
|
ret void
|
|
}
|
|
!0 = !{!"branch_weights", i32 64, i32 4}
|
|
|
|
;CHECK: !0 = !{!"branch_weights", i32 64, i32 4}
|
|
;CHECK: !1 = !{!"branch_weights", i32 4, i32 64}
|