1 ; RUN: opt < %s -O2 -force-vector-unroll=2 -force-vector-width=4 -debug-only=loop-vectorize -stats -S 2>&1 | FileCheck %s 2 ; REQUIRES: asserts 3 4 ; Loop from "rotated" 5 ; CHECK: LV: Loop hints: force=enabled 6 ; Loop from "nonrotated" 7 ; CHECK: LV: Loop hints: force=enabled 8 ; No more loops in the module 9 ; CHECK-NOT: LV: Loop hints: force= 10 ; In total only 1 loop should be rotated. 11 ; CHECK: 1 loop-rotate 12 13 target 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" 14 target triple = "x86_64-unknown-linux-gnu" 15 16 ; See http://reviews.llvm.org/D3348 for details. 17 18 ; 19 ; Test #1 20 ; 21 ; Ensure that "llvm.loop.vectorize.enable" metadata was not lost prior to LoopVectorize pass. 22 ; In past LoopRotate was clearing that metadata. 23 ; 24 ; The source C code is: 25 ; void rotated(float *a, int size) 26 ; { 27 ; int t = 0; 28 ; #pragma omp simd 29 ; for (int i = 0; i < size; ++i) { 30 ; a[i] = a[i-5] * a[i+2]; 31 ; ++t; 32 ; } 33 ;} 34 35 define void @rotated(float* nocapture %a, i64 %size) { 36 entry: 37 %cmp1 = icmp sgt i64 %size, 0 38 br i1 %cmp1, label %for.header, label %for.end 39 40 for.header: 41 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ] 42 %cmp2 = icmp sgt i64 %indvars.iv, %size 43 br i1 %cmp2, label %for.end, label %for.body 44 45 for.body: 46 47 %0 = add nsw i64 %indvars.iv, -5 48 %arrayidx = getelementptr inbounds float* %a, i64 %0 49 %1 = load float* %arrayidx, align 4, !llvm.mem.parallel_loop_access !1 50 %2 = add nsw i64 %indvars.iv, 2 51 %arrayidx2 = getelementptr inbounds float* %a, i64 %2 52 %3 = load float* %arrayidx2, align 4, !llvm.mem.parallel_loop_access !1 53 %mul = fmul float %1, %3 54 %arrayidx4 = getelementptr inbounds float* %a, i64 %indvars.iv 55 store float %mul, float* %arrayidx4, align 4, !llvm.mem.parallel_loop_access !1 56 57 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 58 br label %for.header, !llvm.loop !1 59 60 for.end: 61 ret void 62 } 63 64 !1 = metadata !{metadata !1, metadata !2} 65 !2 = metadata !{metadata !"llvm.loop.vectorize.enable", i1 true} 66 67 ; 68 ; Test #2 69 ; 70 ; Ensure that "llvm.loop.vectorize.enable" metadata was not lost even 71 ; if loop was not rotated (see http://reviews.llvm.org/D3348#comment-4). 72 ; 73 define i32 @nonrotated(i32 %a) { 74 entry: 75 br label %loop_cond 76 loop_cond: 77 %indx = phi i32 [ 1, %entry ], [ %inc, %loop_inc ] 78 %cmp = icmp ne i32 %indx, %a 79 br i1 %cmp, label %return, label %loop_inc 80 loop_inc: 81 %inc = add i32 %indx, 1 82 br label %loop_cond, !llvm.loop !3 83 return: 84 ret i32 0 85 } 86 87 !3 = metadata !{metadata !3, metadata !4} 88 !4 = metadata !{metadata !"llvm.loop.vectorize.enable", i1 true} 89