Chandler Carruth | 871ba72 | 2012-09-26 10:27:46 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -sroa -S | FileCheck %s |
Chandler Carruth | 43c8b46 | 2012-10-04 10:39:28 +0000 | [diff] [blame] | 2 | target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-n8:16:32:64" |
Chandler Carruth | 871ba72 | 2012-09-26 10:27:46 +0000 | [diff] [blame] | 3 | |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 4 | declare void @llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1) |
Chandler Carruth | 871ba72 | 2012-09-26 10:27:46 +0000 | [diff] [blame] | 5 | |
| 6 | define void @test1({ i8, i8 }* %a, { i8, i8 }* %b) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 7 | ; CHECK-LABEL: @test1( |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 8 | ; CHECK: %[[gep_a0:.*]] = getelementptr inbounds { i8, i8 }, { i8, i8 }* %a, i64 0, i32 0 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 9 | ; CHECK: %[[a0:.*]] = load i8, i8* %[[gep_a0]], align 16 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 10 | ; CHECK: %[[gep_a1:.*]] = getelementptr inbounds { i8, i8 }, { i8, i8 }* %a, i64 0, i32 1 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 11 | ; CHECK: %[[a1:.*]] = load i8, i8* %[[gep_a1]], align 1 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 12 | ; CHECK: %[[gep_b0:.*]] = getelementptr inbounds { i8, i8 }, { i8, i8 }* %b, i64 0, i32 0 |
Chandler Carruth | 871ba72 | 2012-09-26 10:27:46 +0000 | [diff] [blame] | 13 | ; CHECK: store i8 %[[a0]], i8* %[[gep_b0]], align 16 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 14 | ; CHECK: %[[gep_b1:.*]] = getelementptr inbounds { i8, i8 }, { i8, i8 }* %b, i64 0, i32 1 |
Chandler Carruth | 871ba72 | 2012-09-26 10:27:46 +0000 | [diff] [blame] | 15 | ; CHECK: store i8 %[[a1]], i8* %[[gep_b1]], align 1 |
| 16 | ; CHECK: ret void |
| 17 | |
| 18 | entry: |
| 19 | %alloca = alloca { i8, i8 }, align 16 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 20 | %gep_a = getelementptr { i8, i8 }, { i8, i8 }* %a, i32 0, i32 0 |
| 21 | %gep_alloca = getelementptr { i8, i8 }, { i8, i8 }* %alloca, i32 0, i32 0 |
| 22 | %gep_b = getelementptr { i8, i8 }, { i8, i8 }* %b, i32 0, i32 0 |
Chandler Carruth | 871ba72 | 2012-09-26 10:27:46 +0000 | [diff] [blame] | 23 | |
| 24 | store i8 420, i8* %gep_alloca, align 16 |
| 25 | |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 26 | call void @llvm.memcpy.p0i8.p0i8.i32(i8* %gep_alloca, i8* %gep_a, i32 2, i32 16, i1 false) |
| 27 | call void @llvm.memcpy.p0i8.p0i8.i32(i8* %gep_b, i8* %gep_alloca, i32 2, i32 16, i1 false) |
Chandler Carruth | 871ba72 | 2012-09-26 10:27:46 +0000 | [diff] [blame] | 28 | ret void |
| 29 | } |
| 30 | |
Chandler Carruth | 3e4273d | 2012-09-26 10:45:28 +0000 | [diff] [blame] | 31 | define void @test2() { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 32 | ; CHECK-LABEL: @test2( |
Chandler Carruth | 903790e | 2012-09-29 10:41:21 +0000 | [diff] [blame] | 33 | ; CHECK: alloca i16 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 34 | ; CHECK: load i8, i8* %{{.*}} |
Chandler Carruth | 4b2b38d | 2012-10-03 08:14:02 +0000 | [diff] [blame] | 35 | ; CHECK: store i8 42, i8* %{{.*}} |
Chandler Carruth | 3e4273d | 2012-09-26 10:45:28 +0000 | [diff] [blame] | 36 | ; CHECK: ret void |
| 37 | |
| 38 | entry: |
| 39 | %a = alloca { i8, i8, i8, i8 }, align 2 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 40 | %gep1 = getelementptr { i8, i8, i8, i8 }, { i8, i8, i8, i8 }* %a, i32 0, i32 1 |
Chandler Carruth | 3e4273d | 2012-09-26 10:45:28 +0000 | [diff] [blame] | 41 | %cast1 = bitcast i8* %gep1 to i16* |
| 42 | store volatile i16 0, i16* %cast1 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 43 | %gep2 = getelementptr { i8, i8, i8, i8 }, { i8, i8, i8, i8 }* %a, i32 0, i32 2 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 44 | %result = load i8, i8* %gep2 |
Chandler Carruth | 4b2b38d | 2012-10-03 08:14:02 +0000 | [diff] [blame] | 45 | store i8 42, i8* %gep2 |
Chandler Carruth | 3e4273d | 2012-09-26 10:45:28 +0000 | [diff] [blame] | 46 | ret void |
| 47 | } |
| 48 | |
Chandler Carruth | 871ba72 | 2012-09-26 10:27:46 +0000 | [diff] [blame] | 49 | define void @PR13920(<2 x i64>* %a, i16* %b) { |
| 50 | ; Test that alignments on memcpy intrinsics get propagated to loads and stores. |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 51 | ; CHECK-LABEL: @PR13920( |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 52 | ; CHECK: load <2 x i64>, <2 x i64>* %a, align 2 |
Chandler Carruth | 871ba72 | 2012-09-26 10:27:46 +0000 | [diff] [blame] | 53 | ; CHECK: store <2 x i64> {{.*}}, <2 x i64>* {{.*}}, align 2 |
| 54 | ; CHECK: ret void |
| 55 | |
| 56 | entry: |
| 57 | %aa = alloca <2 x i64>, align 16 |
| 58 | %aptr = bitcast <2 x i64>* %a to i8* |
| 59 | %aaptr = bitcast <2 x i64>* %aa to i8* |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 60 | call void @llvm.memcpy.p0i8.p0i8.i32(i8* %aaptr, i8* %aptr, i32 16, i32 2, i1 false) |
Chandler Carruth | 871ba72 | 2012-09-26 10:27:46 +0000 | [diff] [blame] | 61 | %bptr = bitcast i16* %b to i8* |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 62 | call void @llvm.memcpy.p0i8.p0i8.i32(i8* %bptr, i8* %aaptr, i32 16, i32 2, i1 false) |
Chandler Carruth | 871ba72 | 2012-09-26 10:27:46 +0000 | [diff] [blame] | 63 | ret void |
| 64 | } |
Chandler Carruth | 903790e | 2012-09-29 10:41:21 +0000 | [diff] [blame] | 65 | |
| 66 | define void @test3(i8* %x) { |
| 67 | ; Test that when we promote an alloca to a type with lower ABI alignment, we |
| 68 | ; provide the needed explicit alignment that code using the alloca may be |
| 69 | ; expecting. However, also check that any offset within an alloca can in turn |
| 70 | ; reduce the alignment. |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 71 | ; CHECK-LABEL: @test3( |
Chandler Carruth | 903790e | 2012-09-29 10:41:21 +0000 | [diff] [blame] | 72 | ; CHECK: alloca [22 x i8], align 8 |
| 73 | ; CHECK: alloca [18 x i8], align 2 |
| 74 | ; CHECK: ret void |
| 75 | |
| 76 | entry: |
| 77 | %a = alloca { i8*, i8*, i8* } |
| 78 | %b = alloca { i8*, i8*, i8* } |
| 79 | %a_raw = bitcast { i8*, i8*, i8* }* %a to i8* |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 80 | call void @llvm.memcpy.p0i8.p0i8.i32(i8* %a_raw, i8* %x, i32 22, i32 8, i1 false) |
Chandler Carruth | 903790e | 2012-09-29 10:41:21 +0000 | [diff] [blame] | 81 | %b_raw = bitcast { i8*, i8*, i8* }* %b to i8* |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 82 | %b_gep = getelementptr i8, i8* %b_raw, i32 6 |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 83 | call void @llvm.memcpy.p0i8.p0i8.i32(i8* %b_gep, i8* %x, i32 18, i32 2, i1 false) |
Chandler Carruth | 903790e | 2012-09-29 10:41:21 +0000 | [diff] [blame] | 84 | ret void |
| 85 | } |
Chandler Carruth | 176ca71 | 2012-10-01 12:16:54 +0000 | [diff] [blame] | 86 | |
Chandler Carruth | 4b2b38d | 2012-10-03 08:14:02 +0000 | [diff] [blame] | 87 | define void @test5() { |
Chandler Carruth | 24ac830 | 2015-01-02 03:55:54 +0000 | [diff] [blame] | 88 | ; Test that we preserve underaligned loads and stores when splitting. The use |
| 89 | ; of volatile in this test case is just to force the loads and stores to not be |
| 90 | ; split or promoted out of existence. |
| 91 | ; |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 92 | ; CHECK-LABEL: @test5( |
Chandler Carruth | 4b2b38d | 2012-10-03 08:14:02 +0000 | [diff] [blame] | 93 | ; CHECK: alloca [9 x i8] |
| 94 | ; CHECK: alloca [9 x i8] |
| 95 | ; CHECK: store volatile double 0.0{{.*}}, double* %{{.*}}, align 1 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 96 | ; CHECK: load volatile i16, i16* %{{.*}}, align 1 |
| 97 | ; CHECK: load double, double* %{{.*}}, align 1 |
Chandler Carruth | 4b2b38d | 2012-10-03 08:14:02 +0000 | [diff] [blame] | 98 | ; CHECK: store volatile double %{{.*}}, double* %{{.*}}, align 1 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 99 | ; CHECK: load volatile i16, i16* %{{.*}}, align 1 |
Chandler Carruth | 4b2b38d | 2012-10-03 08:14:02 +0000 | [diff] [blame] | 100 | ; CHECK: ret void |
| 101 | |
| 102 | entry: |
| 103 | %a = alloca [18 x i8] |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 104 | %raw1 = getelementptr inbounds [18 x i8], [18 x i8]* %a, i32 0, i32 0 |
Chandler Carruth | 4b2b38d | 2012-10-03 08:14:02 +0000 | [diff] [blame] | 105 | %ptr1 = bitcast i8* %raw1 to double* |
| 106 | store volatile double 0.0, double* %ptr1, align 1 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 107 | %weird_gep1 = getelementptr inbounds [18 x i8], [18 x i8]* %a, i32 0, i32 7 |
Chandler Carruth | 4b2b38d | 2012-10-03 08:14:02 +0000 | [diff] [blame] | 108 | %weird_cast1 = bitcast i8* %weird_gep1 to i16* |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 109 | %weird_load1 = load volatile i16, i16* %weird_cast1, align 1 |
Chandler Carruth | 4b2b38d | 2012-10-03 08:14:02 +0000 | [diff] [blame] | 110 | |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 111 | %raw2 = getelementptr inbounds [18 x i8], [18 x i8]* %a, i32 0, i32 9 |
Chandler Carruth | 4b2b38d | 2012-10-03 08:14:02 +0000 | [diff] [blame] | 112 | %ptr2 = bitcast i8* %raw2 to double* |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 113 | %d1 = load double, double* %ptr1, align 1 |
Chandler Carruth | 4b2b38d | 2012-10-03 08:14:02 +0000 | [diff] [blame] | 114 | store volatile double %d1, double* %ptr2, align 1 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 115 | %weird_gep2 = getelementptr inbounds [18 x i8], [18 x i8]* %a, i32 0, i32 16 |
Chandler Carruth | 4b2b38d | 2012-10-03 08:14:02 +0000 | [diff] [blame] | 116 | %weird_cast2 = bitcast i8* %weird_gep2 to i16* |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 117 | %weird_load2 = load volatile i16, i16* %weird_cast2, align 1 |
Chandler Carruth | 4b2b38d | 2012-10-03 08:14:02 +0000 | [diff] [blame] | 118 | |
| 119 | ret void |
| 120 | } |
| 121 | |
| 122 | define void @test6() { |
| 123 | ; Test that we promote alignment when the underlying alloca switches to one |
| 124 | ; that innately provides it. |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 125 | ; CHECK-LABEL: @test6( |
Chandler Carruth | 4b2b38d | 2012-10-03 08:14:02 +0000 | [diff] [blame] | 126 | ; CHECK: alloca double |
| 127 | ; CHECK: alloca double |
| 128 | ; CHECK-NOT: align |
| 129 | ; CHECK: ret void |
| 130 | |
| 131 | entry: |
| 132 | %a = alloca [16 x i8] |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 133 | %raw1 = getelementptr inbounds [16 x i8], [16 x i8]* %a, i32 0, i32 0 |
Chandler Carruth | 4b2b38d | 2012-10-03 08:14:02 +0000 | [diff] [blame] | 134 | %ptr1 = bitcast i8* %raw1 to double* |
| 135 | store volatile double 0.0, double* %ptr1, align 1 |
| 136 | |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 137 | %raw2 = getelementptr inbounds [16 x i8], [16 x i8]* %a, i32 0, i32 8 |
Chandler Carruth | 4b2b38d | 2012-10-03 08:14:02 +0000 | [diff] [blame] | 138 | %ptr2 = bitcast i8* %raw2 to double* |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 139 | %val = load double, double* %ptr1, align 1 |
Chandler Carruth | 4b2b38d | 2012-10-03 08:14:02 +0000 | [diff] [blame] | 140 | store volatile double %val, double* %ptr2, align 1 |
| 141 | |
| 142 | ret void |
| 143 | } |
Chandler Carruth | 08e5f49 | 2012-10-03 08:26:28 +0000 | [diff] [blame] | 144 | |
| 145 | define void @test7(i8* %out) { |
| 146 | ; Test that we properly compute the destination alignment when rewriting |
| 147 | ; memcpys as direct loads or stores. |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 148 | ; CHECK-LABEL: @test7( |
Chandler Carruth | 08e5f49 | 2012-10-03 08:26:28 +0000 | [diff] [blame] | 149 | ; CHECK-NOT: alloca |
| 150 | |
| 151 | entry: |
| 152 | %a = alloca [16 x i8] |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 153 | %raw1 = getelementptr inbounds [16 x i8], [16 x i8]* %a, i32 0, i32 0 |
Chandler Carruth | 08e5f49 | 2012-10-03 08:26:28 +0000 | [diff] [blame] | 154 | %ptr1 = bitcast i8* %raw1 to double* |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 155 | %raw2 = getelementptr inbounds [16 x i8], [16 x i8]* %a, i32 0, i32 8 |
Chandler Carruth | 08e5f49 | 2012-10-03 08:26:28 +0000 | [diff] [blame] | 156 | %ptr2 = bitcast i8* %raw2 to double* |
| 157 | |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 158 | call void @llvm.memcpy.p0i8.p0i8.i32(i8* %raw1, i8* %out, i32 16, i32 0, i1 false) |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 159 | ; CHECK: %[[val2:.*]] = load double, double* %{{.*}}, align 1 |
| 160 | ; CHECK: %[[val1:.*]] = load double, double* %{{.*}}, align 1 |
Chandler Carruth | 08e5f49 | 2012-10-03 08:26:28 +0000 | [diff] [blame] | 161 | |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 162 | %val1 = load double, double* %ptr2, align 1 |
| 163 | %val2 = load double, double* %ptr1, align 1 |
Chandler Carruth | 08e5f49 | 2012-10-03 08:26:28 +0000 | [diff] [blame] | 164 | |
| 165 | store double %val1, double* %ptr1, align 1 |
| 166 | store double %val2, double* %ptr2, align 1 |
| 167 | |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 168 | call void @llvm.memcpy.p0i8.p0i8.i32(i8* %out, i8* %raw1, i32 16, i32 0, i1 false) |
Chandler Carruth | 08e5f49 | 2012-10-03 08:26:28 +0000 | [diff] [blame] | 169 | ; CHECK: store double %[[val1]], double* %{{.*}}, align 1 |
| 170 | ; CHECK: store double %[[val2]], double* %{{.*}}, align 1 |
| 171 | |
| 172 | ret void |
| 173 | ; CHECK: ret void |
| 174 | } |