blob: 577245cda60416ade856bc24c52d77e638872b7e [file] [log] [blame]
Dorit Nuzmand1247a62016-09-22 07:56:23 +00001; RUN: opt < %s -sroa -S | FileCheck %s
2;
Michael Kruse978ba612018-12-20 04:58:07 +00003; Make sure the llvm.access.group meta-data is preserved
Dorit Nuzmand1247a62016-09-22 07:56:23 +00004; when a load/store is replaced with another load/store by sroa
5;
6; class Complex {
7; private:
8; float real_;
9; float imaginary_;
10;
11; public:
12; Complex() : real_(0), imaginary_(0) { }
13; Complex(float real, float imaginary) : real_(real), imaginary_(imaginary) { }
14; Complex(const Complex &rhs) : real_(rhs.real()), imaginary_(rhs.imaginary()) { }
15;
16; inline float real() const { return real_; }
17; inline float imaginary() const { return imaginary_; }
18;
19; Complex operator+(const Complex& rhs) const
20; {
21; return Complex(real_ + rhs.real_, imaginary_ + rhs.imaginary_);
22; }
23; };
24;
25; void test(Complex *out, long size)
26; {
27; #pragma clang loop vectorize(assume_safety)
28; for (long offset = 0; offset < size; ++offset) {
29; Complex t0 = out[offset];
30; out[offset] = t0 + t0;
31; }
32; }
33
34; CHECK: for.body:
35; CHECK-NOT: store i32 %{{.*}}, i32* %{{.*}}, align 4
Michael Kruse978ba612018-12-20 04:58:07 +000036; CHECK: store i32 %{{.*}}, i32* %{{.*}}, align 4, !llvm.access.group !1
Dorit Nuzmand1247a62016-09-22 07:56:23 +000037; CHECK-NOT: store i32 %{{.*}}, i32* %{{.*}}, align 4
Michael Kruse978ba612018-12-20 04:58:07 +000038; CHECK: store i32 %{{.*}}, i32* %{{.*}}, align 4, !llvm.access.group !1
Dorit Nuzmand1247a62016-09-22 07:56:23 +000039; CHECK-NOT: store i32 %{{.*}}, i32* %{{.*}}, align 4
40; CHECK: br label
41
42; ModuleID = '<stdin>'
43source_filename = "mem-par-metadata-sroa1.cpp"
44target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
45target triple = "x86_64-unknown-linux-gnu"
46
47%class.Complex = type { float, float }
48
49; Function Attrs: norecurse nounwind uwtable
50define void @_Z4testP7Complexl(%class.Complex* nocapture %out, i64 %size) local_unnamed_addr #0 {
51entry:
52 %t0 = alloca %class.Complex, align 4
53 %ref.tmp = alloca i64, align 8
54 %tmpcast = bitcast i64* %ref.tmp to %class.Complex*
55 br label %for.cond
56
57for.cond: ; preds = %for.body, %entry
58 %offset.0 = phi i64 [ 0, %entry ], [ %inc, %for.body ]
59 %cmp = icmp slt i64 %offset.0, %size
60 br i1 %cmp, label %for.body, label %for.end
61
62for.body: ; preds = %for.cond
63 %arrayidx = getelementptr inbounds %class.Complex, %class.Complex* %out, i64 %offset.0
64 %real_.i = getelementptr inbounds %class.Complex, %class.Complex* %t0, i64 0, i32 0
65 %real_.i.i = getelementptr inbounds %class.Complex, %class.Complex* %arrayidx, i64 0, i32 0
Michael Kruse978ba612018-12-20 04:58:07 +000066 %0 = load float, float* %real_.i.i, align 4, !llvm.access.group !11
67 store float %0, float* %real_.i, align 4, !llvm.access.group !11
Dorit Nuzmand1247a62016-09-22 07:56:23 +000068 %imaginary_.i = getelementptr inbounds %class.Complex, %class.Complex* %t0, i64 0, i32 1
69 %imaginary_.i.i = getelementptr inbounds %class.Complex, %class.Complex* %arrayidx, i64 0, i32 1
Michael Kruse978ba612018-12-20 04:58:07 +000070 %1 = load float, float* %imaginary_.i.i, align 4, !llvm.access.group !11
71 store float %1, float* %imaginary_.i, align 4, !llvm.access.group !11
Dorit Nuzmand1247a62016-09-22 07:56:23 +000072 %arrayidx1 = getelementptr inbounds %class.Complex, %class.Complex* %out, i64 %offset.0
73 %real_.i1 = getelementptr inbounds %class.Complex, %class.Complex* %t0, i64 0, i32 0
Michael Kruse978ba612018-12-20 04:58:07 +000074 %2 = load float, float* %real_.i1, align 4, !noalias !3, !llvm.access.group !11
Dorit Nuzmand1247a62016-09-22 07:56:23 +000075 %real_2.i = getelementptr inbounds %class.Complex, %class.Complex* %t0, i64 0, i32 0
Michael Kruse978ba612018-12-20 04:58:07 +000076 %3 = load float, float* %real_2.i, align 4, !noalias !3, !llvm.access.group !11
Dorit Nuzmand1247a62016-09-22 07:56:23 +000077 %add.i = fadd float %2, %3
78 %imaginary_.i2 = getelementptr inbounds %class.Complex, %class.Complex* %t0, i64 0, i32 1
Michael Kruse978ba612018-12-20 04:58:07 +000079 %4 = load float, float* %imaginary_.i2, align 4, !noalias !3, !llvm.access.group !11
Dorit Nuzmand1247a62016-09-22 07:56:23 +000080 %imaginary_3.i = getelementptr inbounds %class.Complex, %class.Complex* %t0, i64 0, i32 1
Michael Kruse978ba612018-12-20 04:58:07 +000081 %5 = load float, float* %imaginary_3.i, align 4, !noalias !3, !llvm.access.group !11
Dorit Nuzmand1247a62016-09-22 07:56:23 +000082 %add4.i = fadd float %4, %5
83 %real_.i.i3 = getelementptr inbounds %class.Complex, %class.Complex* %tmpcast, i64 0, i32 0
Michael Kruse978ba612018-12-20 04:58:07 +000084 store float %add.i, float* %real_.i.i3, align 4, !alias.scope !3, !llvm.access.group !11
Dorit Nuzmand1247a62016-09-22 07:56:23 +000085 %imaginary_.i.i4 = getelementptr inbounds %class.Complex, %class.Complex* %tmpcast, i64 0, i32 1
Michael Kruse978ba612018-12-20 04:58:07 +000086 store float %add4.i, float* %imaginary_.i.i4, align 4, !alias.scope !3, !llvm.access.group !11
Dorit Nuzmand1247a62016-09-22 07:56:23 +000087 %6 = bitcast %class.Complex* %arrayidx1 to i64*
Michael Kruse978ba612018-12-20 04:58:07 +000088 %7 = load i64, i64* %ref.tmp, align 8, !llvm.access.group !11
89 store i64 %7, i64* %6, align 4, !llvm.access.group !11
Dorit Nuzmand1247a62016-09-22 07:56:23 +000090 %inc = add nsw i64 %offset.0, 1
91 br label %for.cond, !llvm.loop !1
92
93for.end: ; preds = %for.cond
94 ret void
95}
96
97; Function Attrs: argmemonly nounwind
Daniel Neilson1e687242018-01-19 17:13:12 +000098declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1) #1
Dorit Nuzmand1247a62016-09-22 07:56:23 +000099
100attributes #0 = { norecurse nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
101attributes #1 = { argmemonly nounwind }
102
103!llvm.ident = !{!0}
104
105!0 = !{!"clang version 4.0.0 (cfe/trunk 277751)"}
Michael Kruse978ba612018-12-20 04:58:07 +0000106!1 = distinct !{!1, !2, !{!"llvm.loop.parallel_accesses", !11}}
Dorit Nuzmand1247a62016-09-22 07:56:23 +0000107!2 = !{!"llvm.loop.vectorize.enable", i1 true}
108!3 = !{!4}
109!4 = distinct !{!4, !5, !"_ZNK7ComplexplERKS_: %agg.result"}
110!5 = distinct !{!5, !"_ZNK7ComplexplERKS_"}
Michael Kruse978ba612018-12-20 04:58:07 +0000111!11 = distinct !{}