File: StrLen.ll

package info (click to toggle)
llvm 2.6-9.1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 57,604 kB
  • ctags: 44,336
  • sloc: cpp: 344,766; sh: 12,407; ansic: 10,617; ada: 3,070; ml: 2,505; perl: 2,496; makefile: 1,426; pascal: 1,163; exp: 389; asm: 307; python: 298; objc: 260; lisp: 182; csh: 117; xml: 38; f90: 36; tcl: 20
file content (56 lines) | stat: -rw-r--r-- 1,907 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
; Test that the StrCatOptimizer works correctly
; RUN: llvm-as < %s | opt -simplify-libcalls | llvm-dis | \
; RUN:    not grep {call.*strlen}

target datalayout = "e-p:32:32"
@hello = constant [6 x i8] c"hello\00"		; <[6 x i8]*> [#uses=3]
@null = constant [1 x i8] zeroinitializer		; <[1 x i8]*> [#uses=3]
@null_hello = constant [7 x i8] c"\00hello\00"		; <[7 x i8]*> [#uses=1]

declare i32 @strlen(i8*)

define i32 @test1() {
	%hello_p = getelementptr [6 x i8]* @hello, i32 0, i32 0		; <i8*> [#uses=1]
	%hello_l = call i32 @strlen( i8* %hello_p )		; <i32> [#uses=1]
	ret i32 %hello_l
}

define i32 @test2() {
	%null_p = getelementptr [1 x i8]* @null, i32 0, i32 0		; <i8*> [#uses=1]
	%null_l = call i32 @strlen( i8* %null_p )		; <i32> [#uses=1]
	ret i32 %null_l
}

define i32 @test3() {
	%null_hello_p = getelementptr [7 x i8]* @null_hello, i32 0, i32 0		; <i8*> [#uses=1]
	%null_hello_l = call i32 @strlen( i8* %null_hello_p )		; <i32> [#uses=1]
	ret i32 %null_hello_l
}

define i1 @test4() {
	%hello_p = getelementptr [6 x i8]* @hello, i32 0, i32 0		; <i8*> [#uses=1]
	%hello_l = call i32 @strlen( i8* %hello_p )		; <i32> [#uses=1]
	%eq_hello = icmp eq i32 %hello_l, 0		; <i1> [#uses=1]
	ret i1 %eq_hello
}

define i1 @test5() {
	%null_p = getelementptr [1 x i8]* @null, i32 0, i32 0		; <i8*> [#uses=1]
	%null_l = call i32 @strlen( i8* %null_p )		; <i32> [#uses=1]
	%eq_null = icmp eq i32 %null_l, 0		; <i1> [#uses=1]
	ret i1 %eq_null
}

define i1 @test6() {
	%hello_p = getelementptr [6 x i8]* @hello, i32 0, i32 0		; <i8*> [#uses=1]
	%hello_l = call i32 @strlen( i8* %hello_p )		; <i32> [#uses=1]
	%ne_hello = icmp ne i32 %hello_l, 0		; <i1> [#uses=1]
	ret i1 %ne_hello
}

define i1 @test7() {
	%null_p = getelementptr [1 x i8]* @null, i32 0, i32 0		; <i8*> [#uses=1]
	%null_l = call i32 @strlen( i8* %null_p )		; <i32> [#uses=1]
	%ne_null = icmp ne i32 %null_l, 0		; <i1> [#uses=1]
	ret i1 %ne_null
}