1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 ; Passing select(cond, null, v) as nonnull should be optimized to passing v
6 define nonnull ptr @pr48975(ptr %.0) {
7 ; CHECK-LABEL: @pr48975(
8 ; CHECK-NEXT: [[DOT1:%.*]] = load ptr, ptr [[DOT0:%.*]], align 8
9 ; CHECK-NEXT: [[DOT2:%.*]] = icmp eq ptr [[DOT1]], null
10 ; CHECK-NEXT: [[DOT4:%.*]] = select i1 [[DOT2]], ptr null, ptr [[DOT0]]
11 ; CHECK-NEXT: ret ptr [[DOT4]]
13 %.1 = load ptr, ptr %.0, align 8
14 %.2 = icmp eq ptr %.1, null
15 %.4 = select i1 %.2, ptr null, ptr %.0
19 define nonnull ptr @nonnull_ret(i1 %cond, ptr %p) {
20 ; CHECK-LABEL: @nonnull_ret(
21 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[COND:%.*]], ptr [[P:%.*]], ptr null
22 ; CHECK-NEXT: ret ptr [[RES]]
24 %res = select i1 %cond, ptr %p, ptr null
28 define nonnull ptr @nonnull_ret2(i1 %cond, ptr %p) {
29 ; CHECK-LABEL: @nonnull_ret2(
30 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[COND:%.*]], ptr null, ptr [[P:%.*]]
31 ; CHECK-NEXT: ret ptr [[RES]]
33 %res = select i1 %cond, ptr null, ptr %p
37 define nonnull noundef ptr @nonnull_noundef_ret(i1 %cond, ptr %p) {
38 ; CHECK-LABEL: @nonnull_noundef_ret(
39 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[COND:%.*]], ptr [[P:%.*]], ptr null
40 ; CHECK-NEXT: ret ptr [[RES]]
42 %res = select i1 %cond, ptr %p, ptr null
46 define nonnull noundef ptr @nonnull_noundef_ret2(i1 %cond, ptr %p) {
47 ; CHECK-LABEL: @nonnull_noundef_ret2(
48 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[COND:%.*]], ptr null, ptr [[P:%.*]]
49 ; CHECK-NEXT: ret ptr [[RES]]
51 %res = select i1 %cond, ptr null, ptr %p
56 define void @nonnull_call(i1 %cond, ptr %p) {
57 ; CHECK-LABEL: @nonnull_call(
58 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[COND:%.*]], ptr [[P:%.*]], ptr null
59 ; CHECK-NEXT: call void @f(ptr nonnull [[RES]])
60 ; CHECK-NEXT: ret void
62 %res = select i1 %cond, ptr %p, ptr null
63 call void @f(ptr nonnull %res)
67 define void @nonnull_call2(i1 %cond, ptr %p) {
68 ; CHECK-LABEL: @nonnull_call2(
69 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[COND:%.*]], ptr null, ptr [[P:%.*]]
70 ; CHECK-NEXT: call void @f(ptr nonnull [[RES]])
71 ; CHECK-NEXT: ret void
73 %res = select i1 %cond, ptr null, ptr %p
74 call void @f(ptr nonnull %res)
78 define void @nonnull_noundef_call(i1 %cond, ptr %p) {
79 ; CHECK-LABEL: @nonnull_noundef_call(
80 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[COND:%.*]], ptr [[P:%.*]], ptr null
81 ; CHECK-NEXT: call void @f(ptr noundef nonnull [[RES]])
82 ; CHECK-NEXT: ret void
84 %res = select i1 %cond, ptr %p, ptr null
85 call void @f(ptr nonnull noundef %res)
89 define void @nonnull_noundef_call2(i1 %cond, ptr %p) {
90 ; CHECK-LABEL: @nonnull_noundef_call2(
91 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[COND:%.*]], ptr null, ptr [[P:%.*]]
92 ; CHECK-NEXT: call void @f(ptr noundef nonnull [[RES]])
93 ; CHECK-NEXT: ret void
95 %res = select i1 %cond, ptr null, ptr %p
96 call void @f(ptr nonnull noundef %res)