1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 @hello = constant [6 x i8] c"hello\00"
5 @null = constant [1 x i8] zeroinitializer
7 declare i8* @strndup(i8*, i32)
10 ; CHECK-LABEL: @test1(
11 ; CHECK-NEXT: [[STRDUP:%.*]] = call dereferenceable_or_null(1) i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @null, i64 0, i64 0))
12 ; CHECK-NEXT: ret i8* [[STRDUP]]
14 %src = getelementptr [1 x i8], [1 x i8]* @null, i32 0, i32 0
15 %ret = call i8* @strndup(i8* %src, i32 0)
20 ; CHECK-LABEL: @test2(
21 ; CHECK-NEXT: [[RET:%.*]] = call dereferenceable_or_null(5) i8* @strndup(i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i64 0, i64 0), i32 4)
22 ; CHECK-NEXT: ret i8* [[RET]]
24 %src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0
25 %ret = call i8* @strndup(i8* %src, i32 4)
30 ; CHECK-LABEL: @test3(
31 ; CHECK-NEXT: [[STRDUP:%.*]] = call dereferenceable_or_null(6) i8* @strdup(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i64 0, i64 0))
32 ; CHECK-NEXT: ret i8* [[STRDUP]]
34 %src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0
35 %ret = call i8* @strndup(i8* %src, i32 5)
40 ; CHECK-LABEL: @test4(
41 ; CHECK-NEXT: [[STRDUP:%.*]] = call dereferenceable_or_null(6) i8* @strdup(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i64 0, i64 0))
42 ; CHECK-NEXT: ret i8* [[STRDUP]]
44 %src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0
45 %ret = call i8* @strndup(i8* %src, i32 6)
50 ; CHECK-LABEL: @test5(
51 ; CHECK-NEXT: [[STRDUP:%.*]] = call dereferenceable_or_null(6) i8* @strdup(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i64 0, i64 0))
52 ; CHECK-NEXT: ret i8* [[STRDUP]]
54 %src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0
55 %ret = call i8* @strndup(i8* %src, i32 7)
59 define i8* @test6(i32 %n) {
60 ; CHECK-LABEL: @test6(
61 ; CHECK-NEXT: [[RET:%.*]] = call i8* @strndup(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i64 0, i64 0), i32 [[N:%.*]])
62 ; CHECK-NEXT: ret i8* [[RET]]
64 %src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0
65 %ret = call i8* @strndup(i8* %src, i32 %n)