llvm/llvm/test/Transforms/SimplifyCFG/duplicate-phis.ll

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

; instcombine should sort the PHI operands so that simplifycfg can see the
; duplicate and remove it.

define i32 @foo(i1 %t) {
; CHECK-LABEL: @foo(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    call void @bar()
; CHECK-NEXT:    br i1 [[T:%.*]], label [[TRUE:%.*]], label [[FALSE:%.*]]
; CHECK:       true:
; CHECK-NEXT:    call void @bar()
; CHECK-NEXT:    br label [[FALSE]]
; CHECK:       false:
; CHECK-NEXT:    [[A:%.*]] = phi i32 [ 4, [[TRUE]] ], [ 10, [[ENTRY:%.*]] ]
; CHECK-NEXT:    call void @bar()
; CHECK-NEXT:    ret i32 [[A]]
;
entry:
  call void @bar()
  br i1 %t, label %true, label %false
true:
  call void @bar()
  br label %false
false:
  %a = phi i32 [ 2, %true ], [ 5, %entry ]
  %b = phi i32 [ 5, %entry ], [ 2, %true ]
  call void @bar()
  %c = add i32 %a, %b
  ret i32 %c
}

declare void @bar()