1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=lower-constant-intrinsics -S < %s | FileCheck %s
5 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
6 target triple = "x86_64-unknown-linux-gnu"
8 declare dso_local noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr allocsize(0)
9 declare i64 @llvm.objectsize.i64.p0(ptr, i1 immarg, i1 immarg, i1 immarg)
11 @buffer = dso_local global [4 x i8] zeroinitializer, align 1
13 define dso_local i64 @pick_max(i32 noundef %n) local_unnamed_addr {
14 ; CHECK-LABEL: @pick_max(
16 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[N:%.*]], 0
17 ; CHECK-NEXT: br i1 [[COND]], label [[IF_ELSE:%.*]], label [[IF_END:%.*]]
19 ; CHECK-NEXT: [[MALLOCED:%.*]] = call noalias dereferenceable_or_null(8) ptr @malloc(i64 noundef 8)
20 ; CHECK-NEXT: br label [[IF_END]]
22 ; CHECK-NEXT: [[P:%.*]] = phi ptr [ [[MALLOCED]], [[IF_ELSE]] ], [ @buffer, [[ENTRY:%.*]] ]
23 ; CHECK-NEXT: ret i64 8
26 %cond = icmp eq i32 %n, 0
27 br i1 %cond, label %if.else, label %if.end
30 %malloced = call noalias dereferenceable_or_null(8) ptr @malloc(i64 noundef 8)
34 %p = phi ptr [ %malloced, %if.else ], [ @buffer, %entry ]
35 %size = call i64 @llvm.objectsize.i64.p0(ptr %p, i1 false, i1 true, i1 false)
39 define dso_local i64 @pick_min(i32 noundef %n) local_unnamed_addr {
40 ; CHECK-LABEL: @pick_min(
42 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[N:%.*]], 0
43 ; CHECK-NEXT: br i1 [[COND]], label [[IF_ELSE:%.*]], label [[IF_END:%.*]]
45 ; CHECK-NEXT: [[MALLOCED:%.*]] = call noalias dereferenceable_or_null(8) ptr @malloc(i64 noundef 8)
46 ; CHECK-NEXT: br label [[IF_END]]
48 ; CHECK-NEXT: [[P:%.*]] = phi ptr [ [[MALLOCED]], [[IF_ELSE]] ], [ @buffer, [[ENTRY:%.*]] ]
49 ; CHECK-NEXT: ret i64 4
52 %cond = icmp eq i32 %n, 0
53 br i1 %cond, label %if.else, label %if.end
56 %malloced = call noalias dereferenceable_or_null(8) ptr @malloc(i64 noundef 8)
60 %p = phi ptr [ %malloced, %if.else ], [ @buffer, %entry ]
61 %size = call i64 @llvm.objectsize.i64.p0(ptr %p, i1 true, i1 true, i1 false)
65 define i64 @pick_max_same(i32 %n) {
66 ; CHECK-LABEL: @pick_max_same(
68 ; CHECK-NEXT: [[BUFFER:%.*]] = alloca i8, i64 20, align 1
69 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[N:%.*]], 0
70 ; CHECK-NEXT: br i1 [[COND]], label [[IF_ELSE:%.*]], label [[IF_END:%.*]]
72 ; CHECK-NEXT: [[OFFSETED:%.*]] = getelementptr i8, ptr [[BUFFER]], i64 10
73 ; CHECK-NEXT: br label [[IF_END]]
75 ; CHECK-NEXT: [[P:%.*]] = phi ptr [ [[OFFSETED]], [[IF_ELSE]] ], [ [[BUFFER]], [[ENTRY:%.*]] ]
76 ; CHECK-NEXT: ret i64 20
79 %buffer = alloca i8, i64 20
80 %cond = icmp eq i32 %n, 0
81 br i1 %cond, label %if.else, label %if.end
84 %offseted = getelementptr i8, ptr %buffer, i64 10
88 %p = phi ptr [ %offseted, %if.else ], [ %buffer, %entry ]
89 %size = call i64 @llvm.objectsize.i64.p0(ptr %p, i1 false, i1 true, i1 false)
93 define i64 @pick_min_same(i32 %n) {
94 ; CHECK-LABEL: @pick_min_same(
96 ; CHECK-NEXT: [[BUFFER:%.*]] = alloca i8, i64 20, align 1
97 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[N:%.*]], 0
98 ; CHECK-NEXT: br i1 [[COND]], label [[IF_ELSE:%.*]], label [[IF_END:%.*]]
100 ; CHECK-NEXT: [[OFFSETED:%.*]] = getelementptr i8, ptr [[BUFFER]], i64 10
101 ; CHECK-NEXT: br label [[IF_END]]
103 ; CHECK-NEXT: [[P:%.*]] = phi ptr [ [[OFFSETED]], [[IF_ELSE]] ], [ [[BUFFER]], [[ENTRY:%.*]] ]
104 ; CHECK-NEXT: ret i64 10
107 %buffer = alloca i8, i64 20
108 %cond = icmp eq i32 %n, 0
109 br i1 %cond, label %if.else, label %if.end
112 %offseted = getelementptr i8, ptr %buffer, i64 10
116 %p = phi ptr [ %offseted, %if.else ], [ %buffer, %entry ]
117 %size = call i64 @llvm.objectsize.i64.p0(ptr %p, i1 true, i1 true, i1 false)