Compiler projects using llvm
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 | FileCheck %s

define void @callbr_duplicate_dest() {
; CHECK-LABEL: @callbr_duplicate_dest(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    callbr void asm sideeffect "", "!i"()
; CHECK-NEXT:    to label [[BB:%.*]] [label %bb]
; CHECK:       bb:
; CHECK-NEXT:    ret void
;
entry:
  callbr void asm sideeffect "", "!i"()
  to label %bb [label %bb]

bb:
  ret void
}

; TODO: Can fold to a duplicate callbr destination.
define void @callbr_can_fold_to_duplicate_dest1() {
; CHECK-LABEL: @callbr_can_fold_to_duplicate_dest1(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    callbr void asm sideeffect "", "!i"()
; CHECK-NEXT:    to label [[BB2:%.*]] [label %common.ret]
; CHECK:       common.ret:
; CHECK-NEXT:    ret void
; CHECK:       bb2:
; CHECK-NEXT:    br label [[COMMON_RET:%.*]]
;
entry:
  callbr void asm sideeffect "", "!i"()
  to label %bb2 [label %bb1]

bb1:
  ret void

bb2:
  ret void
}

; TODO: Can fold to a duplicate callbr destination.
define void @callbr_can_fold_to_duplicate_dest2() {
; CHECK-LABEL: @callbr_can_fold_to_duplicate_dest2(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    callbr void asm sideeffect "", "!i,!i"()
; CHECK-NEXT:    to label [[COMMON_RET:%.*]] [label [[BB2:%.*]], label %bb3]
; CHECK:       common.ret:
; CHECK-NEXT:    ret void
; CHECK:       bb2:
; CHECK-NEXT:    br label [[COMMON_RET]]
; CHECK:       bb3:
; CHECK-NEXT:    br label [[COMMON_RET]]
;
entry:
  callbr void asm sideeffect "", "!i,!i"()
  to label %bb1 [label %bb2, label %bb3]

bb1:
  ret void

bb2:
  ret void

bb3:
  ret void
}