80 changes: 73 additions & 7 deletions llvm/test/Transforms/InstCombine/strncpy-1.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; Test that the strncpy library call simplifier works correctly.
;
; RUN: opt < %s -instcombine -S | FileCheck %s
Expand All @@ -17,8 +18,15 @@ declare i32 @puts(i8*)

define i32 @test_simplify1() {
; CHECK-LABEL: @test_simplify1(
; CHECK-NOT: call i8* @strncpy
; CHECK: call i32 @puts
; CHECK-NEXT: [[TARGET:%.*]] = alloca [1024 x i8], align 1
; CHECK-NEXT: [[ARG1:%.*]] = getelementptr inbounds [1024 x i8], [1024 x i8]* [[TARGET]], i32 0, i32 0
; CHECK-NEXT: store i8 0, i8* [[ARG1]], align 1
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* nonnull align 1 dereferenceable(6) [[ARG1]], i8* nonnull align 1 dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i32 0, i32 0), i32 6, i1 false)
; CHECK-NEXT: call void @llvm.memset.p0i8.i32(i8* nonnull align 1 dereferenceable(42) [[ARG1]], i8 0, i32 42, i1 false)
; CHECK-NEXT: call void @llvm.memset.p0i8.i32(i8* nonnull align 1 dereferenceable(42) [[ARG1]], i8 0, i32 42, i1 false)
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @puts(i8* nonnull [[ARG1]])
; CHECK-NEXT: ret i32 0
;
%target = alloca [1024 x i8]
%arg1 = getelementptr [1024 x i8], [1024 x i8]* %target, i32 0, i32 0
store i8 0, i8* %arg1
Expand All @@ -40,56 +48,114 @@ define i32 @test_simplify1() {

define void @test_simplify2() {
; CHECK-LABEL: @test_simplify2(
; CHECK-NEXT: call void @llvm.memset.p0i8.i32(i8* nonnull align 1 dereferenceable(32) getelementptr inbounds ([32 x i8], [32 x i8]* @a, i32 0, i32 0), i8 0, i32 32, i1 false)
; CHECK-NEXT: ret void
;
%dst = getelementptr [32 x i8], [32 x i8]* @a, i32 0, i32 0
%src = getelementptr [1 x i8], [1 x i8]* @null, i32 0, i32 0

call i8* @strncpy(i8* %dst, i8* %src, i32 32)
; CHECK: call void @llvm.memset.p0i8.i32
ret void
}

; Check strncpy(x, y, 0) -> x.

define i8* @test_simplify3() {
; CHECK-LABEL: @test_simplify3(
; CHECK-NEXT: ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @a, i32 0, i32 0)
;
%dst = getelementptr [32 x i8], [32 x i8]* @a, i32 0, i32 0
%src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0

%ret = call i8* @strncpy(i8* %dst, i8* %src, i32 0)
ret i8* %ret
; CHECK: ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @a, i32 0, i32 0)
}

; Check strncpy(x, s, c) -> memcpy(x, s, c, 1) [s and c are constant].

define void @test_simplify4() {
; CHECK-LABEL: @test_simplify4(
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* nonnull align 1 dereferenceable(6) getelementptr inbounds ([32 x i8], [32 x i8]* @a, i32 0, i32 0), i8* nonnull align 1 dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i32 0, i32 0), i32 6, i1 false)
; CHECK-NEXT: ret void
;
%dst = getelementptr [32 x i8], [32 x i8]* @a, i32 0, i32 0
%src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0

call i8* @strncpy(i8* %dst, i8* %src, i32 6)
; CHECK: call void @llvm.memcpy.p0i8.p0i8.i32
ret void
}

define void @test_simplify5(i8* %dst) {
; CHECK-LABEL: @test_simplify5(
; CHECK-NEXT: [[TMP1:%.*]] = call i8* @strncpy(i8* nonnull dereferenceable(8) [[DST:%.*]], i8* nonnull dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i32 0, i32 0), i32 32)
; CHECK-NEXT: ret void
;
%src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0
call i8* @strncpy(i8* dereferenceable(8) %dst, i8* %src, i32 32)
ret void
}

define void @test_simplify6(i8* %dst) {
; CHECK-LABEL: @test_simplify6(
; CHECK-NEXT: [[TMP1:%.*]] = call i8* @strncpy(i8* nonnull dereferenceable(80) [[DST:%.*]], i8* nonnull dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i32 0, i32 0), i32 32)
; CHECK-NEXT: ret void
;
%src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0
call i8* @strncpy(i8* dereferenceable(80) %dst, i8* %src, i32 32)
ret void
}

define void @test_simplify7(i8* %dst, i32 %n) {
; CHECK-LABEL: @test_simplify7(
; CHECK-NEXT: [[TMP1:%.*]] = call i8* @strncpy(i8* nonnull dereferenceable(80) [[DST:%.*]], i8* getelementptr inbounds ([1 x i8], [1 x i8]* @null, i32 0, i32 0), i32 [[N:%.*]])
; CHECK-NEXT: ret void
;
%src = getelementptr [1 x i8], [1 x i8]* @null, i32 0, i32 0
call i8* @strncpy(i8* dereferenceable(80) %dst, i8* %src, i32 %n)
ret void
}

define i8* @test1(i8* %dst, i8* %src, i32 %n) {
; CHECK-LABEL: @test1(
; CHECK-NEXT: [[RET:%.*]] = call i8* @strncpy(i8* nonnull [[DST:%.*]], i8* nonnull [[SRC:%.*]], i32 [[N:%.*]])
; CHECK-NEXT: ret i8* [[RET]]
;
%ret = call i8* @strncpy(i8* nonnull %dst, i8* nonnull %src, i32 %n)
ret i8* %ret
}

define i8* @test2(i8* %dst) {
; CHECK-LABEL: @test2(
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* nonnull align 1 dereferenceable(5) [[DST:%.*]], i8* nonnull align 1 dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i32 0, i32 0), i32 5, i1 false)
; CHECK-NEXT: ret i8* [[DST]]
;
%src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0
%ret = call i8* @strncpy(i8* nonnull %dst, i8* nonnull %src, i32 5)
ret i8* %ret
}

; Check cases that shouldn't be simplified.

define void @test_no_simplify1() {
; CHECK-LABEL: @test_no_simplify1(
; CHECK-NEXT: [[TMP1:%.*]] = call i8* @strncpy(i8* nonnull dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @a, i32 0, i32 0), i8* nonnull dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @b, i32 0, i32 0), i32 32)
; CHECK-NEXT: ret void
;
%dst = getelementptr [32 x i8], [32 x i8]* @a, i32 0, i32 0
%src = getelementptr [32 x i8], [32 x i8]* @b, i32 0, i32 0

call i8* @strncpy(i8* %dst, i8* %src, i32 32)
; CHECK: call i8* @strncpy
ret void
}

define void @test_no_simplify2() {
; CHECK-LABEL: @test_no_simplify2(
; CHECK-NEXT: [[TMP1:%.*]] = call i8* @strncpy(i8* nonnull dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @a, i32 0, i32 0), i8* nonnull dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i32 0, i32 0), i32 8)
; CHECK-NEXT: ret void
;
%dst = getelementptr [32 x i8], [32 x i8]* @a, i32 0, i32 0
%src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0

call i8* @strncpy(i8* %dst, i8* %src, i32 8)
; CHECK: call i8* @strncpy
ret void
}
5 changes: 4 additions & 1 deletion llvm/test/Transforms/InstCombine/strncpy-2.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; Test that the strncpy library call simplifier works correctly.
;
; RUN: opt < %s -instcombine -S | FileCheck %s
Expand All @@ -13,10 +14,12 @@ declare i16* @strncpy(i8*, i8*, i32)

define void @test_no_simplify1() {
; CHECK-LABEL: @test_no_simplify1(
; CHECK-NEXT: [[TMP1:%.*]] = call i16* @strncpy(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @a, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i32 0, i32 0), i32 6)
; CHECK-NEXT: ret void
;
%dst = getelementptr [32 x i8], [32 x i8]* @a, i32 0, i32 0
%src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0

call i16* @strncpy(i8* %dst, i8* %src, i32 6)
; CHECK: call i16* @strncpy
ret void
}
6 changes: 3 additions & 3 deletions llvm/test/Transforms/InstCombine/strncpy_chk-1.ll
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f3

define i8* @test_simplify1() {
; CHECK-LABEL: @test_simplify1(
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 dereferenceable(12) getelementptr inbounds ([60 x i8], [60 x i8]* @a, i32 0, i32 0), i8* align 1 dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0), i32 12, i1 false)
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* nonnull align 1 dereferenceable(12) getelementptr inbounds ([60 x i8], [60 x i8]* @a, i32 0, i32 0), i8* nonnull align 1 dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0), i32 12, i1 false)
; CHECK-NEXT: ret i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i32 0, i32 0)
;
%dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
Expand All @@ -26,7 +26,7 @@ define i8* @test_simplify1() {

define i8* @test_simplify2() {
; CHECK-LABEL: @test_simplify2(
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 dereferenceable(12) getelementptr inbounds ([60 x i8], [60 x i8]* @a, i32 0, i32 0), i8* align 1 dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0), i32 12, i1 false)
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* nonnull align 1 dereferenceable(12) getelementptr inbounds ([60 x i8], [60 x i8]* @a, i32 0, i32 0), i8* nonnull align 1 dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0), i32 12, i1 false)
; CHECK-NEXT: ret i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i32 0, i32 0)
;
%dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
Expand All @@ -38,7 +38,7 @@ define i8* @test_simplify2() {

define i8* @test_simplify3() {
; CHECK-LABEL: @test_simplify3(
; CHECK-NEXT: [[STRNCPY:%.*]] = call i8* @strncpy(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i32 0, i32 0), i8* getelementptr inbounds ([60 x i8], [60 x i8]* @b, i32 0, i32 0), i32 12)
; CHECK-NEXT: [[STRNCPY:%.*]] = call i8* @strncpy(i8* nonnull dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @a, i32 0, i32 0), i8* nonnull dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @b, i32 0, i32 0), i32 12)
; CHECK-NEXT: ret i8* [[STRNCPY]]
;
%dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
Expand Down
20 changes: 13 additions & 7 deletions llvm/test/Transforms/InstCombine/strpbrk-1.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; Test that the strpbrk library call simplifier works correctly.
;
; RUN: opt < %s -instcombine -S | FileCheck %s
Expand All @@ -14,55 +15,60 @@ declare i8* @strpbrk(i8*, i8*)

define i8* @test_simplify1(i8* %str) {
; CHECK-LABEL: @test_simplify1(
; CHECK-NEXT: ret i8* null
;
%pat = getelementptr [1 x i8], [1 x i8]* @null, i32 0, i32 0

%ret = call i8* @strpbrk(i8* %str, i8* %pat)
ret i8* %ret
; CHECK-NEXT: ret i8* null
}

; Check strpbrk("", s) -> NULL.

define i8* @test_simplify2(i8* %pat) {
; CHECK-LABEL: @test_simplify2(
; CHECK-NEXT: ret i8* null
;
%str = getelementptr [1 x i8], [1 x i8]* @null, i32 0, i32 0

%ret = call i8* @strpbrk(i8* %str, i8* %pat)
ret i8* %ret
; CHECK-NEXT: ret i8* null
}

; Check strpbrk(s1, s2), where s1 and s2 are constants.

define i8* @test_simplify3() {
; CHECK-LABEL: @test_simplify3(
; CHECK-NEXT: ret i8* getelementptr inbounds ([12 x i8], [12 x i8]* @hello, i32 0, i32 6)
;
%str = getelementptr [12 x i8], [12 x i8]* @hello, i32 0, i32 0
%pat = getelementptr [2 x i8], [2 x i8]* @w, i32 0, i32 0

%ret = call i8* @strpbrk(i8* %str, i8* %pat)
ret i8* %ret
; CHECK-NEXT: ret i8* getelementptr inbounds ([12 x i8], [12 x i8]* @hello, i32 0, i32 6)
}

; Check strpbrk(s, "a") -> strchr(s, 'a').

define i8* @test_simplify4(i8* %str) {
; CHECK-LABEL: @test_simplify4(
; CHECK-NEXT: [[STRCHR:%.*]] = call i8* @strchr(i8* nonnull dereferenceable(1) [[STR:%.*]], i32 119)
; CHECK-NEXT: ret i8* [[STRCHR]]
;
%pat = getelementptr [2 x i8], [2 x i8]* @w, i32 0, i32 0

%ret = call i8* @strpbrk(i8* %str, i8* %pat)
; CHECK-NEXT: [[VAR:%[a-z]+]] = call i8* @strchr(i8* %str, i32 119)
ret i8* %ret
; CHECK-NEXT: ret i8* [[VAR]]
}

; Check cases that shouldn't be simplified.

define i8* @test_no_simplify1(i8* %str, i8* %pat) {
; CHECK-LABEL: @test_no_simplify1(
; CHECK-NEXT: [[RET:%.*]] = call i8* @strpbrk(i8* [[STR:%.*]], i8* [[PAT:%.*]])
; CHECK-NEXT: ret i8* [[RET]]
;

%ret = call i8* @strpbrk(i8* %str, i8* %pat)
; CHECK-NEXT: %ret = call i8* @strpbrk(i8* %str, i8* %pat)
ret i8* %ret
; CHECK-NEXT: ret i8* %ret
}
55 changes: 41 additions & 14 deletions llvm/test/Transforms/InstCombine/strrchr-1.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; Test that the strrchr library call simplifier works correctly.
; RUN: opt < %s -instcombine -S | FileCheck %s

Expand All @@ -10,9 +11,10 @@ target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f3
declare i8* @strrchr(i8*, i32)

define void @test_simplify1() {
; CHECK: store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @hello, i32 0, i32 6)
; CHECK-NOT: call i8* @strrchr
; CHECK: ret void
; CHECK-LABEL: @test_simplify1(
; CHECK-NEXT: store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @hello, i32 0, i32 6), i8** @chp, align 4
; CHECK-NEXT: ret void
;

%str = getelementptr [14 x i8], [14 x i8]* @hello, i32 0, i32 0
%dst = call i8* @strrchr(i8* %str, i32 119)
Expand All @@ -21,9 +23,10 @@ define void @test_simplify1() {
}

define void @test_simplify2() {
; CHECK: store i8* null, i8** @chp, align 4
; CHECK-NOT: call i8* @strrchr
; CHECK: ret void
; CHECK-LABEL: @test_simplify2(
; CHECK-NEXT: store i8* null, i8** @chp, align 4
; CHECK-NEXT: ret void
;

%str = getelementptr [1 x i8], [1 x i8]* @null, i32 0, i32 0
%dst = call i8* @strrchr(i8* %str, i32 119)
Expand All @@ -32,9 +35,10 @@ define void @test_simplify2() {
}

define void @test_simplify3() {
; CHECK: store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @hello, i32 0, i32 13)
; CHECK-NOT: call i8* @strrchr
; CHECK: ret void
; CHECK-LABEL: @test_simplify3(
; CHECK-NEXT: store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @hello, i32 0, i32 13), i8** @chp, align 4
; CHECK-NEXT: ret void
;

%src = getelementptr [14 x i8], [14 x i8]* @hello, i32 0, i32 0
%dst = call i8* @strrchr(i8* %src, i32 0)
Expand All @@ -43,9 +47,10 @@ define void @test_simplify3() {
}

define void @test_simplify4() {
; CHECK: store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @hello, i32 0, i32 13)
; CHECK-NOT: call i8* @strrchr
; CHECK: ret void
; CHECK-LABEL: @test_simplify4(
; CHECK-NEXT: store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @hello, i32 0, i32 13), i8** @chp, align 4
; CHECK-NEXT: ret void
;

%src = getelementptr [14 x i8], [14 x i8]* @hello, i32 0, i32 0
%dst = call i8* @strrchr(i8* %src, i32 65280)
Expand All @@ -55,11 +60,33 @@ define void @test_simplify4() {

define void @test_nosimplify1(i32 %chr) {
; CHECK-LABEL: @test_nosimplify1(
; CHECK: call i8* @strrchr
; CHECK: ret void
; CHECK-NEXT: [[DST:%.*]] = call i8* @strrchr(i8* nonnull dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @hello, i32 0, i32 0), i32 [[CHR:%.*]])
; CHECK-NEXT: store i8* [[DST]], i8** @chp, align 4
; CHECK-NEXT: ret void
;

%src = getelementptr [14 x i8], [14 x i8]* @hello, i32 0, i32 0
%dst = call i8* @strrchr(i8* %src, i32 %chr)
store i8* %dst, i8** @chp
ret void
}

define i8* @test1(i8* %str, i32 %c) {
; CHECK-LABEL: @test1(
; CHECK-NEXT: [[RET:%.*]] = call i8* @strrchr(i8* nonnull dereferenceable(1) [[STR:%.*]], i32 [[C:%.*]])
; CHECK-NEXT: ret i8* [[RET]]
;

%ret = call i8* @strrchr(i8* %str, i32 %c)
ret i8* %ret
}

define i8* @test2(i8* %str, i32 %c) "null-pointer-is-valid"="true" {
; CHECK-LABEL: @test2(
; CHECK-NEXT: [[RET:%.*]] = call i8* @strrchr(i8* [[STR:%.*]], i32 [[C:%.*]])
; CHECK-NEXT: ret i8* [[RET]]
;

%ret = call i8* @strrchr(i8* %str, i32 %c)
ret i8* %ret
}
41 changes: 33 additions & 8 deletions llvm/test/Transforms/InstCombine/strstr-1.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; Test that the strstr library call simplifier works correctly.
;
; RUN: opt < %s -instcombine -S | FileCheck %s
Expand All @@ -15,51 +16,75 @@ declare i8* @strstr(i8*, i8*)

define i8* @test_simplify1(i8* %str) {
; CHECK-LABEL: @test_simplify1(
; CHECK-NEXT: ret i8* [[STR:%.*]]
;
%pat = getelementptr inbounds [1 x i8], [1 x i8]* @.str, i32 0, i32 0
%ret = call i8* @strstr(i8* %str, i8* %pat)
ret i8* %ret
; CHECK-NEXT: ret i8* %str
}

; Check strstr(str, "a") -> strchr(str, 'a').

define i8* @test_simplify2(i8* %str) {
; CHECK-LABEL: @test_simplify2(
; CHECK-NEXT: [[STRCHR:%.*]] = call i8* @strchr(i8* nonnull dereferenceable(1) [[STR:%.*]], i32 97)
; CHECK-NEXT: ret i8* [[STRCHR]]
;
%pat = getelementptr inbounds [2 x i8], [2 x i8]* @.str1, i32 0, i32 0
%ret = call i8* @strstr(i8* %str, i8* %pat)
ret i8* %ret
; CHECK-NEXT: @strchr(i8* %str, i32 97)
}

; Check strstr("abcde", "bcd") -> "abcde" + 1.

define i8* @test_simplify3() {
; CHECK-LABEL: @test_simplify3(
; CHECK-NEXT: ret i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str2, i64 0, i64 1)
;
%str = getelementptr inbounds [6 x i8], [6 x i8]* @.str2, i32 0, i32 0
%pat = getelementptr inbounds [4 x i8], [4 x i8]* @.str3, i32 0, i32 0
%ret = call i8* @strstr(i8* %str, i8* %pat)
ret i8* %ret
; CHECK-NEXT: getelementptr inbounds ([6 x i8], [6 x i8]* @.str2, i64 0, i64 1)
}

; Check strstr(str, str) -> str.

define i8* @test_simplify4(i8* %str) {
; CHECK-LABEL: @test_simplify4(
; CHECK-NEXT: ret i8* [[STR:%.*]]
;
%ret = call i8* @strstr(i8* %str, i8* %str)
ret i8* %ret
; CHECK-NEXT: ret i8* %str
}

; Check strstr(str, pat) == str -> strncmp(str, pat, strlen(str)) == 0.

define i1 @test_simplify5(i8* %str, i8* %pat) {
; CHECK-LABEL: @test_simplify5(
; CHECK-NEXT: [[STRLEN:%.*]] = call i64 @strlen(i8* nonnull dereferenceable(1) [[PAT:%.*]])
; CHECK-NEXT: [[STRNCMP:%.*]] = call i32 @strncmp(i8* [[STR:%.*]], i8* [[PAT]], i64 [[STRLEN]])
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[STRNCMP]], 0
; CHECK-NEXT: ret i1 [[CMP1]]
;
%ret = call i8* @strstr(i8* %str, i8* %pat)
%cmp = icmp eq i8* %ret, %str
ret i1 %cmp
; CHECK: [[LEN:%[a-z]+]] = call {{i[0-9]+}} @strlen(i8* %pat)
; CHECK: [[NCMP:%[a-z]+]] = call {{i[0-9]+}} @strncmp(i8* %str, i8* %pat, {{i[0-9]+}} [[LEN]])
; CHECK: icmp eq {{i[0-9]+}} [[NCMP]], 0
; CHECK: ret i1
}

define i8* @test1(i8* %str1, i8* %str2) {
; CHECK-LABEL: @test1(
; CHECK-NEXT: [[RET:%.*]] = call i8* @strstr(i8* nonnull dereferenceable(1) [[STR1:%.*]], i8* nonnull dereferenceable(1) [[STR2:%.*]])
; CHECK-NEXT: ret i8* [[RET]]
;
%ret = call i8* @strstr(i8* %str1, i8* %str2)
ret i8* %ret
}

define i8* @test2(i8* %str1, i8* %str2) "null-pointer-is-valid"="true" {
; CHECK-LABEL: @test2(
; CHECK-NEXT: [[RET:%.*]] = call i8* @strstr(i8* [[STR1:%.*]], i8* [[STR2:%.*]])
; CHECK-NEXT: ret i8* [[RET]]
;
%ret = call i8* @strstr(i8* %str1, i8* %str2)
ret i8* %ret
}