• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instcombine -S | FileCheck %s
3
4; InstCombine should mark null-checked argument as nonnull at callsite
5declare void @dummy(i32*, i32)
6
7define void @test(i32* %a, i32 %b) {
8; CHECK-LABEL: @test(
9; CHECK-NEXT:  entry:
10; CHECK-NEXT:    [[COND1:%.*]] = icmp eq i32* %a, null
11; CHECK-NEXT:    br i1 [[COND1]], label %dead, label %not_null
12; CHECK:       not_null:
13; CHECK-NEXT:    [[COND2:%.*]] = icmp eq i32 %b, 0
14; CHECK-NEXT:    br i1 [[COND2]], label %dead, label %not_zero
15; CHECK:       not_zero:
16; CHECK-NEXT:    call void @dummy(i32* nonnull %a, i32 %b)
17; CHECK-NEXT:    ret void
18; CHECK:       dead:
19; CHECK-NEXT:    unreachable
20;
21entry:
22  %cond1 = icmp eq i32* %a, null
23  br i1 %cond1, label %dead, label %not_null
24not_null:
25  %cond2 = icmp eq i32 %b, 0
26  br i1 %cond2, label %dead, label %not_zero
27not_zero:
28  call void @dummy(i32* %a, i32 %b)
29  ret void
30dead:
31  unreachable
32}
33
34; The nonnull attribute in the 'bar' declaration is
35; propagated to the parameters of the 'baz' callsite.
36
37declare void @bar(i8*, i8* nonnull)
38declare void @baz(i8*, i8*)
39
40define void @deduce_nonnull_from_another_call(i8* %a, i8* %b) {
41; CHECK-LABEL: @deduce_nonnull_from_another_call(
42; CHECK-NEXT:    call void @bar(i8* %a, i8* %b)
43; CHECK-NEXT:    call void @baz(i8* nonnull %b, i8* nonnull %b)
44; CHECK-NEXT:    ret void
45;
46  call void @bar(i8* %a, i8* %b)
47  call void @baz(i8* %b, i8* %b)
48  ret void
49}
50
51