1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; Test that the strpbrk library call simplifier works correctly.
4 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
6 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
8 @hello = constant [12 x i8] c"hello world\00"
9 @w = constant [2 x i8] c"w\00"
10 @null = constant [1 x i8] zeroinitializer
12 declare ptr @strpbrk(ptr, ptr)
14 ; Check strpbrk(s, "") -> NULL.
16 define ptr @test_simplify1(ptr %str) {
17 ; CHECK-LABEL: @test_simplify1(
18 ; CHECK-NEXT: ret ptr null
21 %ret = call ptr @strpbrk(ptr %str, ptr @null)
25 ; Check strpbrk("", s) -> NULL.
27 define ptr @test_simplify2(ptr %pat) {
28 ; CHECK-LABEL: @test_simplify2(
29 ; CHECK-NEXT: ret ptr null
32 %ret = call ptr @strpbrk(ptr @null, ptr %pat)
36 ; Check strpbrk(s1, s2), where s1 and s2 are constants.
38 define ptr @test_simplify3() {
39 ; CHECK-LABEL: @test_simplify3(
40 ; CHECK-NEXT: ret ptr getelementptr inbounds (i8, ptr @hello, i32 6)
43 %ret = call ptr @strpbrk(ptr @hello, ptr @w)
47 ; Check strpbrk(s, "a") -> strchr(s, 'a').
49 define ptr @test_simplify4(ptr %str) {
50 ; CHECK-LABEL: @test_simplify4(
51 ; CHECK-NEXT: [[STRCHR:%.*]] = call ptr @strchr(ptr noundef nonnull dereferenceable(1) [[STR:%.*]], i32 119)
52 ; CHECK-NEXT: ret ptr [[STRCHR]]
55 %ret = call ptr @strpbrk(ptr %str, ptr @w)
59 ; Check cases that shouldn't be simplified.
61 define ptr @test_no_simplify1(ptr %str, ptr %pat) {
62 ; CHECK-LABEL: @test_no_simplify1(
63 ; CHECK-NEXT: [[RET:%.*]] = call ptr @strpbrk(ptr [[STR:%.*]], ptr [[PAT:%.*]])
64 ; CHECK-NEXT: ret ptr [[RET]]
67 %ret = call ptr @strpbrk(ptr %str, ptr %pat)