; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=ipsccp -S | FileCheck %s
; Test for PR39772
%struct.Node = type { ptr, ptr, i32 }
define i32 @check(ptr %node) {
; CHECK-LABEL: @check(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[NODE:%.*]], null
; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
; CHECK: if.then:
; CHECK-NEXT: br label [[CLEANUP:%.*]]
; CHECK: if.end:
; CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[NODE]], align 8
; CHECK-NEXT: [[CALL:%.*]] = call i32 @check(ptr [[TMP0]])
; CHECK-NEXT: [[RIGHT:%.*]] = getelementptr inbounds [[STRUCT_NODE:%.*]], ptr [[NODE]], i32 0, i32 1
; CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[RIGHT]], align 8
; CHECK-NEXT: [[CALL1:%.*]] = call i32 @check(ptr [[TMP1]])
; CHECK-NEXT: [[TMP2:%.*]] = load ptr, ptr [[RIGHT]], align 8
; CHECK-NEXT: [[HEIGHT:%.*]] = getelementptr inbounds [[STRUCT_NODE]], ptr [[TMP2]], i32 0, i32 2
; CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr [[HEIGHT]], align 4
; CHECK-NEXT: [[CMP3:%.*]] = icmp ne i32 [[TMP3]], [[CALL1]]
; CHECK-NEXT: br i1 [[CMP3]], label [[IF_THEN4:%.*]], label [[IF_END5:%.*]]
; CHECK: if.then4:
; CHECK-NEXT: unreachable
; CHECK: if.end5:
; CHECK-NEXT: [[CMP6:%.*]] = icmp sgt i32 [[CALL]], [[CALL1]]
; CHECK-NEXT: br i1 [[CMP6]], label [[IF_THEN7:%.*]], label [[IF_ELSE:%.*]]
; CHECK: if.then7:
; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[CALL]], 1
; CHECK-NEXT: br label [[CLEANUP]]
; CHECK: if.else:
; CHECK-NEXT: [[ADD8:%.*]] = add nsw i32 [[CALL1]], 1
; CHECK-NEXT: br label [[CLEANUP]]
; CHECK: cleanup:
; CHECK-NEXT: [[RETVAL_0:%.*]] = phi i32 [ 0, [[IF_THEN]] ], [ [[ADD]], [[IF_THEN7]] ], [ [[ADD8]], [[IF_ELSE]] ]
; CHECK-NEXT: ret i32 [[RETVAL_0]]
;
entry:
%cmp = icmp eq ptr %node, null
br i1 %cmp, label %if.then, label %if.end
if.then: ; preds = %entry
br label %cleanup
if.end: ; preds = %entry
%0 = load ptr, ptr %node
%call = call i32 @check(ptr %0)
%right = getelementptr inbounds %struct.Node, ptr %node, i32 0, i32 1
%1 = load ptr, ptr %right
%call1 = call i32 @check(ptr %1)
%2 = load ptr, ptr %right
%height = getelementptr inbounds %struct.Node, ptr %2, i32 0, i32 2
%3 = load i32, ptr %height
%cmp3 = icmp ne i32 %3, %call1
br i1 %cmp3, label %if.then4, label %if.end5
if.then4: ; preds = %if.end
unreachable
if.end5: ; preds = %if.end
%cmp6 = icmp sgt i32 %call, %call1
br i1 %cmp6, label %if.then7, label %if.else
if.then7: ; preds = %if.end5
%add = add nsw i32 %call, 1
br label %cleanup
if.else: ; preds = %if.end5
%add8 = add nsw i32 %call1, 1
br label %cleanup
cleanup: ; preds = %if.else, %if.then7, %if.then
%retval.0 = phi i32 [ 0, %if.then ], [ %add, %if.then7 ], [ %add8, %if.else ]
ret i32 %retval.0
}
declare ptr @test2_callee(i32, i32)
define void @test2() {
; CHECK-LABEL: @test2(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[FOR_COND:%.*]]
; CHECK: for.cond:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
; CHECK-NEXT: br label [[IF_ELSE33:%.*]]
; CHECK: if.else33:
; CHECK-NEXT: br label [[IF_THEN38:%.*]]
; CHECK: if.then38:
; CHECK-NEXT: [[CALL42:%.*]] = call ptr @test2_callee(i32 0, i32 0)
; CHECK-NEXT: unreachable
;
entry:
br label %for.cond
for.cond: ; preds = %for.inc46, %entry
%op.0 = phi i32 [ 0, %entry ], [ 0, %for.inc46 ]
br label %for.body
for.body: ; preds = %for.cond
%cmp24 = icmp eq i32 %op.0, 38
br i1 %cmp24, label %if.then26, label %if.else33
if.then26: ; preds = %for.body
unreachable
if.else33: ; preds = %for.body
%cmp34 = icmp ne i32 %op.0, 80
%cmp36 = icmp ne i32 %op.0, 81
%or.cond = and i1 %cmp34, %cmp36
br i1 %or.cond, label %if.then38, label %for.inc46
if.then38: ; preds = %if.else33
%call42 = call ptr @test2_callee(i32 %op.0, i32 0)
unreachable
for.inc46: ; preds = %if.else33
br label %for.cond
}