1; RUN: opt -S -passes=loop-vectorize -pass-remarks-analysis=loop-vectorize -pass-remarks-with-hotness < %s 2>&1 | FileCheck %s 2 3; 1 void cold(char *A, char *B, char *C, char *D, char *E, int N) { 4; 2 for(int i = 0; i < N; i++) { 5; 3 A[i + 1] = A[i] + B[i]; 6; 4 C[i] = Dptr E[i]; 7; 5 } 8; 6 } 9; 7 10; 8 void hot(char *A, char *B, char *C, char *D, char *E, int N) { 11; 9 for(int i = 0; i < N; i++) { 12; 10 A[i + 1] = A[i] + B[i]; 13; 11 C[i] = Dptr E[i]; 14; 12 } 15; 13 } 16; 14 17; 15 void unknown(char *A, char *B, char *C, char *D, char *E, int N) { 18; 16 for(int i = 0; i < N; i++) { 19; 17 A[i + 1] = A[i] + B[i]; 20; 18 C[i] = Dptr E[i]; 21; 19 } 22; 20 } 23 24; CHECK: remark: /tmp/s.c:3:14: loop not vectorized: unsafe dependent memory operations in loop. Use #pragma clang loop distribute(enable) to allow loop distribution to attempt to isolate the offending operations into a separate loop 25; CHECK-NEXT: Backward loop carried data dependence. Memory location is the same as accessed at /tmp/s.c:3:16 (hotness: 300) 26; CHECK: remark: /tmp/s.c:10:14: loop not vectorized: unsafe dependent memory operations in loop. Use #pragma clang loop distribute(enable) to allow loop distribution to attempt to isolate the offending operations into a separate loop 27; CHECK-NEXT: Backward loop carried data dependence. Memory location is the same as accessed at /tmp/s.c:10:16 (hotness: 5000) 28; CHECK: remark: /tmp/s.c:17:14: loop not vectorized: unsafe dependent memory operations in loop. Use #pragma clang loop distribute(enable) to allow loop distribution to attempt to isolate the offending operations into a separate loop 29; CHECK-NEXT: Backward loop carried data dependence. Memory location is the same as accessed at /tmp/s.c:17:16{{$}} 30 31; ModuleID = '/tmp/s.c' 32source_filename = "/tmp/s.c" 33target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 34 35; Function Attrs: norecurse nounwind ssp uwtable 36define void @cold(ptr nocapture %A, ptr nocapture readonly %B, ptr nocapture %C, ptr nocapture readonly %D, ptr nocapture readonly %E, i32 %N) local_unnamed_addr #0 !dbg !7 !prof !56 { 37entry: 38 %cmp28 = icmp sgt i32 %N, 0, !dbg !9 39 br i1 %cmp28, label %ph, label %for.cond.cleanup, !dbg !10, !prof !58 40 41ph: 42 br label %for.body 43 44for.body: 45 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %ph ] 46 %arrayidx = getelementptr inbounds i8, ptr %A, i64 %indvars.iv, !dbg !12 47 %0 = load i8, ptr %arrayidx, align 1, !dbg !12, !tbaa !13 48 %arrayidx2 = getelementptr inbounds i8, ptr %B, i64 %indvars.iv, !dbg !16 49 %1 = load i8, ptr %arrayidx2, align 1, !dbg !16, !tbaa !13 50 %add = add i8 %1, %0, !dbg !17 51 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !10 52 %arrayidx7 = getelementptr inbounds i8, ptr %A, i64 %indvars.iv.next, !dbg !18 53 store i8 %add, ptr %arrayidx7, align 1, !dbg !19, !tbaa !13 54 %arrayidx9 = getelementptr inbounds i8, ptr %D, i64 %indvars.iv, !dbg !20 55 %2 = load i8, ptr %arrayidx9, align 1, !dbg !20, !tbaa !13 56 %arrayidx12 = getelementptr inbounds i8, ptr %E, i64 %indvars.iv, !dbg !21 57 %3 = load i8, ptr %arrayidx12, align 1, !dbg !21, !tbaa !13 58 %mul = mul i8 %3, %2, !dbg !22 59 %arrayidx16 = getelementptr inbounds i8, ptr %C, i64 %indvars.iv, !dbg !23 60 store i8 %mul, ptr %arrayidx16, align 1, !dbg !24, !tbaa !13 61 %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !10 62 %exitcond = icmp eq i32 %lftr.wideiv, %N, !dbg !10 63 br i1 %exitcond, label %for.cond.cleanup, label %for.body, !dbg !10, !llvm.loop !25, !prof !59 64 65for.cond.cleanup: 66 ret void, !dbg !11 67} 68 69; Function Attrs: norecurse nounwind ssp uwtable 70define void @hot(ptr nocapture %A, ptr nocapture readonly %B, ptr nocapture %C, ptr nocapture readonly %D, ptr nocapture readonly %E, i32 %N) local_unnamed_addr #0 !dbg !26 !prof !57 { 71entry: 72 %cmp28 = icmp sgt i32 %N, 0, !dbg !27 73 br i1 %cmp28, label %ph, label %for.cond.cleanup, !dbg !28, !prof !58 74 75ph: 76 br label %for.body 77 78for.body: 79 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %ph ] 80 %arrayidx = getelementptr inbounds i8, ptr %A, i64 %indvars.iv, !dbg !30 81 %0 = load i8, ptr %arrayidx, align 1, !dbg !30, !tbaa !13 82 %arrayidx2 = getelementptr inbounds i8, ptr %B, i64 %indvars.iv, !dbg !31 83 %1 = load i8, ptr %arrayidx2, align 1, !dbg !31, !tbaa !13 84 %add = add i8 %1, %0, !dbg !32 85 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !28 86 %arrayidx7 = getelementptr inbounds i8, ptr %A, i64 %indvars.iv.next, !dbg !33 87 store i8 %add, ptr %arrayidx7, align 1, !dbg !34, !tbaa !13 88 %arrayidx9 = getelementptr inbounds i8, ptr %D, i64 %indvars.iv, !dbg !35 89 %2 = load i8, ptr %arrayidx9, align 1, !dbg !35, !tbaa !13 90 %arrayidx12 = getelementptr inbounds i8, ptr %E, i64 %indvars.iv, !dbg !36 91 %3 = load i8, ptr %arrayidx12, align 1, !dbg !36, !tbaa !13 92 %mul = mul i8 %3, %2, !dbg !37 93 %arrayidx16 = getelementptr inbounds i8, ptr %C, i64 %indvars.iv, !dbg !38 94 store i8 %mul, ptr %arrayidx16, align 1, !dbg !39, !tbaa !13 95 %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !28 96 %exitcond = icmp eq i32 %lftr.wideiv, %N, !dbg !28 97 br i1 %exitcond, label %for.cond.cleanup, label %for.body, !dbg !28, !llvm.loop !40, !prof !59 98 99for.cond.cleanup: 100 ret void, !dbg !29 101} 102 103; Function Attrs: norecurse nounwind ssp uwtable 104define void @unknown(ptr nocapture %A, ptr nocapture readonly %B, ptr nocapture %C, ptr nocapture readonly %D, ptr nocapture readonly %E, i32 %N) local_unnamed_addr #0 !dbg !41 { 105entry: 106 %cmp28 = icmp sgt i32 %N, 0, !dbg !42 107 br i1 %cmp28, label %ph, label %for.cond.cleanup, !dbg !43 108 109ph: 110 br label %for.body 111 112for.body: 113 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %ph ] 114 %arrayidx = getelementptr inbounds i8, ptr %A, i64 %indvars.iv, !dbg !45 115 %0 = load i8, ptr %arrayidx, align 1, !dbg !45, !tbaa !13 116 %arrayidx2 = getelementptr inbounds i8, ptr %B, i64 %indvars.iv, !dbg !46 117 %1 = load i8, ptr %arrayidx2, align 1, !dbg !46, !tbaa !13 118 %add = add i8 %1, %0, !dbg !47 119 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !43 120 %arrayidx7 = getelementptr inbounds i8, ptr %A, i64 %indvars.iv.next, !dbg !48 121 store i8 %add, ptr %arrayidx7, align 1, !dbg !49, !tbaa !13 122 %arrayidx9 = getelementptr inbounds i8, ptr %D, i64 %indvars.iv, !dbg !50 123 %2 = load i8, ptr %arrayidx9, align 1, !dbg !50, !tbaa !13 124 %arrayidx12 = getelementptr inbounds i8, ptr %E, i64 %indvars.iv, !dbg !51 125 %3 = load i8, ptr %arrayidx12, align 1, !dbg !51, !tbaa !13 126 %mul = mul i8 %3, %2, !dbg !52 127 %arrayidx16 = getelementptr inbounds i8, ptr %C, i64 %indvars.iv, !dbg !53 128 store i8 %mul, ptr %arrayidx16, align 1, !dbg !54, !tbaa !13 129 %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !43 130 %exitcond = icmp eq i32 %lftr.wideiv, %N, !dbg !43 131 br i1 %exitcond, label %for.cond.cleanup, label %for.body, !dbg !43, !llvm.loop !55 132 133for.cond.cleanup: 134 ret void, !dbg !44 135} 136 137attributes #0 = { norecurse nounwind ssp 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" "stack-protector-buffer-size"="8" "target-cpu"="core2" "target-features"="+cx16,+fxsr,+mmx,+sse,+sse2,+sse3,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } 138 139!llvm.dbg.cu = !{!0} 140!llvm.module.flags = !{!3, !4, !5} 141!llvm.ident = !{!6} 142 143!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 (trunk 273572) (llvm/trunk 273585)", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2) 144!1 = !DIFile(filename: "/tmp/s.c", directory: "/tmp") 145!2 = !{} 146!3 = !{i32 2, !"Dwarf Version", i32 2} 147!4 = !{i32 2, !"Debug Info Version", i32 3} 148!5 = !{i32 1, !"PIC Level", i32 2} 149!6 = !{!"clang version 3.9.0 (trunk 273572) (llvm/trunk 273585)"} 150!7 = distinct !DISubprogram(name: "cold", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !2) 151!8 = !DISubroutineType(types: !2) 152!9 = !DILocation(line: 2, column: 20, scope: !7) 153!10 = !DILocation(line: 2, column: 3, scope: !7) 154!11 = !DILocation(line: 6, column: 1, scope: !7) 155!12 = !DILocation(line: 3, column: 16, scope: !7) 156!13 = !{!14, !14, i64 0} 157!14 = !{!"omnipotent char", !15, i64 0} 158!15 = !{!"Simple C/C++ TBAA"} 159!16 = !DILocation(line: 3, column: 23, scope: !7) 160!17 = !DILocation(line: 3, column: 21, scope: !7) 161!18 = !DILocation(line: 3, column: 5, scope: !7) 162!19 = !DILocation(line: 3, column: 14, scope: !7) 163!20 = !DILocation(line: 4, column: 12, scope: !7) 164!21 = !DILocation(line: 4, column: 19, scope: !7) 165!22 = !DILocation(line: 4, column: 17, scope: !7) 166!23 = !DILocation(line: 4, column: 5, scope: !7) 167!24 = !DILocation(line: 4, column: 10, scope: !7) 168!25 = distinct !{!25, !10} 169!26 = distinct !DISubprogram(name: "hot", scope: !1, file: !1, line: 8, type: !8, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !2) 170!27 = !DILocation(line: 9, column: 20, scope: !26) 171!28 = !DILocation(line: 9, column: 3, scope: !26) 172!29 = !DILocation(line: 13, column: 1, scope: !26) 173!30 = !DILocation(line: 10, column: 16, scope: !26) 174!31 = !DILocation(line: 10, column: 23, scope: !26) 175!32 = !DILocation(line: 10, column: 21, scope: !26) 176!33 = !DILocation(line: 10, column: 5, scope: !26) 177!34 = !DILocation(line: 10, column: 14, scope: !26) 178!35 = !DILocation(line: 11, column: 12, scope: !26) 179!36 = !DILocation(line: 11, column: 19, scope: !26) 180!37 = !DILocation(line: 11, column: 17, scope: !26) 181!38 = !DILocation(line: 11, column: 5, scope: !26) 182!39 = !DILocation(line: 11, column: 10, scope: !26) 183!40 = distinct !{!40, !28} 184!41 = distinct !DISubprogram(name: "unknown", scope: !1, file: !1, line: 15, type: !8, isLocal: false, isDefinition: true, scopeLine: 15, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !2) 185!42 = !DILocation(line: 16, column: 20, scope: !41) 186!43 = !DILocation(line: 16, column: 3, scope: !41) 187!44 = !DILocation(line: 20, column: 1, scope: !41) 188!45 = !DILocation(line: 17, column: 16, scope: !41) 189!46 = !DILocation(line: 17, column: 23, scope: !41) 190!47 = !DILocation(line: 17, column: 21, scope: !41) 191!48 = !DILocation(line: 17, column: 5, scope: !41) 192!49 = !DILocation(line: 17, column: 14, scope: !41) 193!50 = !DILocation(line: 18, column: 12, scope: !41) 194!51 = !DILocation(line: 18, column: 19, scope: !41) 195!52 = !DILocation(line: 18, column: 17, scope: !41) 196!53 = !DILocation(line: 18, column: 5, scope: !41) 197!54 = !DILocation(line: 18, column: 10, scope: !41) 198!55 = distinct !{!55, !43} 199!56 = !{!"function_entry_count", i64 3} 200!57 = !{!"function_entry_count", i64 50} 201!58 = !{!"branch_weights", i32 10000, i32 1} 202!59 = !{!"branch_weights", i32 1, i32 99} 203