Home | History | Annotate | Download | only in InstCombine
      1 ; Test that the strrchr library call simplifier works correctly.
      2 ; RUN: opt < %s -instcombine -S | FileCheck %s
      3 
      4 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"
      5 
      6 @hello = constant [14 x i8] c"hello world\5Cn\00"
      7 @null = constant [1 x i8] zeroinitializer
      8 @chp = global i8* zeroinitializer
      9 
     10 declare i8* @strrchr(i8*, i32)
     11 
     12 define void @test_simplify1() {
     13 ; CHECK: store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @hello, i32 0, i32 6)
     14 ; CHECK-NOT: call i8* @strrchr
     15 ; CHECK: ret void
     16 
     17   %str = getelementptr [14 x i8], [14 x i8]* @hello, i32 0, i32 0
     18   %dst = call i8* @strrchr(i8* %str, i32 119)
     19   store i8* %dst, i8** @chp
     20   ret void
     21 }
     22 
     23 define void @test_simplify2() {
     24 ; CHECK: store i8* null, i8** @chp, align 4
     25 ; CHECK-NOT: call i8* @strrchr
     26 ; CHECK: ret void
     27 
     28   %str = getelementptr [1 x i8], [1 x i8]* @null, i32 0, i32 0
     29   %dst = call i8* @strrchr(i8* %str, i32 119)
     30   store i8* %dst, i8** @chp
     31   ret void
     32 }
     33 
     34 define void @test_simplify3() {
     35 ; CHECK: store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @hello, i32 0, i32 13)
     36 ; CHECK-NOT: call i8* @strrchr
     37 ; CHECK: ret void
     38 
     39   %src = getelementptr [14 x i8], [14 x i8]* @hello, i32 0, i32 0
     40   %dst = call i8* @strrchr(i8* %src, i32 0)
     41   store i8* %dst, i8** @chp
     42   ret void
     43 }
     44 
     45 define void @test_simplify4() {
     46 ; CHECK: store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @hello, i32 0, i32 13)
     47 ; CHECK-NOT: call i8* @strrchr
     48 ; CHECK: ret void
     49 
     50   %src = getelementptr [14 x i8], [14 x i8]* @hello, i32 0, i32 0
     51   %dst = call i8* @strrchr(i8* %src, i32 65280)
     52   store i8* %dst, i8** @chp
     53   ret void
     54 }
     55 
     56 define void @test_nosimplify1(i32 %chr) {
     57 ; CHECK-LABEL: @test_nosimplify1(
     58 ; CHECK: call i8* @strrchr
     59 ; CHECK: ret void
     60 
     61   %src = getelementptr [14 x i8], [14 x i8]* @hello, i32 0, i32 0
     62   %dst = call i8* @strrchr(i8* %src, i32 %chr)
     63   store i8* %dst, i8** @chp
     64   ret void
     65 }
     66