2019-06-13 12:51:35 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
2019-04-17 12:52:47 +08:00
|
|
|
; RUN: opt < %s -simplifycfg -S | FileCheck -enable-var-scope %s
|
|
|
|
|
|
|
|
; Test basic folding to a conditional branch.
|
|
|
|
define i32 @foo(i64 %x, i64 %y) nounwind {
|
|
|
|
; CHECK-LABEL: @foo(
|
2019-06-13 12:51:35 +08:00
|
|
|
; CHECK-NEXT: entry:
|
|
|
|
; CHECK-NEXT: [[EQ:%.*]] = icmp eq i64 [[X:%.*]], [[Y:%.*]]
|
|
|
|
; CHECK-NEXT: br i1 [[EQ]], label [[B:%.*]], label [[SWITCH:%.*]]
|
|
|
|
; CHECK: switch:
|
|
|
|
; CHECK-NEXT: [[LT:%.*]] = icmp slt i64 [[X]], [[Y]]
|
|
|
|
; CHECK-NEXT: br i1 [[LT]], label [[A:%.*]], label [[B]]
|
|
|
|
; CHECK: a:
|
|
|
|
; CHECK-NEXT: tail call void @bees.a() #0
|
|
|
|
; CHECK-NEXT: ret i32 1
|
|
|
|
; CHECK: b:
|
|
|
|
; CHECK-NEXT: [[RETVAL:%.*]] = phi i32 [ 0, [[SWITCH]] ], [ 2, [[ENTRY:%.*]] ]
|
|
|
|
; CHECK-NEXT: tail call void @bees.b() #0
|
|
|
|
; CHECK-NEXT: ret i32 [[RETVAL]]
|
|
|
|
;
|
2019-04-17 12:52:47 +08:00
|
|
|
entry:
|
2019-06-13 12:51:35 +08:00
|
|
|
%eq = icmp eq i64 %x, %y
|
|
|
|
br i1 %eq, label %b, label %switch
|
2019-04-17 12:52:47 +08:00
|
|
|
switch:
|
2019-06-13 12:51:35 +08:00
|
|
|
%lt = icmp slt i64 %x, %y
|
|
|
|
%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
|
|
|
|
]
|
2019-04-17 12:52:47 +08:00
|
|
|
a:
|
2019-06-13 12:51:35 +08:00
|
|
|
tail call void @bees.a() nounwind
|
|
|
|
ret i32 1
|
2019-04-17 12:52:47 +08:00
|
|
|
b:
|
2019-06-13 12:51:35 +08:00
|
|
|
%retval = phi i32 [0, %switch], [0, %switch], [2, %entry]
|
|
|
|
tail call void @bees.b() nounwind
|
|
|
|
ret i32 %retval
|
2019-04-17 12:52:47 +08:00
|
|
|
bees:
|
2019-06-13 12:51:35 +08:00
|
|
|
tail call void @llvm.trap() nounwind
|
|
|
|
unreachable
|
2019-04-17 12:52:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
; Test basic folding to an unconditional branch.
|
|
|
|
define i32 @bar(i64 %x, i64 %y) nounwind {
|
|
|
|
; CHECK-LABEL: @bar(
|
2019-06-13 12:51:35 +08:00
|
|
|
; CHECK-NEXT: entry:
|
|
|
|
; CHECK-NEXT: tail call void @bees.a() #0
|
|
|
|
; CHECK-NEXT: ret i32 0
|
|
|
|
;
|
2019-04-17 12:52:47 +08:00
|
|
|
entry:
|
2019-06-13 12:51:35 +08:00
|
|
|
%lt = icmp slt i64 %x, %y
|
|
|
|
%qux = select i1 %lt, i32 0, i32 2
|
|
|
|
switch i32 %qux, label %bees [
|
|
|
|
i32 0, label %a
|
|
|
|
i32 1, label %b
|
|
|
|
i32 2, label %a
|
|
|
|
]
|
2019-04-17 12:52:47 +08:00
|
|
|
a:
|
2019-06-13 12:51:35 +08:00
|
|
|
%retval = phi i32 [0, %entry], [0, %entry], [1, %b]
|
|
|
|
tail call void @bees.a() nounwind
|
|
|
|
ret i32 0
|
2019-04-17 12:52:47 +08:00
|
|
|
b:
|
2019-06-13 12:51:35 +08:00
|
|
|
tail call void @bees.b() nounwind
|
|
|
|
br label %a
|
2019-04-17 12:52:47 +08:00
|
|
|
bees:
|
2019-06-13 12:51:35 +08:00
|
|
|
tail call void @llvm.trap() nounwind
|
|
|
|
unreachable
|
2019-04-17 12:52:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
; Test the edge case where both values from the select are the default case.
|
|
|
|
define void @bazz(i64 %x, i64 %y) nounwind {
|
|
|
|
; CHECK-LABEL: @bazz(
|
2019-06-13 12:51:35 +08:00
|
|
|
; CHECK-NEXT: entry:
|
|
|
|
; CHECK-NEXT: tail call void @bees.b() #0
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
;
|
2019-04-17 12:52:47 +08:00
|
|
|
entry:
|
2019-06-13 12:51:35 +08:00
|
|
|
%lt = icmp slt i64 %x, %y
|
|
|
|
%qux = select i1 %lt, i32 10, i32 12
|
|
|
|
switch i32 %qux, label %b [
|
|
|
|
i32 0, label %a
|
|
|
|
i32 1, label %bees
|
|
|
|
i32 2, label %bees
|
|
|
|
]
|
2019-04-17 12:52:47 +08:00
|
|
|
a:
|
2019-06-13 12:51:35 +08:00
|
|
|
tail call void @bees.a() nounwind
|
|
|
|
ret void
|
2019-04-17 12:52:47 +08:00
|
|
|
b:
|
2019-06-13 12:51:35 +08:00
|
|
|
tail call void @bees.b() nounwind
|
|
|
|
ret void
|
2019-04-17 12:52:47 +08:00
|
|
|
bees:
|
2019-06-13 12:51:35 +08:00
|
|
|
tail call void @llvm.trap()
|
|
|
|
unreachable
|
2019-04-17 12:52:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
; Test the edge case where both values from the select are equal.
|
|
|
|
define void @quux(i64 %x, i64 %y) nounwind {
|
|
|
|
; CHECK-LABEL: @quux(
|
2019-06-13 12:51:35 +08:00
|
|
|
; CHECK-NEXT: entry:
|
|
|
|
; CHECK-NEXT: tail call void @bees.a() #0
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
;
|
2019-04-17 12:52:47 +08:00
|
|
|
entry:
|
2019-06-13 12:51:35 +08:00
|
|
|
%lt = icmp slt i64 %x, %y
|
|
|
|
%qux = select i1 %lt, i32 0, i32 0
|
|
|
|
switch i32 %qux, label %b [
|
|
|
|
i32 0, label %a
|
|
|
|
i32 1, label %bees
|
|
|
|
i32 2, label %bees
|
|
|
|
]
|
2019-04-17 12:52:47 +08:00
|
|
|
a:
|
2019-06-13 12:51:35 +08:00
|
|
|
tail call void @bees.a() nounwind
|
|
|
|
ret void
|
2019-04-17 12:52:47 +08:00
|
|
|
b:
|
2019-06-13 12:51:35 +08:00
|
|
|
tail call void @bees.b() nounwind
|
|
|
|
ret void
|
2019-04-17 12:52:47 +08:00
|
|
|
bees:
|
2019-06-13 12:51:35 +08:00
|
|
|
tail call void @llvm.trap()
|
|
|
|
unreachable
|
2019-04-17 12:52:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
; A final test, for phi node munging.
|
|
|
|
define i32 @xyzzy(i64 %x, i64 %y) {
|
|
|
|
; CHECK-LABEL: @xyzzy(
|
2019-06-13 12:51:35 +08:00
|
|
|
; CHECK-NEXT: entry:
|
|
|
|
; CHECK-NEXT: [[EQ:%.*]] = icmp eq i64 [[X:%.*]], [[Y:%.*]]
|
|
|
|
; CHECK-NEXT: [[LT:%.*]] = icmp slt i64 [[X]], [[Y]]
|
|
|
|
; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[LT]], i32 -1, i32 1
|
|
|
|
; CHECK-NEXT: [[VAL:%.*]] = select i1 [[EQ]], i32 0, i32 [[SPEC_SELECT]]
|
|
|
|
; CHECK-NEXT: ret i32 [[VAL]]
|
|
|
|
;
|
2019-04-17 12:52:47 +08:00
|
|
|
entry:
|
2019-06-13 12:51:35 +08:00
|
|
|
%eq = icmp eq i64 %x, %y
|
|
|
|
br i1 %eq, label %r, label %cont
|
2019-04-17 12:52:47 +08:00
|
|
|
cont:
|
2019-06-13 12:51:35 +08:00
|
|
|
%lt = icmp slt i64 %x, %y
|
|
|
|
%qux = select i1 %lt, i32 0, i32 2
|
|
|
|
switch i32 %qux, label %bees [
|
|
|
|
i32 0, label %a
|
|
|
|
i32 1, label %r
|
|
|
|
i32 2, label %r
|
|
|
|
]
|
2019-04-17 12:52:47 +08:00
|
|
|
r:
|
2019-06-13 12:51:35 +08:00
|
|
|
%val = phi i32 [0, %entry], [1, %cont], [1, %cont]
|
|
|
|
ret i32 %val
|
2019-04-17 12:52:47 +08:00
|
|
|
a:
|
2019-06-13 12:51:35 +08:00
|
|
|
ret i32 -1
|
2019-04-17 12:52:47 +08:00
|
|
|
bees:
|
2019-06-13 12:51:35 +08:00
|
|
|
tail call void @llvm.trap()
|
|
|
|
unreachable
|
2019-04-17 12:52:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
declare void @llvm.trap() nounwind noreturn
|
|
|
|
declare void @bees.a() nounwind
|
|
|
|
declare void @bees.b() nounwind
|
|
|
|
|
|
|
|
; CHECK: attributes #1 = { cold noreturn nounwind }
|