James Molloy | 7c7255e | 2016-09-08 12:58:04 +0000 | [diff] [blame] | 1 | ; RUN: llc %s -o - -O1 -debug-only=consthoist 2>&1 | FileCheck %s |
| 2 | ; REQUIRES: asserts |
| 3 | |
| 4 | target datalayout = "e-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32" |
| 5 | target triple = "thumbv6m-apple-ios8.0.0" |
| 6 | |
| 7 | declare void @g(i32) |
| 8 | |
| 9 | ; CHECK: Collect constant i32 -3 from call void @g(i32 -3) with cost 2 |
| 10 | define void @f(i1 %cond) { |
| 11 | entry: |
| 12 | call void @g(i32 -3) |
| 13 | br i1 %cond, label %true, label %ret |
| 14 | |
| 15 | true: |
| 16 | call void @g(i32 -3) |
| 17 | br label %ret |
| 18 | |
| 19 | ret: |
| 20 | ret void |
| 21 | } |
James Molloy | 753c18f | 2016-09-08 12:58:12 +0000 | [diff] [blame] | 22 | |
| 23 | ; CHECK: Function: h |
| 24 | ; CHECK-NOT: Collect constant i32 -193 from |
| 25 | define void @h(i1 %cond, i32 %p, i32 %q) { |
| 26 | entry: |
| 27 | %a = and i32 %p, 4294967103 |
| 28 | call void @g(i32 %a) |
| 29 | br i1 %cond, label %true, label %ret |
| 30 | |
| 31 | true: |
| 32 | %b = and i32 %q, 4294967103 |
| 33 | call void @g(i32 %b) |
| 34 | br label %ret |
| 35 | |
| 36 | ret: |
| 37 | ret void |
| 38 | } |
| 39 | |
James Molloy | 1454e90 | 2016-09-09 13:35:28 +0000 | [diff] [blame] | 40 | ; CHECK: Function: test_icmp_neg |
| 41 | ; CHECK-NOT: Collect constant |
| 42 | define void @test_icmp_neg(i1 %cond, i32 %arg, i32 %arg2) { |
| 43 | entry: |
| 44 | %a = icmp ne i32 %arg, -5 |
| 45 | call void @g2(i1 %a) |
| 46 | br i1 %cond, label %true, label %ret |
| 47 | |
| 48 | true: |
| 49 | %b = icmp ne i32 %arg2, -5 |
| 50 | call void @g2(i1 %b) |
| 51 | br label %ret |
| 52 | |
| 53 | ret: |
| 54 | ret void |
| 55 | } |
| 56 | declare void @g2(i1) |
| 57 | |
| 58 | ; CHECK: Function: test_icmp_neg2 |
| 59 | ; CHECK: Hoist constant (i32 -500) to BB entry |
| 60 | define void @test_icmp_neg2(i1 %cond, i32 %arg, i32 %arg2) { |
| 61 | entry: |
| 62 | %a = icmp ne i32 %arg, -500 |
| 63 | call void @g2(i1 %a) |
| 64 | br i1 %cond, label %true, label %ret |
| 65 | |
| 66 | true: |
| 67 | %b = icmp ne i32 %arg2, -500 |
| 68 | call void @g2(i1 %b) |
| 69 | br label %ret |
| 70 | |
| 71 | ret: |
| 72 | ret void |
| 73 | } |
James Molloy | 57d9dfa | 2016-09-09 13:35:36 +0000 | [diff] [blame] | 74 | |
| 75 | ; CHECK: Function: test_add_neg |
| 76 | ; CHECK-NOT: Collect constant i32 -5 |
| 77 | define void @test_add_neg(i1 %cond, i32 %arg, i32 %arg2) { |
| 78 | entry: |
| 79 | %a = add i32 %arg, -5 |
| 80 | call void @g(i32 %a) |
| 81 | br i1 %cond, label %true, label %ret |
| 82 | |
| 83 | true: |
| 84 | %b = add i32 %arg2, -5 |
| 85 | call void @g(i32 %b) |
| 86 | br label %ret |
| 87 | |
| 88 | ret: |
| 89 | ret void |
| 90 | } |