Michael Kuperstein | 243c073 | 2015-08-11 14:10:58 +0000 | [diff] [blame^] | 1 | ; RUN: llc -o - -mtriple=i386-unknown-linux-gnu < %s | FileCheck %s |
| 2 | ; RUN: llc -o - -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s |
| 3 | |
| 4 | @a = common global i32 0, align 4 |
| 5 | @b = common global i32 0, align 4 |
| 6 | @c = common global i32 0, align 4 |
| 7 | @e = common global i32 0, align 4 |
| 8 | @x = common global i32 0, align 4 |
| 9 | @f = common global i32 0, align 4 |
| 10 | @h = common global i32 0, align 4 |
| 11 | @i = common global i32 0, align 4 |
| 12 | |
| 13 | ; Test -Os to make sure immediates with multiple users don't get pulled in to |
| 14 | ; instructions. |
| 15 | define i32 @foo() optsize { |
| 16 | ; CHECK-LABEL: foo: |
| 17 | ; CHECK: movl $1234, [[R1:%[a-z]+]] |
| 18 | ; CHECK-NOT: movl $1234, a |
| 19 | ; CHECK-NOT: movl $1234, b |
| 20 | ; CHECK-NOT: movl $12, c |
| 21 | ; CHECK-NOT: cmpl $12, e |
| 22 | ; CHECK: movl [[R1]], a |
| 23 | ; CHECK: movl [[R1]], b |
| 24 | |
| 25 | entry: |
| 26 | store i32 1234, i32* @a |
| 27 | store i32 1234, i32* @b |
| 28 | store i32 12, i32* @c |
| 29 | %0 = load i32, i32* @e |
| 30 | %cmp = icmp eq i32 %0, 12 |
| 31 | br i1 %cmp, label %if.then, label %if.end |
| 32 | |
| 33 | if.then: ; preds = %entry |
| 34 | store i32 1, i32* @x |
| 35 | br label %if.end |
| 36 | |
| 37 | ; New block.. Make sure 1234 isn't live across basic blocks from before. |
| 38 | ; CHECK: movl $1234, f |
| 39 | ; CHECK: movl $555, [[R3:%[a-z]+]] |
| 40 | ; CHECK-NOT: movl $555, h |
| 41 | ; CHECK-NOT: addl $555, i |
| 42 | ; CHECK: movl [[R3]], h |
| 43 | ; CHECK: addl [[R3]], i |
| 44 | |
| 45 | if.end: ; preds = %if.then, %entry |
| 46 | store i32 1234, i32* @f |
| 47 | store i32 555, i32* @h |
| 48 | %1 = load i32, i32* @i |
| 49 | %add1 = add nsw i32 %1, 555 |
| 50 | store i32 %add1, i32* @i |
| 51 | ret i32 0 |
| 52 | } |
| 53 | |
| 54 | ; Test -O2 to make sure that all immediates get pulled in to their users. |
| 55 | define i32 @foo2() { |
| 56 | ; CHECK-LABEL: foo2: |
| 57 | ; CHECK: movl $1234, a |
| 58 | ; CHECK: movl $1234, b |
| 59 | |
| 60 | entry: |
| 61 | store i32 1234, i32* @a |
| 62 | store i32 1234, i32* @b |
| 63 | |
| 64 | ret i32 0 |
| 65 | } |
| 66 | |
| 67 | declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) #1 |
| 68 | |
| 69 | @AA = common global [100 x i8] zeroinitializer, align 1 |
| 70 | |
| 71 | ; memset gets lowered in DAG. Constant merging should hoist all the |
| 72 | ; immediates used to store to the individual memory locations. Make |
| 73 | ; sure we don't directly store the immediates. |
| 74 | define void @foomemset() optsize { |
| 75 | ; CHECK-LABEL: foomemset: |
| 76 | ; CHECK-NOT: movl ${{.*}}, AA |
| 77 | ; CHECK: mov{{l|q}} %{{e|r}}ax, AA |
| 78 | |
| 79 | entry: |
| 80 | call void @llvm.memset.p0i8.i32(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @AA, i32 0, i32 0), i8 33, i32 24, i32 1, i1 false) |
| 81 | ret void |
| 82 | } |