; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -passes=gvn -dom-tree-reachability-max-bbs-to-explore=1 -S < %s | FileCheck %s
define i8 @f(i1 %arg0, i1 %arg1, i1 %arg2) {
; CHECK-LABEL: define i8 @f(
; CHECK-SAME: i1 [[ARG0:%.*]], i1 [[ARG1:%.*]], i1 [[ARG2:%.*]]) {
; CHECK-NEXT:  [[BB:.*:]]
; CHECK-NEXT:    br i1 [[ARG2]], label %[[BB2:.*]], label %[[BB11:.*]]
; CHECK:       [[BB11]]:
; CHECK-NEXT:    br label %[[BB3:.*]]
; CHECK:       [[BB2]]:
; CHECK-NEXT:    br label %[[BB3]]
; CHECK:       [[BB3]]:
; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias ptr @_Znwm(i64 2)
; CHECK-NEXT:    br label %[[BB4:.*]]
; CHECK:       [[BB4]]:
; CHECK-NEXT:    [[PHI:%.*]] = phi ptr [ null, %[[BB4]] ], [ [[CALL]], %[[BB3]] ]
; CHECK-NEXT:    store i8 2, ptr [[PHI]], align 4
; CHECK-NEXT:    br i1 [[ARG0]], label %[[BB5:.*]], label %[[BB4]]
; CHECK:       [[BB5]]:
; CHECK-NEXT:    br i1 [[ARG1]], label %[[BB7:.*]], label %[[BB6:.*]]
; CHECK:       [[BB6]]:
; CHECK-NEXT:    call void @use(i64 undef)
; CHECK-NEXT:    br label %[[BB9:.*]]
; CHECK:       [[BB7]]:
; CHECK-NEXT:    [[LOAD8:%.*]] = load i8, ptr [[CALL]], align 4
; CHECK-NEXT:    br label %[[BB9]]
; CHECK:       [[BB9]]:
; CHECK-NEXT:    [[PHI10:%.*]] = phi i8 [ [[LOAD8]], %[[BB7]] ], [ 4, %[[BB6]] ]
; CHECK-NEXT:    ret i8 [[PHI10]]
;
bb:
  br i1 %arg2, label %bb2, label %bb11

bb11:
  br label %bb3

bb2:
  br label %bb3

bb3:
  %call = tail call noalias ptr @_Znwm(i64 2)
  br label %bb4

bb4:
  %phi = phi ptr [ null, %bb4 ], [ %call, %bb3 ]
  store i8 2, ptr %phi, align 4
  br i1 %arg0, label %bb5, label %bb4

bb5:
  br i1 %arg1, label %bb7, label %bb6

bb6:
  %load = load i64, ptr %call, align 4
  call void @use(i64 %load)
  br label %bb9

bb7:
  %load8 = load i8, ptr %call, align 4
  br label %bb9

bb9:
  %phi10 = phi i8 [ %load8, %bb7 ], [ 4, %bb6 ]
  ret i8 %phi10
}

declare ptr @_Znwm(i64)
declare void @use(i64)
