brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · 6365234 Raw
88 lines · plain
1; RUN: opt < %s -passes=loop-vectorize,instcombine -force-vector-interleave=1 -force-vector-width=4 -S | FileCheck %s2 3target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"4 5%struct.coordinate = type { i32, i32 }6 7; Make sure that we don't generate a wide load when accessing the struct.8; struct coordinate {9;  int x;10;  int y;11; };12;13;14; int foo(struct coordinate *A, int n) {15;16;   int sum = 0;17;   for (int i = 0; i < n; ++i)18;     sum += A[i].x;19;20;   return sum;21; }22 23;CHECK-LABEL: @foo(24;CHECK-NOT: load <4 x i32>25;CHECK: ret26define i32 @foo(ptr nocapture %A, i32 %n) nounwind uwtable readonly ssp {27entry:28  %cmp4 = icmp sgt i32 %n, 029  br i1 %cmp4, label %for.body, label %for.end30 31for.body:                                         ; preds = %entry, %for.body32  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]33  %sum.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]34  %x = getelementptr inbounds %struct.coordinate, ptr %A, i64 %indvars.iv, i32 035  %0 = load i32, ptr %x, align 436  %add = add nsw i32 %0, %sum.0537  %indvars.iv.next = add i64 %indvars.iv, 138  %lftr.wideiv = trunc i64 %indvars.iv.next to i3239  %exitcond = icmp eq i32 %lftr.wideiv, %n40  br i1 %exitcond, label %for.end, label %for.body41 42for.end:                                          ; preds = %for.body, %entry43  %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.body ]44  ret i32 %sum.0.lcssa45}46 47%struct.lit = type { i32 }48 49; Verify that we still vectorize the access if the struct has the same size as50; the loaded element.51; struct lit {52;  int x;53; };54;55;56; int bar(struct lit *A, int n) {57;58;   int sum = 0;59;   for (int i = 0; i < n; ++i)60;     sum += A[i].x;61;62;   return sum;63; }64 65;CHECK-LABEL: @bar(66;CHECK: load <4 x i32>67;CHECK: ret68define i32 @bar(ptr nocapture %A, i32 %n) nounwind uwtable readonly ssp {69entry:70  %cmp4 = icmp sgt i32 %n, 071  br i1 %cmp4, label %for.body, label %for.end72 73for.body:                                         ; preds = %entry, %for.body74  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]75  %sum.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]76  %x = getelementptr inbounds %struct.lit, ptr %A, i64 %indvars.iv, i32 077  %0 = load i32, ptr %x, align 478  %add = add nsw i32 %0, %sum.0579  %indvars.iv.next = add i64 %indvars.iv, 180  %lftr.wideiv = trunc i64 %indvars.iv.next to i3281  %exitcond = icmp eq i32 %lftr.wideiv, %n82  br i1 %exitcond, label %for.end, label %for.body83 84for.end:                                          ; preds = %for.body, %entry85  %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.body ]86  ret i32 %sum.0.lcssa87}88