OLD | NEW |
(Empty) | |
| 1 ; RUN: opt -globalize-constant-vectors %s -S | FileCheck %s |
| 2 ; RUN: opt -globalize-constant-vectors %s -S | FileCheck -check-prefix=C4xi1 %s |
| 3 ; RUN: opt -globalize-constant-vectors %s -S | FileCheck -check-prefix=C8xi1 %s |
| 4 ; RUN: opt -globalize-constant-vectors %s -S | FileCheck -check-prefix=C16xi1 %s |
| 5 ; RUN: opt -globalize-constant-vectors %s -S | FileCheck -check-prefix=C16xi8 %s |
| 6 ; RUN: opt -globalize-constant-vectors %s -S | FileCheck -check-prefix=C8xi16 %s |
| 7 ; RUN: opt -globalize-constant-vectors %s -S | FileCheck -check-prefix=C4xi32 %s |
| 8 ; RUN: opt -globalize-constant-vectors %s -S | FileCheck -check-prefix=C4xfloat
%s |
| 9 ; RUN: opt -globalize-constant-vectors %s -S | FileCheck -check-prefix=Cbranch %
s |
| 10 ; RUN: opt -globalize-constant-vectors %s -S | FileCheck -check-prefix=Cduplicat
e %s |
| 11 ; RUN: opt -globalize-constant-vectors %s -S | FileCheck -check-prefix=Czeroinit
ializer %s |
| 12 ; RUN: opt -expand-constant-expr -globalize-constant-vectors %s -S | FileCheck -
check-prefix=Cnestedconst %s |
| 13 |
| 14 ; Run the test once per function so that each check can look at its |
| 15 ; globals as well as its function. |
| 16 |
| 17 ; The datalayout is needed to determine the alignment of the globals. |
| 18 target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64
:64:64-p:32:32:32-v128:32:32" |
| 19 |
| 20 ; Globals shouldn't get globalized. |
| 21 ; CHECK: @global_should_stay_untouched = internal constant <4 x i32> <i32 1337,
i32 0, i32 0, i32 0> |
| 22 @global_should_stay_untouched = internal constant <4 x i32> <i32 1337, i32 0, i3
2 0, i32 0> |
| 23 |
| 24 ; Also test a global initializer with nested const-exprs. |
| 25 ; NOTE: Have the global share the same const-expr as an instruction below. |
| 26 ; CHECK: @global_with_nesting = internal global <{ <4 x i32>, <8 x i16> }> <{ <4
x i32> <i32 1, i32 4, i32 10, i32 20>, <8 x i16> <i16 0, i16 1, i16 1, i16 2, i
16 3, i16 5, i16 8, i16 13> }> |
| 27 @global_with_nesting = internal global <{ <4 x i32>, <8 x i16> }> <{ <4 x i32> <
i32 1, i32 4, i32 10, i32 20>, <8 x i16> <i16 0, i16 1, i16 1, i16 2, i16 3, i16
5, i16 8, i16 13> }> |
| 28 |
| 29 ; 4xi1 vectors should get globalized. |
| 30 define void @test4xi1(<4 x i1> %in) { |
| 31 %ft0 = and <4 x i1> %in, <i1 false, i1 true, i1 false, i1 true> |
| 32 %ft1 = and <4 x i1> <i1 true, i1 false, i1 true, i1 false>, %in |
| 33 ret void |
| 34 } |
| 35 ; C4xi1: @[[C1:[_a-z0-9]+]] = internal unnamed_addr constant <4 x i1> <i1 false,
i1 true, i1 false, i1 true>, align 4 |
| 36 ; C4xi1: @[[C2:[_a-z0-9]+]] = internal unnamed_addr constant <4 x i1> <i1 true,
i1 false, i1 true, i1 false>, align 4 |
| 37 ; C4xi1: define void @test4xi1(<4 x i1> %in) { |
| 38 ; C4xi1-NEXT: %[[M1:[_a-z0-9]+]] = load <4 x i1>* @[[C1]], align 4 |
| 39 ; C4xi1-NEXT: %[[M2:[_a-z0-9]+]] = load <4 x i1>* @[[C2]], align 4 |
| 40 ; C4xi1-NEXT: %ft0 = and <4 x i1> %in, %[[M1]] |
| 41 ; C4xi1-NEXT: %ft1 = and <4 x i1> %[[M2]], %in |
| 42 ; C4xi1-NEXT: ret void |
| 43 |
| 44 ; 8xi1 vectors should get globalized. |
| 45 define void @test8xi1(<8 x i1> %in) { |
| 46 %ft0 = and <8 x i1> %in, <i1 false, i1 true, i1 false, i1 true, i1 false, i1 t
rue, i1 false, i1 true> |
| 47 %ft1 = and <8 x i1> <i1 true, i1 false, i1 true, i1 false, i1 true, i1 false,
i1 true, i1 false>, %in |
| 48 ret void |
| 49 } |
| 50 ; C8xi1: @[[C1:[_a-z0-9]+]] = internal unnamed_addr constant <8 x i1> <i1 false,
i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true>, align 8 |
| 51 ; C8xi1: @[[C2:[_a-z0-9]+]] = internal unnamed_addr constant <8 x i1> <i1 true,
i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false>, align 8 |
| 52 ; C8xi1: define void @test8xi1(<8 x i1> %in) { |
| 53 ; C8xi1-NEXT: %[[M1:[_a-z0-9]+]] = load <8 x i1>* @[[C1]], align 8 |
| 54 ; C8xi1-NEXT: %[[M2:[_a-z0-9]+]] = load <8 x i1>* @[[C2]], align 8 |
| 55 ; C8xi1-NEXT: %ft0 = and <8 x i1> %in, %[[M1]] |
| 56 ; C8xi1-NEXT: %ft1 = and <8 x i1> %[[M2]], %in |
| 57 ; C8xi1-NEXT: ret void |
| 58 |
| 59 ; 16xi1 vectors should get globalized. |
| 60 define void @test16xi1(<16 x i1> %in) { |
| 61 %ft0 = and <16 x i1> %in, <i1 false, i1 true, i1 false, i1 true, i1 false, i1
true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true
, i1 false, i1 true> |
| 62 %ft1 = and <16 x i1> <i1 true, i1 false, i1 true, i1 false, i1 true, i1 false,
i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1
true, i1 false>, %in |
| 63 ret void |
| 64 } |
| 65 ; C16xi1: @[[C1:[_a-z0-9]+]] = internal unnamed_addr constant <16 x i1> <i1 fals
e, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i
1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true>, align 16 |
| 66 ; C16xi1: @[[C2:[_a-z0-9]+]] = internal unnamed_addr constant <16 x i1> <i1 true
, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1
false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false>, align 16 |
| 67 ; C16xi1: define void @test16xi1(<16 x i1> %in) { |
| 68 ; C16xi1-NEXT: %[[M1:[_a-z0-9]+]] = load <16 x i1>* @[[C1]], align 16 |
| 69 ; C16xi1-NEXT: %[[M2:[_a-z0-9]+]] = load <16 x i1>* @[[C2]], align 16 |
| 70 ; C16xi1-NEXT: %ft0 = and <16 x i1> %in, %[[M1]] |
| 71 ; C16xi1-NEXT: %ft1 = and <16 x i1> %[[M2]], %in |
| 72 ; C16xi1-NEXT: ret void |
| 73 |
| 74 ; 16xi8 vectors should get globalized. |
| 75 define void @test16xi8(<16 x i8> %in) { |
| 76 %nonsquares = add <16 x i8> %in, <i8 2, i8 3, i8 5, i8 6, i8 7, i8 8, i8 10, i
8 11, i8 12, i8 13, i8 14, i8 15, i8 17, i8 18, i8 19, i8 20> |
| 77 %sort = add <16 x i8> <i8 0, i8 1, i8 3, i8 5, i8 9, i8 11, i8 14, i8 17, i8 2
5, i8 27, i8 30, i8 33, i8 38, i8 41, i8 45, i8 49>, %in |
| 78 ret void |
| 79 } |
| 80 ; C16xi8: @[[C1:[_a-z0-9]+]] = internal unnamed_addr constant <16 x i8> <i8 2, i
8 3, i8 5, i8 6, i8 7, i8 8, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 17, i8
18, i8 19, i8 20>, align 4 |
| 81 ; C16xi8: @[[C2:[_a-z0-9]+]] = internal unnamed_addr constant <16 x i8> <i8 0, i
8 1, i8 3, i8 5, i8 9, i8 11, i8 14, i8 17, i8 25, i8 27, i8 30, i8 33, i8 38, i
8 41, i8 45, i8 49>, align 4 |
| 82 ; C16xi8: define void @test16xi8(<16 x i8> %in) { |
| 83 ; C16xi8-NEXT: %[[M1:[_a-z0-9]+]] = load <16 x i8>* @[[C1]], align 4 |
| 84 ; C16xi8-NEXT: %[[M2:[_a-z0-9]+]] = load <16 x i8>* @[[C2]], align 4 |
| 85 ; C16xi8-NEXT: %nonsquares = add <16 x i8> %in, %[[M1]] |
| 86 ; C16xi8-NEXT: %sort = add <16 x i8> %[[M2]], %in |
| 87 ; C16xi8-NEXT: ret void |
| 88 |
| 89 ; 8xi16 vectors should get globalized. |
| 90 define void @test8xi16(<8 x i16> %in) { |
| 91 %fib = add <8 x i16> %in, <i16 0, i16 1, i16 1, i16 2, i16 3, i16 5, i16 8, i1
6 13> |
| 92 %answer = add <8 x i16> <i16 42, i16 42, i16 42, i16 42, i16 42, i16 42, i16 4
2, i16 42>, %in |
| 93 ret void |
| 94 } |
| 95 ; C8xi16: @[[C1:[_a-z0-9]+]] = internal unnamed_addr constant <8 x i16> <i16 0,
i16 1, i16 1, i16 2, i16 3, i16 5, i16 8, i16 13>, align 4 |
| 96 ; C8xi16: @[[C2:[_a-z0-9]+]] = internal unnamed_addr constant <8 x i16> <i16 42,
i16 42, i16 42, i16 42, i16 42, i16 42, i16 42, i16 42>, align 4 |
| 97 ; C8xi16: define void @test8xi16(<8 x i16> %in) { |
| 98 ; C8xi16-NEXT: %[[M1:[_a-z0-9]+]] = load <8 x i16>* @[[C1]], align 4 |
| 99 ; C8xi16-NEXT: %[[M2:[_a-z0-9]+]] = load <8 x i16>* @[[C2]], align 4 |
| 100 ; C8xi16-NEXT: %fib = add <8 x i16> %in, %[[M1]] |
| 101 ; C8xi16-NEXT: %answer = add <8 x i16> %[[M2]], %in |
| 102 ; C8xi16-NEXT: ret void |
| 103 |
| 104 ; 4xi32 vectors should get globalized. |
| 105 define void @test4xi32(<4 x i32> %in) { |
| 106 %tetrahedral = add <4 x i32> %in, <i32 1, i32 4, i32 10, i32 20> |
| 107 %serauqs = add <4 x i32> <i32 1, i32 4, i32 9, i32 61>, %in |
| 108 ret void |
| 109 } |
| 110 ; C4xi32: @[[C1:[_a-z0-9]+]] = internal unnamed_addr constant <4 x i32> <i32 1,
i32 4, i32 10, i32 20>, align 4 |
| 111 ; C4xi32: @[[C2:[_a-z0-9]+]] = internal unnamed_addr constant <4 x i32> <i32 1,
i32 4, i32 9, i32 61>, align 4 |
| 112 ; C4xi32: define void @test4xi32(<4 x i32> %in) { |
| 113 ; C4xi32-NEXT: %[[M1:[_a-z0-9]+]] = load <4 x i32>* @[[C1]], align 4 |
| 114 ; C4xi32-NEXT: %[[M2:[_a-z0-9]+]] = load <4 x i32>* @[[C2]], align 4 |
| 115 ; C4xi32-NEXT: %tetrahedral = add <4 x i32> %in, %[[M1]] |
| 116 ; C4xi32-NEXT: %serauqs = add <4 x i32> %[[M2]], %in |
| 117 ; C4xi32-NEXT: ret void |
| 118 |
| 119 ; 4xfloat vectors should get globalized. |
| 120 define void @test4xfloat(<4 x float> %in) { |
| 121 %polyhex = fadd <4 x float> %in, <float 1., float 1., float 3., float 7.> |
| 122 %poset = fadd <4 x float> <float 1., float 1., float 3., float 19.>, %in |
| 123 ret void |
| 124 } |
| 125 ; C4xfloat: @[[C1:[_a-z0-9]+]] = internal unnamed_addr constant <4 x float> <flo
at 1.000000e+00, float 1.000000e+00, float 3.000000e+00, float 7.000000e+00>, al
ign 4 |
| 126 ; C4xfloat: @[[C2:[_a-z0-9]+]] = internal unnamed_addr constant <4 x float> <flo
at 1.000000e+00, float 1.000000e+00, float 3.000000e+00, float 1.900000e+01>, al
ign 4 |
| 127 ; C4xfloat: define void @test4xfloat(<4 x float> %in) { |
| 128 ; C4xfloat-NEXT: %[[M1:[_a-z0-9]+]] = load <4 x float>* @[[C1]], align 4 |
| 129 ; C4xfloat-NEXT: %[[M2:[_a-z0-9]+]] = load <4 x float>* @[[C2]], align 4 |
| 130 ; C4xfloat-NEXT: %polyhex = fadd <4 x float> %in, %[[M1]] |
| 131 ; C4xfloat-NEXT: %poset = fadd <4 x float> %[[M2]], %in |
| 132 ; C4xfloat-NEXT: ret void |
| 133 |
| 134 ; Globalized constant loads have to dominate their use. |
| 135 define void @testbranch(i1 %cond, <4 x i32> %in) { |
| 136 br i1 %cond, label %lhs, label %rhs |
| 137 lhs: |
| 138 %from_lhs = add <4 x i32> %in, <i32 1, i32 1, i32 2, i32 2> |
| 139 br label %done |
| 140 rhs: |
| 141 %from_rhs = add <4 x i32> <i32 2, i32 2, i32 1, i32 1>, %in |
| 142 br label %done |
| 143 done: |
| 144 %merged = phi <4 x i32> [ %from_lhs, %lhs ], [ %from_rhs, %rhs ] |
| 145 ret void |
| 146 } |
| 147 ; Cbranch: @[[C1:[_a-z0-9]+]] = internal unnamed_addr constant <4 x i32> <i32 1,
i32 1, i32 2, i32 2>, align 4 |
| 148 ; Cbranch: @[[C2:[_a-z0-9]+]] = internal unnamed_addr constant <4 x i32> <i32 2,
i32 2, i32 1, i32 1>, align 4 |
| 149 ; Cbranch: define void @testbranch(i1 %cond, <4 x i32> %in) { |
| 150 ; Cbranch-NEXT: %[[M1:[_a-z0-9]+]] = load <4 x i32>* @[[C1]], align 4 |
| 151 ; Cbranch-NEXT: %[[M2:[_a-z0-9]+]] = load <4 x i32>* @[[C2]], align 4 |
| 152 ; Cbranch-NEXT: br i1 %cond, label %lhs, label %rhs |
| 153 ; Cbranch: lhs: |
| 154 ; Cbranch-NEXT: %from_lhs = add <4 x i32> %in, %[[M1]] |
| 155 ; Cbranch-NEXT: br label %done |
| 156 ; Cbranch: rhs: |
| 157 ; Cbranch-NEXT: %from_rhs = add <4 x i32> %[[M2]], %in |
| 158 ; Cbranch-NEXT: br label %done |
| 159 ; Cbranch: done: |
| 160 ; Cbranch-NEXT: %merged = phi <4 x i32> [ %from_lhs, %lhs ], [ %from_rhs, %rhs ] |
| 161 ; Cbranch-NEXT: ret void |
| 162 |
| 163 ; Globalizing redundant constants between functions should materialize |
| 164 ; them in each function, but there should only be a single global. |
| 165 define void @testduplicate1() { |
| 166 %foo = add <4 x i32> <i32 1, i32 1, i32 1, i32 1>, undef |
| 167 ret void |
| 168 } |
| 169 define void @testduplicate2() { |
| 170 %foo = add <4 x i32> <i32 1, i32 1, i32 1, i32 1>, undef |
| 171 ret void |
| 172 } |
| 173 ; Cduplicate: @[[C1:[_a-z0-9]+]] = internal unnamed_addr constant <4 x i32> <i32
1, i32 1, i32 1, i32 1>, align 4 |
| 174 ; Cduplicate: define void @testduplicate1() { |
| 175 ; Cduplicate-NEXT: %[[M1:[_a-z0-9]+]] = load <4 x i32>* @[[C1]], align 4 |
| 176 ; Cduplicate-NEXT: %foo = add <4 x i32> %[[M1]], undef |
| 177 ; Cduplicate-NEXT: ret void |
| 178 ; Cduplicate: define void @testduplicate2() { |
| 179 ; Cduplicate-NEXT: %[[M1:[_a-z0-9]+]] = load <4 x i32>* @[[C1]], align 4 |
| 180 ; Cduplicate-NEXT: %foo = add <4 x i32> %[[M1]], undef |
| 181 ; Cduplicate-NEXT: ret void |
| 182 |
| 183 ; zeroinitializer vectors should get globalized. |
| 184 define void @testzeroinitializer(<4 x float> %in) { |
| 185 %id = fadd <4 x float> %in, <float 0.0, float 0.0, float 0.0, float 0.0> |
| 186 ret void |
| 187 } |
| 188 ; Czeroinitializer: @[[C1:[_a-z0-9]+]] = internal unnamed_addr constant <4 x flo
at> zeroinitializer, align 4 |
| 189 ; Czeroinitializer: define void @testzeroinitializer(<4 x float> %in) { |
| 190 ; Czeroinitializer-NEXT: %[[M1:[_a-z0-9]+]] = load <4 x float>* @[[C1]], align 4 |
| 191 ; Czeroinitializer-NEXT: %id = fadd <4 x float> %in, %[[M1]] |
| 192 ; Czeroinitializer-NEXT: ret void |
| 193 |
| 194 ; Nested constant exprs are handled by running -expand-constant-expr first. |
| 195 define i64 @test_nested_const(i64 %x) { |
| 196 %foo = add i64 bitcast (<8 x i8><i8 10, i8 20, i8 30, i8 40, i8 50, i8 60, i8
70, i8 80> to i64), %x |
| 197 ret i64 %foo |
| 198 } |
| 199 ; Cnestedconst: @[[C1:[_a-z0-9]+]] = internal unnamed_addr constant <8 x i8> <i8
10, i8 20, i8 30, i8 40, i8 50, i8 60, i8 70, i8 80>, align 8 |
| 200 ; Cnestedconst: define i64 @test_nested_const(i64 %x) { |
| 201 ; Cnestedconst-NEXT: %[[M1:[_a-z0-9]+]] = load <8 x i8>* @[[C1]], align 8 |
| 202 ; Cnestedconst-NEXT: %[[X1:[_a-z0-9]+]] = bitcast <8 x i8> %[[M1]] to i64 |
| 203 ; Cnestedconst-NEXT: add i64 %[[X1]], %x |
| 204 ; Cnestedconst-NEXT: ret i64 %foo |
OLD | NEW |