Duncan P. N. Exon Smith | 73686d3 | 2014-06-17 00:19:35 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -sroa -S | FileCheck %s |
Reid Kleckner | c36f48f | 2014-08-22 00:09:56 +0000 | [diff] [blame] | 2 | target datalayout = "e-p:64:64:64-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-f80:128-v64:64:64-v128:128:128-a0:0:64-n8:16:32:64" |
Duncan P. N. Exon Smith | 73686d3 | 2014-06-17 00:19:35 +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* nocapture, i8* nocapture, i32, i32, i1) nounwind |
| 5 | declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) nounwind |
Duncan P. N. Exon Smith | 73686d3 | 2014-06-17 00:19:35 +0000 | [diff] [blame] | 6 | |
| 7 | define void @no_split_on_non_byte_width(i32) { |
| 8 | ; This tests that allocas are not split into slices that are not byte width multiple |
| 9 | %arg = alloca i32 , align 8 |
| 10 | store i32 %0, i32* %arg |
| 11 | br label %load_i32 |
| 12 | |
| 13 | load_i32: |
| 14 | ; CHECK-LABEL: load_i32: |
| 15 | ; CHECK-NOT: bitcast {{.*}} to i1 |
| 16 | ; CHECK-NOT: zext i1 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 17 | %r0 = load i32, i32* %arg |
Duncan P. N. Exon Smith | 73686d3 | 2014-06-17 00:19:35 +0000 | [diff] [blame] | 18 | br label %load_i1 |
| 19 | |
| 20 | load_i1: |
| 21 | ; CHECK-LABEL: load_i1: |
| 22 | ; CHECK: bitcast {{.*}} to i1 |
| 23 | %p1 = bitcast i32* %arg to i1* |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 24 | %t1 = load i1, i1* %p1 |
Duncan P. N. Exon Smith | 73686d3 | 2014-06-17 00:19:35 +0000 | [diff] [blame] | 25 | ret void |
| 26 | } |
Reid Kleckner | c36f48f | 2014-08-22 00:09:56 +0000 | [diff] [blame] | 27 | |
| 28 | ; PR18726: Check that we use memcpy and memset to fill out padding when we have |
| 29 | ; a slice with a simple single type whose store size is smaller than the slice |
| 30 | ; size. |
| 31 | |
| 32 | %union.Foo = type { x86_fp80, i64, i64 } |
| 33 | |
| 34 | @foo_copy_source = external constant %union.Foo |
| 35 | @i64_sink = global i64 0 |
| 36 | |
| 37 | define void @memcpy_fp80_padding() { |
| 38 | %x = alloca %union.Foo |
| 39 | |
| 40 | ; Copy from a global. |
| 41 | %x_i8 = bitcast %union.Foo* %x to i8* |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 42 | call void @llvm.memcpy.p0i8.p0i8.i32(i8* %x_i8, i8* bitcast (%union.Foo* @foo_copy_source to i8*), i32 32, i32 16, i1 false) |
Reid Kleckner | c36f48f | 2014-08-22 00:09:56 +0000 | [diff] [blame] | 43 | |
| 44 | ; Access a slice of the alloca to trigger SROA. |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 45 | %mid_p = getelementptr %union.Foo, %union.Foo* %x, i32 0, i32 1 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 46 | %elt = load i64, i64* %mid_p |
Reid Kleckner | c36f48f | 2014-08-22 00:09:56 +0000 | [diff] [blame] | 47 | store i64 %elt, i64* @i64_sink |
| 48 | ret void |
| 49 | } |
| 50 | ; CHECK-LABEL: define void @memcpy_fp80_padding |
| 51 | ; CHECK: alloca x86_fp80 |
| 52 | ; CHECK: call void @llvm.memcpy.p0i8.p0i8.i32 |
David Blaikie | f72d05b | 2015-03-13 18:20:45 +0000 | [diff] [blame] | 53 | ; CHECK: load i64, i64* getelementptr inbounds (%union.Foo, %union.Foo* @foo_copy_source, i64 0, i32 1) |
| 54 | ; CHECK: load i64, i64* getelementptr inbounds (%union.Foo, %union.Foo* @foo_copy_source, i64 0, i32 2) |
Reid Kleckner | c36f48f | 2014-08-22 00:09:56 +0000 | [diff] [blame] | 55 | |
| 56 | define void @memset_fp80_padding() { |
| 57 | %x = alloca %union.Foo |
| 58 | |
| 59 | ; Set to all ones. |
| 60 | %x_i8 = bitcast %union.Foo* %x to i8* |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 61 | call void @llvm.memset.p0i8.i32(i8* %x_i8, i8 -1, i32 32, i32 16, i1 false) |
Reid Kleckner | c36f48f | 2014-08-22 00:09:56 +0000 | [diff] [blame] | 62 | |
| 63 | ; Access a slice of the alloca to trigger SROA. |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 64 | %mid_p = getelementptr %union.Foo, %union.Foo* %x, i32 0, i32 1 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 65 | %elt = load i64, i64* %mid_p |
Reid Kleckner | c36f48f | 2014-08-22 00:09:56 +0000 | [diff] [blame] | 66 | store i64 %elt, i64* @i64_sink |
| 67 | ret void |
| 68 | } |
| 69 | ; CHECK-LABEL: define void @memset_fp80_padding |
| 70 | ; CHECK: alloca x86_fp80 |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 71 | ; CHECK: call void @llvm.memset.p0i8.i32(i8* %{{.*}}, i8 -1, i32 16, i32 16, i1 false) |
Reid Kleckner | c36f48f | 2014-08-22 00:09:56 +0000 | [diff] [blame] | 72 | ; CHECK: store i64 -1, i64* @i64_sink |
Yunzhong Gao | 300bdb3 | 2014-08-22 23:27:04 +0000 | [diff] [blame] | 73 | |
| 74 | %S.vec3float = type { float, float, float } |
| 75 | %U.vec3float = type { <4 x float> } |
| 76 | |
| 77 | declare i32 @memcpy_vec3float_helper(%S.vec3float*) |
| 78 | |
| 79 | define i32 @memcpy_vec3float_widening(%S.vec3float* %x) { |
| 80 | ; CHECK-LABEL: @memcpy_vec3float_widening( |
| 81 | ; PR18726: Check that SROA does not rewrite a 12-byte memcpy into a 16-byte |
| 82 | ; vector store, hence accidentally putting gibberish onto the stack. |
| 83 | entry: |
| 84 | ; Create a temporary variable %tmp1 and copy %x[0] into it |
| 85 | %tmp1 = alloca %S.vec3float, align 4 |
| 86 | %0 = bitcast %S.vec3float* %tmp1 to i8* |
| 87 | %1 = bitcast %S.vec3float* %x to i8* |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 88 | call void @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* %1, i32 12, i32 4, i1 false) |
Yunzhong Gao | 300bdb3 | 2014-08-22 23:27:04 +0000 | [diff] [blame] | 89 | |
| 90 | ; The following block does nothing; but appears to confuse SROA |
| 91 | %unused1 = bitcast %S.vec3float* %tmp1 to %U.vec3float* |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 92 | %unused2 = getelementptr inbounds %U.vec3float, %U.vec3float* %unused1, i32 0, i32 0 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 93 | %unused3 = load <4 x float>, <4 x float>* %unused2, align 1 |
Yunzhong Gao | 300bdb3 | 2014-08-22 23:27:04 +0000 | [diff] [blame] | 94 | |
| 95 | ; Create a second temporary and copy %tmp1 into it |
| 96 | %tmp2 = alloca %S.vec3float, align 4 |
| 97 | %2 = bitcast %S.vec3float* %tmp2 to i8* |
| 98 | %3 = bitcast %S.vec3float* %tmp1 to i8* |
| 99 | ; CHECK: alloca |
| 100 | ; CHECK-NOT: store <4 x float> |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 101 | call void @llvm.memcpy.p0i8.p0i8.i32(i8* %2, i8* %3, i32 12, i32 4, i1 false) |
Yunzhong Gao | 300bdb3 | 2014-08-22 23:27:04 +0000 | [diff] [blame] | 102 | |
| 103 | %result = call i32 @memcpy_vec3float_helper(%S.vec3float* %tmp2) |
| 104 | ret i32 %result |
| 105 | ; CHECK: ret i32 %result |
| 106 | } |