; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
; RUN: opt -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S < %s | FileCheck %s
declare void @bar() nounwind
define i32 @test1(ptr %a, i32 %b, ptr %c, i32 %d) nounwind {
; CHECK-LABEL: define i32 @test1
; CHECK-SAME: (ptr [[A:%.*]], i32 [[B:%.*]], ptr [[C:%.*]], i32 [[D:%.*]]) #[[ATTR0:[0-9]+]] {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[B]], 0
; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: tail call void @bar() #[[ATTR0]]
; CHECK-NEXT: br label [[IF_END7:%.*]]
; CHECK: if.else:
; CHECK-NEXT: [[TOBOOL3:%.*]] = icmp eq i32 [[D]], 0
; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[TOBOOL3]], true
; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
; CHECK-NEXT: tail call void @bar() #[[ATTR0]]
; CHECK-NEXT: br label [[IF_END7]]
; CHECK: if.end7:
; CHECK-NEXT: [[X_0:%.*]] = phi ptr [ [[A]], [[IF_THEN]] ], [ [[C]], [[IF_ELSE]] ]
; CHECK-NEXT: [[TMP9:%.*]] = load i32, ptr [[X_0]], align 4
; CHECK-NEXT: ret i32 [[TMP9]]
;
entry:
%tobool = icmp eq i32 %b, 0
br i1 %tobool, label %if.else, label %if.then
if.then: ; preds = %entry
tail call void @bar() nounwind
br label %if.end7
if.else: ; preds = %entry
%tobool3 = icmp eq i32 %d, 0
br i1 %tobool3, label %if.end7, label %if.then4
if.then4: ; preds = %if.else
tail call void @bar() nounwind
br label %if.end7
if.end7: ; preds = %if.else, %if.then4, %if.then
%x.0 = phi ptr [ %a, %if.then ], [ %c, %if.then4 ], [ null, %if.else ]
%tmp9 = load i32, ptr %x.0
ret i32 %tmp9
}
define i32 @test1_no_null_opt(ptr %a, i32 %b, ptr %c, i32 %d) nounwind #0 {
; CHECK-LABEL: define i32 @test1_no_null_opt
; CHECK-SAME: (ptr [[A:%.*]], i32 [[B:%.*]], ptr [[C:%.*]], i32 [[D:%.*]]) #[[ATTR1:[0-9]+]] {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[B]], 0
; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: tail call void @bar() #[[ATTR0]]
; CHECK-NEXT: br label [[IF_END7:%.*]]
; CHECK: if.else:
; CHECK-NEXT: [[TOBOOL3:%.*]] = icmp eq i32 [[D]], 0
; CHECK-NEXT: br i1 [[TOBOOL3]], label [[IF_END7]], label [[IF_THEN4:%.*]]
; CHECK: if.then4:
; CHECK-NEXT: tail call void @bar() #[[ATTR0]]
; CHECK-NEXT: br label [[IF_END7]]
; CHECK: if.end7:
; CHECK-NEXT: [[X_0:%.*]] = phi ptr [ [[A]], [[IF_THEN]] ], [ [[C]], [[IF_THEN4]] ], [ null, [[IF_ELSE]] ]
; CHECK-NEXT: [[TMP9:%.*]] = load i32, ptr [[X_0]], align 4
; CHECK-NEXT: ret i32 [[TMP9]]
;
entry:
%tobool = icmp eq i32 %b, 0
br i1 %tobool, label %if.else, label %if.then
if.then: ; preds = %entry
tail call void @bar() nounwind
br label %if.end7
if.else: ; preds = %entry
%tobool3 = icmp eq i32 %d, 0
br i1 %tobool3, label %if.end7, label %if.then4
if.then4: ; preds = %if.else
tail call void @bar() nounwind
br label %if.end7
if.end7: ; preds = %if.else, %if.then4, %if.then
%x.0 = phi ptr [ %a, %if.then ], [ %c, %if.then4 ], [ null, %if.else ]
%tmp9 = load i32, ptr %x.0
ret i32 %tmp9
}
define i32 @test2(ptr %a, i32 %b, ptr %c, i32 %d) nounwind {
; CHECK-LABEL: define i32 @test2
; CHECK-SAME: (ptr [[A:%.*]], i32 [[B:%.*]], ptr [[C:%.*]], i32 [[D:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[B]], 0
; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: tail call void @bar() #[[ATTR0]]
; CHECK-NEXT: [[TMP9:%.*]] = load i32, ptr [[A]], align 4
; CHECK-NEXT: ret i32 [[TMP9]]
; CHECK: if.else:
; CHECK-NEXT: [[TOBOOL3:%.*]] = icmp eq i32 [[D]], 0
; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[TOBOOL3]], true
; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
; CHECK-NEXT: tail call void @bar() #[[ATTR0]]
; CHECK-NEXT: unreachable
;
entry:
%tobool = icmp eq i32 %b, 0
br i1 %tobool, label %if.else, label %if.then
if.then: ; preds = %entry
tail call void @bar() nounwind
br label %if.end7
if.else: ; preds = %entry
%tobool3 = icmp eq i32 %d, 0
br i1 %tobool3, label %if.end7, label %if.then4
if.then4: ; preds = %if.else
tail call void @bar() nounwind
br label %if.end7
if.end7: ; preds = %if.else, %if.then4, %if.then
%x.0 = phi ptr [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
%tmp9 = load i32, ptr %x.0
ret i32 %tmp9
}
define i32 @test2_no_null_opt(ptr %a, i32 %b, ptr %c, i32 %d) nounwind #0 {
; CHECK-LABEL: define i32 @test2_no_null_opt
; CHECK-SAME: (ptr [[A:%.*]], i32 [[B:%.*]], ptr [[C:%.*]], i32 [[D:%.*]]) #[[ATTR1]] {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[B]], 0
; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: tail call void @bar() #[[ATTR0]]
; CHECK-NEXT: br label [[IF_END7:%.*]]
; CHECK: if.else:
; CHECK-NEXT: [[TOBOOL3:%.*]] = icmp eq i32 [[D]], 0
; CHECK-NEXT: br i1 [[TOBOOL3]], label [[IF_END7]], label [[IF_THEN4:%.*]]
; CHECK: if.then4:
; CHECK-NEXT: tail call void @bar() #[[ATTR0]]
; CHECK-NEXT: br label [[IF_END7]]
; CHECK: if.end7:
; CHECK-NEXT: [[X_0:%.*]] = phi ptr [ [[A]], [[IF_THEN]] ], [ null, [[IF_THEN4]] ], [ null, [[IF_ELSE]] ]
; CHECK-NEXT: [[TMP9:%.*]] = load i32, ptr [[X_0]], align 4
; CHECK-NEXT: ret i32 [[TMP9]]
;
entry:
%tobool = icmp eq i32 %b, 0
br i1 %tobool, label %if.else, label %if.then
if.then: ; preds = %entry
tail call void @bar() nounwind
br label %if.end7
if.else: ; preds = %entry
%tobool3 = icmp eq i32 %d, 0
br i1 %tobool3, label %if.end7, label %if.then4
if.then4: ; preds = %if.else
tail call void @bar() nounwind
br label %if.end7
if.end7: ; preds = %if.else, %if.then4, %if.then
%x.0 = phi ptr [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
%tmp9 = load i32, ptr %x.0
ret i32 %tmp9
}
define i32 @test3(ptr %a, i32 %b, ptr %c, i32 %d) nounwind {
; CHECK-LABEL: define i32 @test3
; CHECK-SAME: (ptr [[A:%.*]], i32 [[B:%.*]], ptr [[C:%.*]], i32 [[D:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[B]], 0
; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: tail call void @bar() #[[ATTR0]]
; CHECK-NEXT: br label [[IF_END7:%.*]]
; CHECK: if.else:
; CHECK-NEXT: [[TOBOOL3:%.*]] = icmp eq i32 [[D]], 0
; CHECK-NEXT: br i1 [[TOBOOL3]], label [[IF_END7]], label [[IF_THEN4:%.*]]
; CHECK: if.then4:
; CHECK-NEXT: tail call void @bar() #[[ATTR0]]
; CHECK-NEXT: br label [[IF_END7]]
; CHECK: if.end7:
; CHECK-NEXT: [[X_0:%.*]] = phi ptr [ [[A]], [[IF_THEN]] ], [ null, [[IF_THEN4]] ], [ null, [[IF_ELSE]] ]
; CHECK-NEXT: tail call void @bar() #[[ATTR0]]
; CHECK-NEXT: [[TMP9:%.*]] = load i32, ptr [[X_0]], align 4
; CHECK-NEXT: ret i32 [[TMP9]]
;
entry:
%tobool = icmp eq i32 %b, 0
br i1 %tobool, label %if.else, label %if.then
if.then: ; preds = %entry
tail call void @bar() nounwind
br label %if.end7
if.else: ; preds = %entry
%tobool3 = icmp eq i32 %d, 0
br i1 %tobool3, label %if.end7, label %if.then4
if.then4: ; preds = %if.else
tail call void @bar() nounwind
br label %if.end7
if.end7: ; preds = %if.else, %if.then4, %if.then
%x.0 = phi ptr [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
tail call void @bar() nounwind
%tmp9 = load i32, ptr %x.0
ret i32 %tmp9
}
define i32 @test3_no_null_opt(ptr %a, i32 %b, ptr %c, i32 %d) nounwind #0 {
; CHECK-LABEL: define i32 @test3_no_null_opt
; CHECK-SAME: (ptr [[A:%.*]], i32 [[B:%.*]], ptr [[C:%.*]], i32 [[D:%.*]]) #[[ATTR1]] {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[B]], 0
; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: tail call void @bar() #[[ATTR0]]
; CHECK-NEXT: br label [[IF_END7:%.*]]
; CHECK: if.else:
; CHECK-NEXT: [[TOBOOL3:%.*]] = icmp eq i32 [[D]], 0
; CHECK-NEXT: br i1 [[TOBOOL3]], label [[IF_END7]], label [[IF_THEN4:%.*]]
; CHECK: if.then4:
; CHECK-NEXT: tail call void @bar() #[[ATTR0]]
; CHECK-NEXT: br label [[IF_END7]]
; CHECK: if.end7:
; CHECK-NEXT: [[X_0:%.*]] = phi ptr [ [[A]], [[IF_THEN]] ], [ null, [[IF_THEN4]] ], [ null, [[IF_ELSE]] ]
; CHECK-NEXT: tail call void @bar() #[[ATTR0]]
; CHECK-NEXT: [[TMP9:%.*]] = load i32, ptr [[X_0]], align 4
; CHECK-NEXT: ret i32 [[TMP9]]
;
entry:
%tobool = icmp eq i32 %b, 0
br i1 %tobool, label %if.else, label %if.then
if.then: ; preds = %entry
tail call void @bar() nounwind
br label %if.end7
if.else: ; preds = %entry
%tobool3 = icmp eq i32 %d, 0
br i1 %tobool3, label %if.end7, label %if.then4
if.then4: ; preds = %if.else
tail call void @bar() nounwind
br label %if.end7
if.end7: ; preds = %if.else, %if.then4, %if.then
%x.0 = phi ptr [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
tail call void @bar() nounwind
%tmp9 = load i32, ptr %x.0
ret i32 %tmp9
}
define i32 @test4(ptr %a, i32 %b, ptr %c, i32 %d) nounwind {
; CHECK-LABEL: define i32 @test4
; CHECK-SAME: (ptr [[A:%.*]], i32 [[B:%.*]], ptr [[C:%.*]], i32 [[D:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[B]], 0
; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: tail call void @bar() #[[ATTR0]]
; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, ptr [[A]], i32 10
; CHECK-NEXT: [[TMP9:%.*]] = load i32, ptr [[GEP]], align 4
; CHECK-NEXT: [[TMP10:%.*]] = or i32 [[TMP9]], 1
; CHECK-NEXT: store i32 [[TMP10]], ptr [[GEP]], align 4
; CHECK-NEXT: ret i32 [[TMP9]]
; CHECK: if.else:
; CHECK-NEXT: [[TOBOOL3:%.*]] = icmp eq i32 [[D]], 0
; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[TOBOOL3]], true
; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
; CHECK-NEXT: tail call void @bar() #[[ATTR0]]
; CHECK-NEXT: unreachable
;
entry:
%tobool = icmp eq i32 %b, 0
br i1 %tobool, label %if.else, label %if.then
if.then: ; preds = %entry
tail call void @bar() nounwind
br label %if.end7
if.else: ; preds = %entry
%tobool3 = icmp eq i32 %d, 0
br i1 %tobool3, label %if.end7, label %if.then4
if.then4: ; preds = %if.else
tail call void @bar() nounwind
br label %if.end7
if.end7: ; preds = %if.else, %if.then4, %if.then
%x.0 = phi ptr [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
%gep = getelementptr i32, ptr %x.0, i32 10
%tmp9 = load i32, ptr %gep
%tmp10 = or i32 %tmp9, 1
store i32 %tmp10, ptr %gep
ret i32 %tmp9
}
define i32 @test4_no_null_opt(ptr %a, i32 %b, ptr %c, i32 %d) nounwind #0 {
; CHECK-LABEL: define i32 @test4_no_null_opt
; CHECK-SAME: (ptr [[A:%.*]], i32 [[B:%.*]], ptr [[C:%.*]], i32 [[D:%.*]]) #[[ATTR1]] {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[B]], 0
; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: tail call void @bar() #[[ATTR0]]
; CHECK-NEXT: br label [[IF_END7:%.*]]
; CHECK: if.else:
; CHECK-NEXT: [[TOBOOL3:%.*]] = icmp eq i32 [[D]], 0
; CHECK-NEXT: br i1 [[TOBOOL3]], label [[IF_END7]], label [[IF_THEN4:%.*]]
; CHECK: if.then4:
; CHECK-NEXT: tail call void @bar() #[[ATTR0]]
; CHECK-NEXT: br label [[IF_END7]]
; CHECK: if.end7:
; CHECK-NEXT: [[X_0:%.*]] = phi ptr [ [[A]], [[IF_THEN]] ], [ null, [[IF_THEN4]] ], [ null, [[IF_ELSE]] ]
; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, ptr [[X_0]], i32 10
; CHECK-NEXT: [[TMP9:%.*]] = load i32, ptr [[GEP]], align 4
; CHECK-NEXT: [[TMP10:%.*]] = or i32 [[TMP9]], 1
; CHECK-NEXT: store i32 [[TMP10]], ptr [[GEP]], align 4
; CHECK-NEXT: ret i32 [[TMP9]]
;
entry:
%tobool = icmp eq i32 %b, 0
br i1 %tobool, label %if.else, label %if.then
if.then: ; preds = %entry
tail call void @bar() nounwind
br label %if.end7
if.else: ; preds = %entry
%tobool3 = icmp eq i32 %d, 0
br i1 %tobool3, label %if.end7, label %if.then4
if.then4: ; preds = %if.else
tail call void @bar() nounwind
br label %if.end7
if.end7: ; preds = %if.else, %if.then4, %if.then
%x.0 = phi ptr [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
%gep = getelementptr i32, ptr %x.0, i32 10
%tmp9 = load i32, ptr %gep
%tmp10 = or i32 %tmp9, 1
store i32 %tmp10, ptr %gep
ret i32 %tmp9
}
attributes #0 = { null_pointer_is_valid }