Reid Spencer | 34efdf8 | 2005-05-03 06:22:41 +0000 | [diff] [blame] | 1 | ; Test that the StrChrOptimizer works correctly |
Reid Spencer | 43b4003 | 2007-04-16 15:31:49 +0000 | [diff] [blame] | 2 | ; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis | \ |
| 3 | ; RUN: not grep {call.*%strchr} |
Reid Spencer | 34efdf8 | 2005-05-03 06:22:41 +0000 | [diff] [blame] | 4 | |
| 5 | declare sbyte* %strchr(sbyte*,int) |
| 6 | declare int %puts(sbyte*) |
| 7 | %hello = constant [14 x sbyte] c"hello world\n\00" |
| 8 | %null = constant [1 x sbyte] c"\00" |
| 9 | |
| 10 | implementation ; Functions: |
| 11 | |
| 12 | int %main () { |
| 13 | %hello_p = getelementptr [14 x sbyte]* %hello, int 0, int 0 |
| 14 | %null_p = getelementptr [1 x sbyte]* %null, int 0, int 0 |
| 15 | |
| 16 | %world = call sbyte* %strchr(sbyte* %hello_p, int 119 ) |
| 17 | %ignore = call sbyte* %strchr(sbyte* %null_p, int 119 ) |
Reid Spencer | c88e681 | 2005-05-03 17:09:38 +0000 | [diff] [blame] | 18 | %len = call int %puts(sbyte* %world) |
| 19 | %index = add int %len, 112 |
| 20 | %result = call sbyte* %strchr(sbyte* %hello_p, int %index) |
| 21 | ret int %index |
Reid Spencer | 34efdf8 | 2005-05-03 06:22:41 +0000 | [diff] [blame] | 22 | } |