88 lines · plain
1; RUN: opt < %s -passes=loop-vectorize -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx -debug-only=loop-vectorize -stats -S 2>&1 | FileCheck %s2; REQUIRES: asserts3 4; CHECK: LV: Loop hints: force=enabled5; CHECK: LV: Loop hints: force=?6; No more loops in the module7; CHECK-NOT: LV: Loop hints: force=8; CHECK: 2 loop-vectorize - Number of loops analyzed for vectorization9; CHECK: 1 loop-vectorize - Number of loops vectorized10 11target 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"12target triple = "x86_64-apple-macosx10.8.0"13 14;15; The source code for the test:16;17; #include <math.h>18; void foo(ptr restrict A, ptr restrict B)19; {20; for (int i = 0; i < 1000; i+=2) A[i] = sinf(B[i]);21; }22;23 24;25; This loop will be vectorized, although the scalar cost is lower than any of vector costs, but vectorization is explicitly forced in metadata.26;27 28define void @vectorized(ptr noalias nocapture %A, ptr noalias nocapture %B) {29entry:30 br label %for.body31 32for.body:33 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]34 %arrayidx = getelementptr inbounds float, ptr %B, i64 %indvars.iv35 %0 = load float, ptr %arrayidx, align 4, !llvm.access.group !1136 %call = tail call float @llvm.sin.f32(float %0)37 %arrayidx2 = getelementptr inbounds float, ptr %A, i64 %indvars.iv38 store float %call, ptr %arrayidx2, align 4, !llvm.access.group !1139 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 240 %lftr.wideiv = trunc i64 %indvars.iv.next to i3241 %exitcond = icmp eq i32 %lftr.wideiv, 100042 br i1 %exitcond, label %for.end.loopexit, label %for.body, !llvm.loop !143 44for.end.loopexit:45 br label %for.end46 47for.end:48 ret void49}50 51!1 = !{!1, !2, !{!"llvm.loop.parallel_accesses", !11}}52!2 = !{!"llvm.loop.vectorize.enable", i1 true}53!11 = distinct !{}54 55;56; This method will not be vectorized, as scalar cost is lower than any of vector costs.57;58 59define void @not_vectorized(ptr noalias nocapture %A, ptr noalias nocapture %B) {60entry:61 br label %for.body62 63for.body:64 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]65 %arrayidx = getelementptr inbounds float, ptr %B, i64 %indvars.iv66 %0 = load float, ptr %arrayidx, align 4, !llvm.access.group !1367 %call = tail call float @llvm.sin.f32(float %0)68 %arrayidx2 = getelementptr inbounds float, ptr %A, i64 %indvars.iv69 store float %call, ptr %arrayidx2, align 4, !llvm.access.group !1370 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 271 %lftr.wideiv = trunc i64 %indvars.iv.next to i3272 %exitcond = icmp eq i32 %lftr.wideiv, 100073 br i1 %exitcond, label %for.end.loopexit, label %for.body, !llvm.loop !374 75for.end.loopexit:76 br label %for.end77 78for.end:79 ret void80}81 82declare float @llvm.sin.f32(float) nounwind readnone83 84; Dummy metadata85!3 = !{!3, !{!"llvm.loop.parallel_accesses", !13}}86!13 = distinct !{}87 88