1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 @hello = constant [6 x i8] c"hello\00"
5 @null = constant [1 x i8] zeroinitializer
7 declare ptr @strndup(ptr, i64)
10 ; CHECK-LABEL: @test1(
11 ; CHECK-NEXT: [[STRDUP:%.*]] = call dereferenceable_or_null(1) ptr @strdup(ptr nonnull @null)
12 ; CHECK-NEXT: ret ptr [[STRDUP]]
14 %ret = call ptr @strndup(ptr @null, i64 0)
19 ; CHECK-LABEL: @test2(
20 ; CHECK-NEXT: [[RET:%.*]] = call dereferenceable_or_null(5) ptr @strndup(ptr nonnull dereferenceable(6) @hello, i64 4)
21 ; CHECK-NEXT: ret ptr [[RET]]
23 %ret = call ptr @strndup(ptr @hello, i64 4)
28 ; CHECK-LABEL: @test3(
29 ; CHECK-NEXT: [[STRDUP:%.*]] = call dereferenceable_or_null(6) ptr @strdup(ptr nonnull @hello)
30 ; CHECK-NEXT: ret ptr [[STRDUP]]
32 %ret = call ptr @strndup(ptr @hello, i64 5)
37 ; CHECK-LABEL: @test4(
38 ; CHECK-NEXT: [[STRDUP:%.*]] = call dereferenceable_or_null(6) ptr @strdup(ptr nonnull @hello)
39 ; CHECK-NEXT: ret ptr [[STRDUP]]
41 %ret = call ptr @strndup(ptr @hello, i64 6)
46 ; CHECK-LABEL: @test5(
47 ; CHECK-NEXT: [[STRDUP:%.*]] = call dereferenceable_or_null(6) ptr @strdup(ptr nonnull @hello)
48 ; CHECK-NEXT: ret ptr [[STRDUP]]
50 %ret = call ptr @strndup(ptr @hello, i64 7)
54 define ptr @test6(i64 %n) {
55 ; CHECK-LABEL: @test6(
56 ; CHECK-NEXT: [[RET:%.*]] = call ptr @strndup(ptr nonnull @hello, i64 [[N:%.*]])
57 ; CHECK-NEXT: ret ptr [[RET]]
59 %ret = call ptr @strndup(ptr @hello, i64 %n)