Files
clang-p2996/llvm/test/Transforms/LoopUnswitch/2015-06-17-Metadata.ll
Serguei Katkov 66182d6c38 [SimplifyCFG] Re-apply Relax restriction for folding unconditional branches
The commit rL308422 introduces a restriction for folding unconditional
branches. Specifically if empty block with unconditional branch leads to
header of the loop then elimination of this basic block is prohibited.
However it seems this condition is redundantly strict.
If elimination of this basic block does not introduce more back edges
then we can eliminate this block.

The patch implements this relax of restriction.

The test profile/Linux/counter_promo_nest.c in compiler-rt project
is updated to meet this change.

Reviewers: efriedma, mcrosier, pacxx, hsung, davidxl	
Reviewed By: pacxx
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42691

llvm-svn: 324572
2018-02-08 07:16:29 +00:00

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}