llvm/llvm/test/Transforms/Inline/inline-switch-default-2.ll

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
; RUN: opt %s -S -passes=inline -inline-threshold=11 | FileCheck %s

; Check for scenarios without TTI.

define i64 @foo1(i64 %a) {
; CHECK-LABEL: define i64 @foo1(
; CHECK-SAME: i64 [[A:%.*]]) {
; CHECK-NEXT:    [[B:%.*]] = call i64 @bar1(i64 [[A]])
; CHECK-NEXT:    ret i64 [[B]]
;
  %b = call i64 @bar1(i64 %a)
  ret i64 %b
}

define i64 @foo2(i64 %a) {
; CHECK-LABEL: define i64 @foo2(
; CHECK-SAME: i64 [[A:%.*]]) {
; CHECK-NEXT:    [[B_I:%.*]] = call i64 @bar2(i64 [[A]])
; CHECK-NEXT:    ret i64 [[B_I]]
;
  %b = call i64 @bar2(i64 %a)
  ret i64 %b
}

define i64 @bar1(i64 %a) {
; CHECK-LABEL: define i64 @bar1(
; CHECK-SAME: i64 [[A:%.*]]) {
; CHECK-NEXT:    switch i64 [[A]], label [[DEFAULT_BRANCH:%.*]] [
; CHECK-NEXT:      i64 0, label [[BRANCH_0:%.*]]
; CHECK-NEXT:      i64 2, label [[BRANCH_2:%.*]]
; CHECK-NEXT:      i64 4, label [[BRANCH_4:%.*]]
; CHECK-NEXT:      i64 6, label [[BRANCH_6:%.*]]
; CHECK-NEXT:    ]
; CHECK:       branch_0:
; CHECK-NEXT:    br label [[EXIT:%.*]]
; CHECK:       branch_2:
; CHECK-NEXT:    br label [[EXIT]]
; CHECK:       branch_4:
; CHECK-NEXT:    br label [[EXIT]]
; CHECK:       branch_6:
; CHECK-NEXT:    br label [[EXIT]]
; CHECK:       default_branch:
; CHECK-NEXT:    br label [[EXIT]]
; CHECK:       exit:
; CHECK-NEXT:    [[B:%.*]] = phi i64 [ 5, [[BRANCH_0]] ], [ 9, [[BRANCH_2]] ], [ 2, [[BRANCH_4]] ], [ 7, [[BRANCH_6]] ], [ 3, [[DEFAULT_BRANCH]] ]
; CHECK-NEXT:    ret i64 [[B]]
;
  switch i64 %a, label %default_branch [
  i64 0, label %branch_0
  i64 2, label %branch_2
  i64 4, label %branch_4
  i64 6, label %branch_6
  ]

branch_0:
  br label %exit

branch_2:
  br label %exit

branch_4:
  br label %exit

branch_6:
  br label %exit

default_branch:
  br label %exit

exit:
  %b = phi i64 [ 5, %branch_0 ], [ 9, %branch_2 ], [ 2, %branch_4 ], [ 7, %branch_6 ], [ 3, %default_branch ]
  ret i64 %b
}

define i64 @bar2(i64 %a) {
; CHECK-LABEL: define i64 @bar2(
; CHECK-SAME: i64 [[A:%.*]]) {
; CHECK-NEXT:    switch i64 [[A]], label [[UNREACHABLEDEFAULT:%.*]] [
; CHECK-NEXT:      i64 0, label [[BRANCH_0:%.*]]
; CHECK-NEXT:      i64 2, label [[BRANCH_2:%.*]]
; CHECK-NEXT:      i64 4, label [[BRANCH_4:%.*]]
; CHECK-NEXT:      i64 6, label [[BRANCH_6:%.*]]
; CHECK-NEXT:    ]
; CHECK:       branch_0:
; CHECK-NEXT:    br label [[EXIT:%.*]]
; CHECK:       branch_2:
; CHECK-NEXT:    br label [[EXIT]]
; CHECK:       branch_4:
; CHECK-NEXT:    br label [[EXIT]]
; CHECK:       branch_6:
; CHECK-NEXT:    br label [[EXIT]]
; CHECK:       unreachabledefault:
; CHECK-NEXT:    unreachable
; CHECK:       exit:
; CHECK-NEXT:    [[B:%.*]] = phi i64 [ 5, [[BRANCH_0]] ], [ 9, [[BRANCH_2]] ], [ 2, [[BRANCH_4]] ], [ 7, [[BRANCH_6]] ]
; CHECK-NEXT:    ret i64 [[B]]
;
  switch i64 %a, label %unreachabledefault [
  i64 0, label %branch_0
  i64 2, label %branch_2
  i64 4, label %branch_4
  i64 6, label %branch_6
  ]

branch_0:
  br label %exit

branch_2:
  br label %exit

branch_4:
  br label %exit

branch_6:
  br label %exit

unreachabledefault:
  unreachable

exit:
  %b = phi i64 [ 5, %branch_0 ], [ 9, %branch_2 ], [ 2, %branch_4 ], [ 7, %branch_6 ]
  ret i64 %b
}