Chris Lattner | 090ca91 | 2011-04-18 06:55:51 +0000 | [diff] [blame] | 1 | ; RUN: llc < %s -fast-isel -O0 -regalloc=fast -asm-verbose=0 -fast-isel-abort | FileCheck %s |
Chris Lattner | fff65b3 | 2011-04-17 01:16:47 +0000 | [diff] [blame] | 2 | |
| 3 | target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" |
| 4 | target triple = "x86_64-apple-darwin10.0.0" |
| 5 | |
| 6 | ; Make sure that fast-isel folds the immediate into the binop even though it |
| 7 | ; is non-canonical. |
| 8 | define i32 @test1(i32 %i) nounwind ssp { |
| 9 | %and = and i32 8, %i |
| 10 | ret i32 %and |
| 11 | } |
| 12 | |
| 13 | ; CHECK: test1: |
| 14 | ; CHECK: andl $8, |
Chris Lattner | fd3f635 | 2011-04-17 06:35:44 +0000 | [diff] [blame] | 15 | |
| 16 | |
Chris Lattner | 685090f | 2011-04-17 17:12:08 +0000 | [diff] [blame] | 17 | @G = external global i32 |
| 18 | define i64 @test3() nounwind { |
| 19 | %A = ptrtoint i32* @G to i64 |
| 20 | ret i64 %A |
Chris Lattner | 685090f | 2011-04-17 17:12:08 +0000 | [diff] [blame] | 21 | ; CHECK: test3: |
| 22 | ; CHECK: movq _G@GOTPCREL(%rip), %rax |
| 23 | ; CHECK-NEXT: ret |
Chris Lattner | 0a1c997 | 2011-04-17 17:47:38 +0000 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | |
| 27 | |
| 28 | ; rdar://9289558 |
| 29 | @rtx_length = external global [153 x i8] |
| 30 | |
| 31 | define i32 @test4(i64 %idxprom9) nounwind { |
| 32 | %arrayidx10 = getelementptr inbounds [153 x i8]* @rtx_length, i32 0, i64 %idxprom9 |
| 33 | %tmp11 = load i8* %arrayidx10, align 1 |
| 34 | %conv = zext i8 %tmp11 to i32 |
| 35 | ret i32 %conv |
| 36 | |
| 37 | ; CHECK: test4: |
| 38 | ; CHECK: movq _rtx_length@GOTPCREL(%rip), %rax |
| 39 | ; CHECK-NEXT: movzbl (%rax,%rdi), %eax |
| 40 | ; CHECK-NEXT: ret |
| 41 | } |
Chris Lattner | 602fc06 | 2011-04-17 20:23:29 +0000 | [diff] [blame] | 42 | |
| 43 | |
| 44 | ; PR3242 - Out of range shifts should not be folded by fastisel. |
| 45 | define void @test5(i32 %x, i32* %p) nounwind { |
| 46 | %y = ashr i32 %x, 50000 |
| 47 | store i32 %y, i32* %p |
| 48 | ret void |
| 49 | |
| 50 | ; CHECK: test5: |
| 51 | ; CHECK: movl $50000, %ecx |
| 52 | ; CHECK: sarl %cl, %edi |
| 53 | ; CHECK: ret |
| 54 | } |
| 55 | |
| 56 | ; rdar://9289501 - fast isel should fold trivial multiplies to shifts. |
| 57 | define i64 @test6(i64 %x) nounwind ssp { |
| 58 | entry: |
| 59 | %mul = mul nsw i64 %x, 8 |
| 60 | ret i64 %mul |
| 61 | |
| 62 | ; CHECK: test6: |
| 63 | ; CHECK: leaq (,%rdi,8), %rax |
| 64 | } |
| 65 | |
| 66 | define i32 @test7(i32 %x) nounwind ssp { |
| 67 | entry: |
| 68 | %mul = mul nsw i32 %x, 8 |
| 69 | ret i32 %mul |
| 70 | ; CHECK: test7: |
| 71 | ; CHECK: leal (,%rdi,8), %eax |
| 72 | } |
| 73 | |
Chris Lattner | 1518afd | 2011-04-18 06:22:33 +0000 | [diff] [blame] | 74 | |
| 75 | ; rdar://9289507 - folding of immediates into 64-bit operations. |
| 76 | define i64 @test8(i64 %x) nounwind ssp { |
| 77 | entry: |
| 78 | %add = add nsw i64 %x, 7 |
| 79 | ret i64 %add |
| 80 | |
| 81 | ; CHECK: test8: |
| 82 | ; CHECK: addq $7, %rdi |
| 83 | } |
| 84 | |
| 85 | define i64 @test9(i64 %x) nounwind ssp { |
| 86 | entry: |
| 87 | %add = mul nsw i64 %x, 7 |
| 88 | ret i64 %add |
| 89 | ; CHECK: test9: |
| 90 | ; CHECK: imulq $7, %rdi, %rax |
| 91 | } |
Chris Lattner | 090ca91 | 2011-04-18 06:55:51 +0000 | [diff] [blame] | 92 | |
| 93 | ; rdar://9297011 - Don't reject udiv by a power of 2. |
| 94 | define i32 @test10(i32 %X) nounwind { |
| 95 | %Y = udiv i32 %X, 8 |
| 96 | ret i32 %Y |
| 97 | ; CHECK: test10: |
| 98 | ; CHECK: shrl $3, |
| 99 | } |
Chris Lattner | f051c1a | 2011-04-18 07:00:40 +0000 | [diff] [blame] | 100 | |
| 101 | define i32 @test11(i32 %X) nounwind { |
| 102 | %Y = sdiv exact i32 %X, 8 |
| 103 | ret i32 %Y |
| 104 | ; CHECK: test11: |
| 105 | ; CHECK: sarl $3, |
| 106 | } |
| 107 | |
Chris Lattner | 90cb88a | 2011-04-19 04:22:17 +0000 | [diff] [blame] | 108 | |
| 109 | ; rdar://9297006 - Trunc to bool. |
| 110 | define void @test12(i8 %tmp) nounwind ssp noredzone { |
| 111 | entry: |
| 112 | %tobool = trunc i8 %tmp to i1 |
| 113 | br i1 %tobool, label %if.then, label %if.end |
| 114 | |
| 115 | if.then: ; preds = %entry |
| 116 | call void @test12(i8 0) noredzone |
| 117 | br label %if.end |
| 118 | |
| 119 | if.end: ; preds = %if.then, %entry |
| 120 | ret void |
| 121 | ; CHECK: test12: |
| 122 | ; CHECK: testb $1, |
Chris Lattner | c76d121 | 2011-04-19 04:26:32 +0000 | [diff] [blame] | 123 | ; CHECK-NEXT: je L |
Chris Lattner | e03b8d3 | 2011-04-19 04:42:38 +0000 | [diff] [blame] | 124 | ; CHECK-NEXT: movl $0, %edi |
| 125 | ; CHECK-NEXT: callq |
| 126 | } |
| 127 | |
| 128 | declare void @test13f(i1 %X) |
| 129 | |
| 130 | define void @test13() nounwind { |
| 131 | call void @test13f(i1 0) |
| 132 | ret void |
| 133 | ; CHECK: test13: |
| 134 | ; CHECK: movl $0, %edi |
| 135 | ; CHECK-NEXT: callq |
Chris Lattner | 90cb88a | 2011-04-19 04:22:17 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Chris Lattner | b44101c | 2011-04-19 05:09:50 +0000 | [diff] [blame] | 138 | |
| 139 | |
| 140 | ; rdar://9297003 - fast isel bails out on all functions taking bools |
| 141 | define void @test14(i8 %tmp) nounwind ssp noredzone { |
| 142 | entry: |
| 143 | %tobool = trunc i8 %tmp to i1 |
| 144 | call void @test13f(i1 zeroext %tobool) noredzone |
| 145 | ret void |
| 146 | ; CHECK: test14: |
| 147 | ; CHECK: andb $1, |
| 148 | ; CHECK: callq |
| 149 | } |
| 150 | |
Chris Lattner | 832e494 | 2011-04-19 05:52:03 +0000 | [diff] [blame] | 151 | declare void @llvm.memcpy.p0i8.p0i8.i64(i8*, i8*, i64, i32, i1) |
| 152 | |
| 153 | ; rdar://9289488 - fast-isel shouldn't bail out on llvm.memcpy |
| 154 | define void @test15(i8* %a, i8* %b) nounwind { |
| 155 | call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* %b, i64 4, i32 4, i1 false) |
| 156 | ret void |
| 157 | ; CHECK: test15: |
| 158 | ; CHECK-NEXT: movl (%rsi), %eax |
| 159 | ; CHECK-NEXT: movl %eax, (%rdi) |
| 160 | ; CHECK-NEXT: ret |
| 161 | } |
Eli Friedman | 3762046 | 2011-04-19 17:22:22 +0000 | [diff] [blame] | 162 | |
| 163 | ; Handling for varargs calls |
| 164 | declare void @test16callee(...) nounwind |
| 165 | define void @test16() nounwind { |
| 166 | ; CHECK: test16: |
| 167 | ; CHECK: movl $1, %edi |
| 168 | ; CHECK: movb $0, %al |
| 169 | ; CHECK: callq _test16callee |
| 170 | call void (...)* @test16callee(i32 1) |
| 171 | br label %block2 |
| 172 | |
| 173 | block2: |
| 174 | ; CHECK: movabsq $1 |
| 175 | ; CHECK: cvtsi2sdq {{.*}} %xmm0 |
| 176 | ; CHECK: movb $1, %al |
| 177 | ; CHECK: callq _test16callee |
| 178 | call void (...)* @test16callee(double 1.000000e+00) |
| 179 | ret void |
| 180 | } |