88 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; Test that the strrchr library call simplifier works correctly.3; RUN: opt < %s -passes=instcombine -S | FileCheck %s4 5target 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"6 7@hello = constant [14 x i8] c"hello world\5Cn\00"8@null = constant [1 x i8] zeroinitializer9@chp = global ptr zeroinitializer10 11declare ptr @strrchr(ptr, i32)12 13define void @test_simplify1() {14; CHECK-LABEL: @test_simplify1(15; CHECK-NEXT: store ptr getelementptr inbounds nuw (i8, ptr @hello, i32 6), ptr @chp, align 416; CHECK-NEXT: ret void17;18 19 %dst = call ptr @strrchr(ptr @hello, i32 119)20 store ptr %dst, ptr @chp21 ret void22}23 24define void @test_simplify2() {25; CHECK-LABEL: @test_simplify2(26; CHECK-NEXT: store ptr null, ptr @chp, align 427; CHECK-NEXT: ret void28;29 30 %dst = call ptr @strrchr(ptr @null, i32 119)31 store ptr %dst, ptr @chp32 ret void33}34 35define void @test_simplify3() {36; CHECK-LABEL: @test_simplify3(37; CHECK-NEXT: store ptr getelementptr inbounds nuw (i8, ptr @hello, i32 13), ptr @chp, align 438; CHECK-NEXT: ret void39;40 41 %dst = call ptr @strrchr(ptr @hello, i32 0)42 store ptr %dst, ptr @chp43 ret void44}45 46define void @test_simplify4() {47; CHECK-LABEL: @test_simplify4(48; CHECK-NEXT: store ptr getelementptr inbounds nuw (i8, ptr @hello, i32 13), ptr @chp, align 449; CHECK-NEXT: ret void50;51 52 %dst = call ptr @strrchr(ptr @hello, i32 65280)53 store ptr %dst, ptr @chp54 ret void55}56 57define void @test_xform_to_memrchr(i32 %chr) {58; CHECK-LABEL: @test_xform_to_memrchr(59; CHECK-NEXT: [[MEMRCHR:%.*]] = call ptr @memrchr(ptr noundef nonnull dereferenceable(14) @hello, i32 [[CHR:%.*]], i32 14)60; CHECK-NEXT: store ptr [[MEMRCHR]], ptr @chp, align 461; CHECK-NEXT: ret void62;63 64 %dst = call ptr @strrchr(ptr @hello, i32 %chr)65 store ptr %dst, ptr @chp66 ret void67}68 69define ptr @test1(ptr %str, i32 %c) {70; CHECK-LABEL: @test1(71; CHECK-NEXT: [[RET:%.*]] = call ptr @strrchr(ptr noundef nonnull dereferenceable(1) [[STR:%.*]], i32 [[C:%.*]])72; CHECK-NEXT: ret ptr [[RET]]73;74 75 %ret = call ptr @strrchr(ptr %str, i32 %c)76 ret ptr %ret77}78 79define ptr @test2(ptr %str, i32 %c) null_pointer_is_valid {80; CHECK-LABEL: @test2(81; CHECK-NEXT: [[RET:%.*]] = call ptr @strrchr(ptr noundef [[STR:%.*]], i32 [[C:%.*]])82; CHECK-NEXT: ret ptr [[RET]]83;84 85 %ret = call ptr @strrchr(ptr %str, i32 %c)86 ret ptr %ret87}88