OLD | NEW |
(Empty) | |
| 1 ; RUN: opt < %s -simplify-allocas -S | FileCheck %s |
| 2 |
| 3 target datalayout = "p:32:32:32" |
| 4 |
| 5 %struct = type { i32, i32 } |
| 6 |
| 7 declare void @receive_alloca(%struct* %ptr) |
| 8 declare void @receive_vector_alloca(<4 x i32>* %ptr) |
| 9 |
| 10 define void @alloca_fixed() { |
| 11 %buf = alloca %struct, align 128 |
| 12 call void @receive_alloca(%struct* %buf) |
| 13 ret void |
| 14 } |
| 15 ; CHECK-LABEL: define void @alloca_fixed() { |
| 16 ; CHECK-NEXT: %buf = alloca i8, i32 8, align 128 |
| 17 ; CHECK-NEXT: %buf.bc = bitcast i8* %buf to %struct* |
| 18 ; CHECK-NEXT: call void @receive_alloca(%struct* %buf.bc) |
| 19 |
| 20 ; When the size passed to alloca is a constant, it should be a |
| 21 ; constant in the output too. |
| 22 define void @alloca_fixed_array() { |
| 23 %buf = alloca %struct, i32 100 |
| 24 call void @receive_alloca(%struct* %buf) |
| 25 ret void |
| 26 } |
| 27 ; CHECK-LABEL: define void @alloca_fixed_array() { |
| 28 ; CHECK-NEXT: %buf = alloca i8, i32 800, align 8 |
| 29 ; CHECK-NEXT: %buf.bc = bitcast i8* %buf to %struct* |
| 30 ; CHECK-NEXT: call void @receive_alloca(%struct* %buf.bc) |
| 31 |
| 32 define void @alloca_fixed_vector() { |
| 33 %buf = alloca <4 x i32>, align 128 |
| 34 call void @receive_vector_alloca(<4 x i32>* %buf) |
| 35 ret void |
| 36 } |
| 37 ; CHECK-LABEL: define void @alloca_fixed_vector() { |
| 38 ; CHECK-NEXT: %buf = alloca i8, i32 16, align 128 |
| 39 ; CHECK-NEXT: %buf.bc = bitcast i8* %buf to <4 x i32>* |
| 40 ; CHECK-NEXT: call void @receive_vector_alloca(<4 x i32>* %buf.bc) |
| 41 |
| 42 define void @alloca_variable(i32 %size) { |
| 43 %buf = alloca %struct, i32 %size |
| 44 call void @receive_alloca(%struct* %buf) |
| 45 ret void |
| 46 } |
| 47 ; CHECK-LABEL: define void @alloca_variable(i32 %size) { |
| 48 ; CHECK-NEXT: %buf.alloca_mul = mul i32 8, %size |
| 49 ; CHECK-NEXT: %buf = alloca i8, i32 %buf.alloca_mul |
| 50 ; CHECK-NEXT: %buf.bc = bitcast i8* %buf to %struct* |
| 51 ; CHECK-NEXT: call void @receive_alloca(%struct* %buf.bc) |
| 52 |
| 53 define void @alloca_alignment_i32() { |
| 54 %buf = alloca i32 |
| 55 ret void |
| 56 } |
| 57 ; CHECK-LABEL: void @alloca_alignment_i32() { |
| 58 ; CHECK-NEXT: alloca i8, i32 4, align 4 |
| 59 |
| 60 define void @alloca_alignment_double() { |
| 61 %buf = alloca double |
| 62 ret void |
| 63 } |
| 64 ; CHECK-LABEL: void @alloca_alignment_double() { |
| 65 ; CHECK-NEXT: alloca i8, i32 8, align 8 |
| 66 |
| 67 define void @alloca_lower_alignment() { |
| 68 %buf = alloca i32, align 1 |
| 69 ret void |
| 70 } |
| 71 ; CHECK-LABEL: void @alloca_lower_alignment() { |
| 72 ; CHECK-NEXT: alloca i8, i32 4, align 1 |
| 73 |
| 74 define void @alloca_array_trunc() { |
| 75 %a = alloca i32, i64 1024 |
| 76 unreachable |
| 77 } |
| 78 ; CHECK-LABEL: define void @alloca_array_trunc() |
| 79 ; CHECK-NEXT: %a = alloca i8, i32 4096 |
| 80 |
| 81 define void @alloca_array_zext() { |
| 82 %a = alloca i32, i8 128 |
| 83 unreachable |
| 84 } |
| 85 ; CHECK-LABEL: define void @alloca_array_zext() |
| 86 ; CHECK-NEXT: %a = alloca i8, i32 512 |
| 87 |
| 88 define void @dyn_alloca_array_trunc(i64 %a) { |
| 89 %b = alloca i32, i64 %a |
| 90 unreachable |
| 91 } |
| 92 ; CHECK-LABEL: define void @dyn_alloca_array_trunc(i64 %a) |
| 93 ; CHECK-NEXT: trunc i64 %a to i32 |
| 94 ; CHECK-NEXT: mul i32 4, |
| 95 ; CHECK-NEXT: alloca i8, i32 |
| 96 |
| 97 define void @dyn_alloca_array_zext(i8 %a) { |
| 98 %b = alloca i32, i8 %a |
| 99 unreachable |
| 100 } |
| 101 ; CHECK-LABEL: define void @dyn_alloca_array_zext(i8 %a) |
| 102 ; CHECK-NEXT: zext i8 %a to i32 |
| 103 ; CHECK-NEXT: mul i32 4, |
| 104 ; CHECK-NEXT: alloca i8, i32 |
| 105 |
| 106 define void @dyn_inst_alloca_array(i32 %a) { |
| 107 %b = add i32 1, %a |
| 108 %c = alloca i32, i32 %b |
| 109 unreachable |
| 110 } |
| 111 ; CHECK-LABEL: define void @dyn_inst_alloca_array(i32 %a) |
| 112 ; CHECK-NEXT: %b = add i32 1, %a |
| 113 ; CHECK-NEXT: mul i32 4, %b |
| 114 ; CHECK-NEXT: %c = alloca i8, i32 |
| 115 |
| 116 define void @dyn_inst_alloca_array_trunc(i64 %a) { |
| 117 %b = add i64 1, %a |
| 118 %c = alloca i32, i64 %b |
| 119 unreachable |
| 120 } |
| 121 ; CHECK-LABEL: define void @dyn_inst_alloca_array_trunc(i64 %a) |
| 122 ; CHECK-NEXT: %b = add i64 1, %a |
| 123 ; CHECK-NEXT: trunc i64 %b to i32 |
| 124 ; CHECK-NEXT: mul i32 4, |
| 125 ; CHECK-NEXT: %c = alloca i8, i32 |
| 126 |
| 127 define void @dyn_inst_alloca_array_zext(i8 %a) { |
| 128 %b = add i8 1, %a |
| 129 %c = alloca i32, i8 %b |
| 130 unreachable |
| 131 } |
| 132 ; CHECK-LABEL: define void @dyn_inst_alloca_array_zext(i8 %a) |
| 133 ; CHECK-NEXT: %b = add i8 1, %a |
| 134 ; CHECK-NEXT: zext i8 %b to i32 |
| 135 ; CHECK-NEXT: mul i32 4, |
| 136 ; CHECK-NEXT: %c = alloca i8, i32 |
OLD | NEW |