2011-12-26 20:54:14 +00:00
|
|
|
; RUN: opt -simplifycfg -S -o - < %s | FileCheck %s
|
|
|
|
|
|
|
|
declare void @helper(i32)
|
|
|
|
|
|
|
|
define void @test1(i1 %a, i1 %b) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test1(
|
2011-12-26 20:54:14 +00:00
|
|
|
entry:
|
|
|
|
br i1 %a, label %Y, label %X, !prof !0
|
|
|
|
; CHECK: br i1 %or.cond, label %Z, label %Y, !prof !0
|
|
|
|
|
2011-12-27 04:31:52 +00:00
|
|
|
X:
|
|
|
|
%c = or i1 %b, false
|
|
|
|
br i1 %c, label %Z, label %Y, !prof !1
|
|
|
|
|
|
|
|
Y:
|
|
|
|
call void @helper(i32 0)
|
|
|
|
ret void
|
|
|
|
|
|
|
|
Z:
|
|
|
|
call void @helper(i32 1)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @test2(i1 %a, i1 %b) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test2(
|
2011-12-27 04:31:52 +00:00
|
|
|
entry:
|
|
|
|
br i1 %a, label %X, label %Y, !prof !1
|
|
|
|
; CHECK: br i1 %or.cond, label %Z, label %Y, !prof !1
|
|
|
|
; CHECK-NOT: !prof
|
|
|
|
|
|
|
|
X:
|
|
|
|
%c = or i1 %b, false
|
|
|
|
br i1 %c, label %Z, label %Y, !prof !2
|
|
|
|
|
|
|
|
Y:
|
|
|
|
call void @helper(i32 0)
|
|
|
|
ret void
|
|
|
|
|
|
|
|
Z:
|
|
|
|
call void @helper(i32 1)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @test3(i1 %a, i1 %b) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test3(
|
2011-12-27 04:31:52 +00:00
|
|
|
; CHECK-NOT: !prof
|
|
|
|
entry:
|
|
|
|
br i1 %a, label %X, label %Y, !prof !1
|
|
|
|
|
2011-12-26 20:54:14 +00:00
|
|
|
X:
|
|
|
|
%c = or i1 %b, false
|
|
|
|
br i1 %c, label %Z, label %Y
|
|
|
|
|
|
|
|
Y:
|
|
|
|
call void @helper(i32 0)
|
|
|
|
ret void
|
|
|
|
|
|
|
|
Z:
|
|
|
|
call void @helper(i32 1)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2011-12-27 04:31:52 +00:00
|
|
|
define void @test4(i1 %a, i1 %b) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test4(
|
2011-12-27 04:31:52 +00:00
|
|
|
; CHECK-NOT: !prof
|
|
|
|
entry:
|
|
|
|
br i1 %a, label %X, label %Y
|
|
|
|
|
|
|
|
X:
|
|
|
|
%c = or i1 %b, false
|
|
|
|
br i1 %c, label %Z, label %Y, !prof !1
|
|
|
|
|
|
|
|
Y:
|
|
|
|
call void @helper(i32 0)
|
|
|
|
ret void
|
|
|
|
|
|
|
|
Z:
|
|
|
|
call void @helper(i32 1)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2012-09-12 17:04:11 +00:00
|
|
|
;; test5 - The case where it jumps to the default target will be removed.
|
|
|
|
define void @test5(i32 %M, i32 %N) nounwind uwtable {
|
|
|
|
entry:
|
|
|
|
switch i32 %N, label %sw2 [
|
|
|
|
i32 1, label %sw2
|
|
|
|
i32 2, label %sw.bb
|
|
|
|
i32 3, label %sw.bb1
|
|
|
|
], !prof !3
|
2013-12-20 08:21:24 +00:00
|
|
|
; CHECK-LABEL: @test5(
|
2012-09-12 17:04:11 +00:00
|
|
|
; CHECK: switch i32 %N, label %sw2 [
|
|
|
|
; CHECK: i32 3, label %sw.bb1
|
|
|
|
; CHECK: i32 2, label %sw.bb
|
|
|
|
; CHECK: ], !prof !2
|
|
|
|
|
|
|
|
sw.bb:
|
|
|
|
call void @helper(i32 0)
|
|
|
|
br label %sw.epilog
|
|
|
|
|
|
|
|
sw.bb1:
|
|
|
|
call void @helper(i32 1)
|
|
|
|
br label %sw.epilog
|
|
|
|
|
|
|
|
sw2:
|
|
|
|
call void @helper(i32 2)
|
|
|
|
br label %sw.epilog
|
|
|
|
|
|
|
|
sw.epilog:
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2012-09-14 21:53:06 +00:00
|
|
|
;; test6 - Some cases of the second switch are pruned during optimization.
|
|
|
|
;; Then the second switch will be converted to a branch, finally, the first
|
|
|
|
;; switch and the branch will be merged into a single switch.
|
|
|
|
define void @test6(i32 %M, i32 %N) nounwind uwtable {
|
|
|
|
entry:
|
|
|
|
switch i32 %N, label %sw2 [
|
|
|
|
i32 1, label %sw2
|
|
|
|
i32 2, label %sw.bb
|
|
|
|
i32 3, label %sw.bb1
|
|
|
|
], !prof !4
|
2013-12-20 08:21:24 +00:00
|
|
|
; CHECK-LABEL: @test6(
|
2012-09-14 21:53:06 +00:00
|
|
|
; CHECK: switch i32 %N, label %sw.epilog
|
|
|
|
; CHECK: i32 3, label %sw.bb1
|
|
|
|
; CHECK: i32 2, label %sw.bb
|
|
|
|
; CHECK: i32 4, label %sw.bb5
|
|
|
|
; CHECK: ], !prof !3
|
|
|
|
|
|
|
|
sw.bb:
|
|
|
|
call void @helper(i32 0)
|
|
|
|
br label %sw.epilog
|
|
|
|
|
|
|
|
sw.bb1:
|
|
|
|
call void @helper(i32 1)
|
|
|
|
br label %sw.epilog
|
|
|
|
|
|
|
|
sw2:
|
|
|
|
;; Here "case 2" is invalidated since the default case of the first switch
|
|
|
|
;; does not include "case 2".
|
|
|
|
switch i32 %N, label %sw.epilog [
|
|
|
|
i32 2, label %sw.bb4
|
|
|
|
i32 4, label %sw.bb5
|
|
|
|
], !prof !5
|
|
|
|
|
|
|
|
sw.bb4:
|
|
|
|
call void @helper(i32 2)
|
|
|
|
br label %sw.epilog
|
|
|
|
|
|
|
|
sw.bb5:
|
|
|
|
call void @helper(i32 3)
|
|
|
|
br label %sw.epilog
|
|
|
|
|
|
|
|
sw.epilog:
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2012-09-15 00:39:57 +00:00
|
|
|
;; This test is based on test1 but swapped the targets of the second branch.
|
|
|
|
define void @test1_swap(i1 %a, i1 %b) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test1_swap(
|
2012-09-15 00:39:57 +00:00
|
|
|
entry:
|
|
|
|
br i1 %a, label %Y, label %X, !prof !0
|
|
|
|
; CHECK: br i1 %or.cond, label %Y, label %Z, !prof !4
|
|
|
|
|
|
|
|
X:
|
|
|
|
%c = or i1 %b, false
|
|
|
|
br i1 %c, label %Y, label %Z, !prof !1
|
|
|
|
|
|
|
|
Y:
|
|
|
|
call void @helper(i32 0)
|
|
|
|
ret void
|
|
|
|
|
|
|
|
Z:
|
|
|
|
call void @helper(i32 1)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2012-09-17 21:30:40 +00:00
|
|
|
define void @test7(i1 %a, i1 %b) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test7(
|
2012-09-17 21:30:40 +00:00
|
|
|
entry:
|
|
|
|
%c = or i1 %b, false
|
|
|
|
br i1 %a, label %Y, label %X, !prof !0
|
|
|
|
; CHECK: br i1 %brmerge, label %Y, label %Z, !prof !5
|
|
|
|
|
|
|
|
X:
|
|
|
|
br i1 %c, label %Y, label %Z, !prof !6
|
|
|
|
|
|
|
|
Y:
|
|
|
|
call void @helper(i32 0)
|
|
|
|
ret void
|
|
|
|
|
|
|
|
Z:
|
|
|
|
call void @helper(i32 1)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2012-09-17 22:28:55 +00:00
|
|
|
; Test basic folding to a conditional branch.
|
|
|
|
define void @test8(i64 %x, i64 %y) nounwind {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test8(
|
2012-09-17 22:28:55 +00:00
|
|
|
entry:
|
|
|
|
%lt = icmp slt i64 %x, %y
|
|
|
|
; CHECK: br i1 %lt, label %a, label %b, !prof !6
|
|
|
|
%qux = select i1 %lt, i32 0, i32 2
|
|
|
|
switch i32 %qux, label %bees [
|
|
|
|
i32 0, label %a
|
|
|
|
i32 1, label %b
|
|
|
|
i32 2, label %b
|
|
|
|
], !prof !7
|
|
|
|
a:
|
|
|
|
call void @helper(i32 0) nounwind
|
|
|
|
ret void
|
|
|
|
b:
|
|
|
|
call void @helper(i32 1) nounwind
|
|
|
|
ret void
|
|
|
|
bees:
|
|
|
|
call void @helper(i32 2) nounwind
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2012-09-17 23:07:43 +00:00
|
|
|
; Test edge splitting when the default target has icmp and unconditinal
|
|
|
|
; branch
|
|
|
|
define i1 @test9(i32 %x, i32 %y) nounwind {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test9(
|
2012-09-17 23:07:43 +00:00
|
|
|
entry:
|
|
|
|
switch i32 %x, label %bees [
|
|
|
|
i32 0, label %a
|
|
|
|
i32 1, label %end
|
|
|
|
i32 2, label %end
|
|
|
|
], !prof !7
|
|
|
|
; CHECK: switch i32 %x, label %bees [
|
|
|
|
; CHECK: i32 0, label %a
|
|
|
|
; CHECK: i32 1, label %end
|
|
|
|
; CHECK: i32 2, label %end
|
|
|
|
; CHECK: i32 92, label %end
|
|
|
|
; CHECK: ], !prof !7
|
|
|
|
|
|
|
|
a:
|
|
|
|
call void @helper(i32 0) nounwind
|
|
|
|
%reta = icmp slt i32 %x, %y
|
|
|
|
ret i1 %reta
|
|
|
|
|
|
|
|
bees:
|
|
|
|
%tmp = icmp eq i32 %x, 92
|
|
|
|
br label %end
|
|
|
|
|
|
|
|
end:
|
|
|
|
; CHECK: end:
|
|
|
|
; CHECK: %ret = phi i1 [ true, %entry ], [ false, %bees ], [ true, %entry ], [ true, %entry ]
|
|
|
|
%ret = phi i1 [ true, %entry ], [%tmp, %bees], [true, %entry]
|
|
|
|
call void @helper(i32 2) nounwind
|
|
|
|
ret i1 %ret
|
|
|
|
}
|
|
|
|
|
2012-09-18 00:47:33 +00:00
|
|
|
define void @test10(i32 %x) nounwind readnone ssp noredzone {
|
|
|
|
entry:
|
|
|
|
switch i32 %x, label %lor.rhs [
|
|
|
|
i32 2, label %lor.end
|
|
|
|
i32 1, label %lor.end
|
|
|
|
i32 3, label %lor.end
|
|
|
|
], !prof !7
|
|
|
|
|
|
|
|
lor.rhs:
|
|
|
|
call void @helper(i32 1) nounwind
|
|
|
|
ret void
|
|
|
|
|
|
|
|
lor.end:
|
|
|
|
call void @helper(i32 0) nounwind
|
|
|
|
ret void
|
|
|
|
|
2013-12-20 08:21:24 +00:00
|
|
|
; CHECK-LABEL: @test10(
|
2012-09-18 00:47:33 +00:00
|
|
|
; CHECK: %x.off = add i32 %x, -1
|
|
|
|
; CHECK: %switch = icmp ult i32 %x.off, 3
|
|
|
|
; CHECK: br i1 %switch, label %lor.end, label %lor.rhs, !prof !8
|
|
|
|
}
|
|
|
|
|
|
|
|
; Remove dead cases from the switch.
|
|
|
|
define void @test11(i32 %x) nounwind {
|
|
|
|
%i = shl i32 %x, 1
|
|
|
|
switch i32 %i, label %a [
|
|
|
|
i32 21, label %b
|
|
|
|
i32 24, label %c
|
|
|
|
], !prof !8
|
2013-12-20 08:21:24 +00:00
|
|
|
; CHECK-LABEL: @test11(
|
2012-09-18 00:47:33 +00:00
|
|
|
; CHECK: %cond = icmp eq i32 %i, 24
|
|
|
|
; CHECK: br i1 %cond, label %c, label %a, !prof !9
|
|
|
|
|
|
|
|
a:
|
|
|
|
call void @helper(i32 0) nounwind
|
|
|
|
ret void
|
|
|
|
b:
|
|
|
|
call void @helper(i32 1) nounwind
|
|
|
|
ret void
|
|
|
|
c:
|
|
|
|
call void @helper(i32 2) nounwind
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2013-12-10 00:13:41 +00:00
|
|
|
;; test12 - Don't crash if the whole switch is removed
|
|
|
|
define void @test12(i32 %M, i32 %N) nounwind uwtable {
|
|
|
|
entry:
|
|
|
|
switch i32 %N, label %sw.bb [
|
|
|
|
i32 1, label %sw.bb
|
|
|
|
], !prof !9
|
2013-12-20 08:21:24 +00:00
|
|
|
; CHECK-LABEL: @test12(
|
2013-12-20 08:21:27 +00:00
|
|
|
; CHECK-NEXT: entry:
|
|
|
|
; CHECK-NEXT: call void @helper
|
|
|
|
; CHECK-NEXT: ret void
|
2013-12-10 00:13:41 +00:00
|
|
|
|
|
|
|
sw.bb:
|
|
|
|
call void @helper(i32 0)
|
|
|
|
br label %sw.epilog
|
|
|
|
|
|
|
|
sw.epilog:
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2013-12-20 08:21:30 +00:00
|
|
|
;; If every case is dead, make sure they are all removed. This used to
|
|
|
|
;; crash trying to merge the metadata.
|
|
|
|
define void @test13(i32 %x) nounwind {
|
|
|
|
entry:
|
|
|
|
%i = shl i32 %x, 1
|
|
|
|
switch i32 %i, label %a [
|
|
|
|
i32 21, label %b
|
|
|
|
i32 25, label %c
|
|
|
|
], !prof !8
|
|
|
|
; CHECK-LABEL: @test13(
|
|
|
|
; CHECK-NEXT: entry:
|
|
|
|
; CHECK-NEXT: call void @helper
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
|
|
|
|
a:
|
|
|
|
call void @helper(i32 0) nounwind
|
|
|
|
ret void
|
|
|
|
b:
|
|
|
|
call void @helper(i32 1) nounwind
|
|
|
|
ret void
|
|
|
|
c:
|
|
|
|
call void @helper(i32 2) nounwind
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2014-01-27 23:39:03 +00:00
|
|
|
;; When folding branches to common destination, the updated branch weights
|
|
|
|
;; can exceed uint32 by more than factor of 2. We should keep halving the
|
|
|
|
;; weights until they can fit into uint32.
|
|
|
|
@max_regno = common global i32 0, align 4
|
|
|
|
define void @test14(i32* %old, i32 %final) {
|
|
|
|
; CHECK-LABEL: @test14
|
|
|
|
; CHECK: br i1 %or.cond, label %for.exit, label %for.inc, !prof !10
|
|
|
|
for.cond:
|
|
|
|
br label %for.cond2
|
|
|
|
for.cond2:
|
|
|
|
%i.1 = phi i32 [ %inc19, %for.inc ], [ 0, %for.cond ]
|
|
|
|
%bit.0 = phi i32 [ %shl, %for.inc ], [ 1, %for.cond ]
|
|
|
|
%tobool = icmp eq i32 %bit.0, 0
|
|
|
|
br i1 %tobool, label %for.exit, label %for.body3, !prof !10
|
|
|
|
for.body3:
|
|
|
|
%v3 = load i32* @max_regno, align 4
|
|
|
|
%cmp4 = icmp eq i32 %i.1, %v3
|
|
|
|
br i1 %cmp4, label %for.exit, label %for.inc, !prof !11
|
|
|
|
for.inc:
|
|
|
|
%shl = shl i32 %bit.0, 1
|
|
|
|
%inc19 = add nsw i32 %i.1, 1
|
|
|
|
br label %for.cond2
|
|
|
|
for.exit:
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
IR: Make metadata typeless in assembly
Now that `Metadata` is typeless, reflect that in the assembly. These
are the matching assembly changes for the metadata/value split in
r223802.
- Only use the `metadata` type when referencing metadata from a call
intrinsic -- i.e., only when it's used as a `Value`.
- Stop pretending that `ValueAsMetadata` is wrapped in an `MDNode`
when referencing it from call intrinsics.
So, assembly like this:
define @foo(i32 %v) {
call void @llvm.foo(metadata !{i32 %v}, metadata !0)
call void @llvm.foo(metadata !{i32 7}, metadata !0)
call void @llvm.foo(metadata !1, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{metadata !3}, metadata !0)
ret void, !bar !2
}
!0 = metadata !{metadata !2}
!1 = metadata !{i32* @global}
!2 = metadata !{metadata !3}
!3 = metadata !{}
turns into this:
define @foo(i32 %v) {
call void @llvm.foo(metadata i32 %v, metadata !0)
call void @llvm.foo(metadata i32 7, metadata !0)
call void @llvm.foo(metadata i32* @global, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{!3}, metadata !0)
ret void, !bar !2
}
!0 = !{!2}
!1 = !{i32* @global}
!2 = !{!3}
!3 = !{}
I wrote an upgrade script that handled almost all of the tests in llvm
and many of the tests in cfe (even handling many `CHECK` lines). I've
attached it (or will attach it in a moment if you're speedy) to PR21532
to help everyone update their out-of-tree testcases.
This is part of PR21532.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224257 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-15 19:07:53 +00:00
|
|
|
!0 = !{!"branch_weights", i32 3, i32 5}
|
|
|
|
!1 = !{!"branch_weights", i32 1, i32 1}
|
|
|
|
!2 = !{!"branch_weights", i32 1, i32 2}
|
|
|
|
!3 = !{!"branch_weights", i32 4, i32 3, i32 2, i32 1}
|
|
|
|
!4 = !{!"branch_weights", i32 4, i32 3, i32 2, i32 1}
|
|
|
|
!5 = !{!"branch_weights", i32 7, i32 6, i32 5}
|
|
|
|
!6 = !{!"branch_weights", i32 1, i32 3}
|
|
|
|
!7 = !{!"branch_weights", i32 33, i32 9, i32 8, i32 7}
|
|
|
|
!8 = !{!"branch_weights", i32 33, i32 9, i32 8}
|
|
|
|
!9 = !{!"branch_weights", i32 7, i32 6}
|
|
|
|
!10 = !{!"branch_weights", i32 672646, i32 21604207}
|
|
|
|
!11 = !{!"branch_weights", i32 6960, i32 21597248}
|
|
|
|
|
|
|
|
; CHECK: !0 = !{!"branch_weights", i32 5, i32 11}
|
|
|
|
; CHECK: !1 = !{!"branch_weights", i32 1, i32 5}
|
|
|
|
; CHECK: !2 = !{!"branch_weights", i32 7, i32 1, i32 2}
|
|
|
|
; CHECK: !3 = !{!"branch_weights", i32 49, i32 12, i32 24, i32 35}
|
|
|
|
; CHECK: !4 = !{!"branch_weights", i32 11, i32 5}
|
|
|
|
; CHECK: !5 = !{!"branch_weights", i32 17, i32 15}
|
|
|
|
; CHECK: !6 = !{!"branch_weights", i32 9, i32 7}
|
|
|
|
; CHECK: !7 = !{!"branch_weights", i32 17, i32 9, i32 8, i32 7, i32 17}
|
|
|
|
; CHECK: !8 = !{!"branch_weights", i32 24, i32 33}
|
|
|
|
; CHECK: !9 = !{!"branch_weights", i32 8, i32 33}
|
2014-01-27 23:39:03 +00:00
|
|
|
;; The false weight prints out as a negative integer here, but inside llvm, we
|
|
|
|
;; treat the weight as an unsigned integer.
|
IR: Make metadata typeless in assembly
Now that `Metadata` is typeless, reflect that in the assembly. These
are the matching assembly changes for the metadata/value split in
r223802.
- Only use the `metadata` type when referencing metadata from a call
intrinsic -- i.e., only when it's used as a `Value`.
- Stop pretending that `ValueAsMetadata` is wrapped in an `MDNode`
when referencing it from call intrinsics.
So, assembly like this:
define @foo(i32 %v) {
call void @llvm.foo(metadata !{i32 %v}, metadata !0)
call void @llvm.foo(metadata !{i32 7}, metadata !0)
call void @llvm.foo(metadata !1, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{metadata !3}, metadata !0)
ret void, !bar !2
}
!0 = metadata !{metadata !2}
!1 = metadata !{i32* @global}
!2 = metadata !{metadata !3}
!3 = metadata !{}
turns into this:
define @foo(i32 %v) {
call void @llvm.foo(metadata i32 %v, metadata !0)
call void @llvm.foo(metadata i32 7, metadata !0)
call void @llvm.foo(metadata i32* @global, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{!3}, metadata !0)
ret void, !bar !2
}
!0 = !{!2}
!1 = !{i32* @global}
!2 = !{!3}
!3 = !{}
I wrote an upgrade script that handled almost all of the tests in llvm
and many of the tests in cfe (even handling many `CHECK` lines). I've
attached it (or will attach it in a moment if you're speedy) to PR21532
to help everyone update their out-of-tree testcases.
This is part of PR21532.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224257 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-15 19:07:53 +00:00
|
|
|
; CHECK: !10 = !{!"branch_weights", i32 112017436, i32 -735157296}
|