1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -passes='sroa<preserve-cfg>' -S | FileCheck %s --check-prefixes=CHECK,CHECK-PRESERVE-CFG 3; RUN: opt < %s -passes='sroa<modify-cfg>' -S | FileCheck %s --check-prefixes=CHECK,CHECK-MODIFY-CFG 4; 5; Make sure the llvm.access.group meta-data is preserved 6; when a load/store is replaced with another load/store by sroa 7; 8; class Complex { 9; private: 10; float real_; 11; float imaginary_; 12; 13; public: 14; Complex() : real_(0), imaginary_(0) { } 15; Complex(float real, float imaginary) : real_(real), imaginary_(imaginary) { } 16; Complex(const Complex &rhs) : real_(rhs.real()), imaginary_(rhs.imaginary()) { } 17; 18; inline float real() const { return real_; } 19; inline float imaginary() const { return imaginary_; } 20; 21; Complex operator+(const Complex& rhs) const 22; { 23; return Complex(real_ + rhs.real_, imaginary_ + rhs.imaginary_); 24; } 25; }; 26; 27; void test(Complex *out, long size) 28; { 29; #pragma clang loop vectorize(assume_safety) 30; for (long offset = 0; offset < size; ++offset) { 31; Complex t0 = out[offset]; 32; out[offset] = t0 + t0; 33; } 34; } 35 36 37; ModuleID = '<stdin>' 38source_filename = "mem-par-metadata-sroa1.cpp" 39target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 40target triple = "x86_64-unknown-linux-gnu" 41 42%class.Complex = type { float, float } 43 44; Function Attrs: norecurse nounwind uwtable 45define void @_Z4testP7Complexl(ptr nocapture %out, i64 %size) local_unnamed_addr #0 { 46; CHECK-LABEL: @_Z4testP7Complexl( 47; CHECK-NEXT: entry: 48; CHECK-NEXT: br label [[FOR_COND:%.*]] 49; CHECK: for.cond: 50; CHECK-NEXT: [[OFFSET_0:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[FOR_BODY:%.*]] ] 51; CHECK-NEXT: [[CMP:%.*]] = icmp slt i64 [[OFFSET_0]], [[SIZE:%.*]] 52; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END:%.*]] 53; CHECK: for.body: 54; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [[CLASS_COMPLEX:%.*]], ptr [[OUT:%.*]], i64 [[OFFSET_0]] 55; CHECK-NEXT: [[TMP0:%.*]] = load float, ptr [[ARRAYIDX]], align 4, !llvm.access.group [[ACC_GRP1:![0-9]+]] 56; CHECK-NEXT: [[IMAGINARY__I_I:%.*]] = getelementptr inbounds [[CLASS_COMPLEX]], ptr [[ARRAYIDX]], i64 0, i32 1 57; CHECK-NEXT: [[TMP1:%.*]] = load float, ptr [[IMAGINARY__I_I]], align 4, !llvm.access.group [[ACC_GRP1]] 58; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds [[CLASS_COMPLEX]], ptr [[OUT]], i64 [[OFFSET_0]] 59; CHECK-NEXT: [[ADD_I:%.*]] = fadd float [[TMP0]], [[TMP0]] 60; CHECK-NEXT: [[ADD4_I:%.*]] = fadd float [[TMP1]], [[TMP1]] 61; CHECK-NEXT: [[TMP2:%.*]] = bitcast float [[ADD_I]] to i32 62; CHECK-NEXT: [[TMP3:%.*]] = bitcast float [[ADD4_I]] to i32 63; CHECK-NEXT: store i32 [[TMP2]], ptr [[ARRAYIDX1]], align 4, !llvm.access.group [[ACC_GRP1]] 64; CHECK-NEXT: [[ARRAYIDX1_SROA_IDX:%.*]] = getelementptr inbounds i8, ptr [[ARRAYIDX1]], i64 4 65; CHECK-NEXT: store i32 [[TMP3]], ptr [[ARRAYIDX1_SROA_IDX]], align 4, !llvm.access.group [[ACC_GRP1]] 66; CHECK-NEXT: [[INC]] = add nsw i64 [[OFFSET_0]], 1 67; CHECK-NEXT: br label [[FOR_COND]], !llvm.loop [[LOOP2:![0-9]+]] 68; CHECK: for.end: 69; CHECK-NEXT: ret void 70; 71entry: 72 %t0 = alloca %class.Complex, align 4 73 %ref.tmp = alloca i64, align 8 74 br label %for.cond 75 76for.cond: ; preds = %for.body, %entry 77 %offset.0 = phi i64 [ 0, %entry ], [ %inc, %for.body ] 78 %cmp = icmp slt i64 %offset.0, %size 79 br i1 %cmp, label %for.body, label %for.end 80 81for.body: ; preds = %for.cond 82 %arrayidx = getelementptr inbounds %class.Complex, ptr %out, i64 %offset.0 83 %0 = load float, ptr %arrayidx, align 4, !llvm.access.group !11 84 store float %0, ptr %t0, align 4, !llvm.access.group !11 85 %imaginary_.i = getelementptr inbounds %class.Complex, ptr %t0, i64 0, i32 1 86 %imaginary_.i.i = getelementptr inbounds %class.Complex, ptr %arrayidx, i64 0, i32 1 87 %1 = load float, ptr %imaginary_.i.i, align 4, !llvm.access.group !11 88 store float %1, ptr %imaginary_.i, align 4, !llvm.access.group !11 89 %arrayidx1 = getelementptr inbounds %class.Complex, ptr %out, i64 %offset.0 90 %2 = load float, ptr %t0, align 4, !noalias !3, !llvm.access.group !11 91 %3 = load float, ptr %t0, align 4, !noalias !3, !llvm.access.group !11 92 %add.i = fadd float %2, %3 93 %imaginary_.i2 = getelementptr inbounds %class.Complex, ptr %t0, i64 0, i32 1 94 %4 = load float, ptr %imaginary_.i2, align 4, !noalias !3, !llvm.access.group !11 95 %imaginary_3.i = getelementptr inbounds %class.Complex, ptr %t0, i64 0, i32 1 96 %5 = load float, ptr %imaginary_3.i, align 4, !noalias !3, !llvm.access.group !11 97 %add4.i = fadd float %4, %5 98 store float %add.i, ptr %ref.tmp, align 4, !alias.scope !3, !llvm.access.group !11 99 %imaginary_.i.i4 = getelementptr inbounds %class.Complex, ptr %ref.tmp, i64 0, i32 1 100 store float %add4.i, ptr %imaginary_.i.i4, align 4, !alias.scope !3, !llvm.access.group !11 101 %6 = load i64, ptr %ref.tmp, align 8, !llvm.access.group !11 102 store i64 %6, ptr %arrayidx1, align 4, !llvm.access.group !11 103 %inc = add nsw i64 %offset.0, 1 104 br label %for.cond, !llvm.loop !1 105 106for.end: ; preds = %for.cond 107 ret void 108} 109 110; Function Attrs: argmemonly nounwind 111declare void @llvm.memcpy.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1) #1 112 113attributes #0 = { norecurse nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="all" "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" } 114attributes #1 = { argmemonly nounwind } 115 116!llvm.ident = !{!0} 117 118!0 = !{!"clang version 4.0.0 (cfe/trunk 277751)"} 119!1 = distinct !{!1, !2, !{!"llvm.loop.parallel_accesses", !11}} 120!2 = !{!"llvm.loop.vectorize.enable", i1 true} 121!3 = !{!4} 122!4 = distinct !{!4, !5, !"_ZNK7ComplexplERKS_: %agg.result"} 123!5 = distinct !{!5, !"_ZNK7ComplexplERKS_"} 124!11 = distinct !{} 125;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line: 126; CHECK-MODIFY-CFG: {{.*}} 127; CHECK-PRESERVE-CFG: {{.*}} 128