1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -instcombine -S | FileCheck %s 3 4@hello = constant [6 x i8] c"hello\00" 5@null = constant [1 x i8] zeroinitializer 6 7declare i8* @strndup(i8*, i32) 8 9define i8* @test1() { 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]] 13; 14 %src = getelementptr [1 x i8], [1 x i8]* @null, i32 0, i32 0 15 %ret = call i8* @strndup(i8* %src, i32 0) 16 ret i8* %ret 17} 18 19define i8* @test2() { 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]] 23; 24 %src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0 25 %ret = call i8* @strndup(i8* %src, i32 4) 26 ret i8* %ret 27} 28 29define i8* @test3() { 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]] 33; 34 %src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0 35 %ret = call i8* @strndup(i8* %src, i32 5) 36 ret i8* %ret 37} 38 39define i8* @test4() { 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]] 43; 44 %src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0 45 %ret = call i8* @strndup(i8* %src, i32 6) 46 ret i8* %ret 47} 48 49define i8* @test5() { 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]] 53; 54 %src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0 55 %ret = call i8* @strndup(i8* %src, i32 7) 56 ret i8* %ret 57} 58 59define 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]] 63; 64 %src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0 65 %ret = call i8* @strndup(i8* %src, i32 %n) 66 ret i8* %ret 67} 68