File: StrChr.ll

package info (click to toggle)
llvm-2.7 2.7-6
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 59,992 kB
  • ctags: 49,499
  • sloc: cpp: 373,792; ansic: 16,885; sh: 12,614; asm: 6,809; ada: 3,083; ml: 2,942; python: 2,671; perl: 2,404; makefile: 1,691; pascal: 1,235; exp: 399; objc: 291; lisp: 184; csh: 117; xml: 38; f90: 36
file content (26 lines) | stat: -rw-r--r-- 973 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
; Test that the StrChrOptimizer works correctly
; RUN: opt < %s -simplify-libcalls -S | \
; RUN:   not grep {call.*@strchr}

; This transformation requires the pointer size, as it assumes that size_t is
; the size of a pointer.
target datalayout = "-p:64:64:64"

@hello = constant [14 x i8] c"hello world\5Cn\00"		; <[14 x i8]*> [#uses=1]
@null = constant [1 x i8] zeroinitializer		; <[1 x i8]*> [#uses=1]

declare i8* @strchr(i8*, i32)

declare i32 @puts(i8*)

define i32 @main() {
	%hello_p = getelementptr [14 x i8]* @hello, i32 0, i32 0		; <i8*> [#uses=2]
	%null_p = getelementptr [1 x i8]* @null, i32 0, i32 0		; <i8*> [#uses=1]
	%world = call i8* @strchr( i8* %hello_p, i32 119 )		; <i8*> [#uses=1]
	%ignore = call i8* @strchr( i8* %null_p, i32 119 )		; <i8*> [#uses=0]
	%len = call i32 @puts( i8* %world )		; <i32> [#uses=1]
	%index = add i32 %len, 112		; <i32> [#uses=2]
	%result = call i8* @strchr( i8* %hello_p, i32 %index )		; <i8*> [#uses=0]
	ret i32 %index
}