1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -lower-constant-intrinsics  -S < %s | FileCheck %s
3
4
5target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
6target triple = "x86_64-unknown-linux-gnu"
7
8declare dso_local noalias noundef i8* @malloc(i64 noundef) local_unnamed_addr allocsize(0)
9declare i64 @llvm.objectsize.i64.p0i8(i8*, i1 immarg, i1 immarg, i1 immarg)
10
11@buffer = dso_local global [4 x i8] zeroinitializer, align 1
12
13define dso_local i64 @pick_max(i32 noundef %n) local_unnamed_addr {
14; CHECK-LABEL: @pick_max(
15; CHECK-NEXT:  entry:
16; CHECK-NEXT:    [[COND:%.*]] = icmp eq i32 [[N:%.*]], 0
17; CHECK-NEXT:    br i1 [[COND]], label [[IF_ELSE:%.*]], label [[IF_END:%.*]]
18; CHECK:       if.else:
19; CHECK-NEXT:    [[MALLOCED:%.*]] = call noalias dereferenceable_or_null(8) i8* @malloc(i64 noundef 8)
20; CHECK-NEXT:    br label [[IF_END]]
21; CHECK:       if.end:
22; CHECK-NEXT:    [[P:%.*]] = phi i8* [ [[MALLOCED]], [[IF_ELSE]] ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @buffer, i64 0, i64 0), [[ENTRY:%.*]] ]
23; CHECK-NEXT:    ret i64 8
24;
25entry:
26  %cond = icmp eq i32 %n, 0
27  br i1 %cond, label %if.else, label %if.end
28
29if.else:
30  %malloced = call noalias dereferenceable_or_null(8) i8* @malloc(i64 noundef 8)
31  br label %if.end
32
33if.end:
34  %p = phi i8* [ %malloced, %if.else ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @buffer, i64 0, i64 0), %entry ]
35  %size = call i64 @llvm.objectsize.i64.p0i8(i8* %p, i1 false, i1 true, i1 false)
36  ret i64 %size
37}
38
39define dso_local i64 @pick_min(i32 noundef %n) local_unnamed_addr {
40; CHECK-LABEL: @pick_min(
41; CHECK-NEXT:  entry:
42; CHECK-NEXT:    [[COND:%.*]] = icmp eq i32 [[N:%.*]], 0
43; CHECK-NEXT:    br i1 [[COND]], label [[IF_ELSE:%.*]], label [[IF_END:%.*]]
44; CHECK:       if.else:
45; CHECK-NEXT:    [[MALLOCED:%.*]] = call noalias dereferenceable_or_null(8) i8* @malloc(i64 noundef 8)
46; CHECK-NEXT:    br label [[IF_END]]
47; CHECK:       if.end:
48; CHECK-NEXT:    [[P:%.*]] = phi i8* [ [[MALLOCED]], [[IF_ELSE]] ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @buffer, i64 0, i64 0), [[ENTRY:%.*]] ]
49; CHECK-NEXT:    ret i64 4
50;
51entry:
52  %cond = icmp eq i32 %n, 0
53  br i1 %cond, label %if.else, label %if.end
54
55if.else:
56  %malloced = call noalias dereferenceable_or_null(8) i8* @malloc(i64 noundef 8)
57  br label %if.end
58
59if.end:
60  %p = phi i8* [ %malloced, %if.else ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @buffer, i64 0, i64 0), %entry ]
61  %size = call i64 @llvm.objectsize.i64.p0i8(i8* %p, i1 true, i1 true, i1 false)
62  ret i64 %size
63}
64