1; RUN: opt -S -loop-rotate < %s | FileCheck %s 2; RUN: opt -S -loop-rotate -enable-mssa-loop-dependency=true -verify-memoryssa < %s | FileCheck %s 3 4declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone 5declare void @llvm.dbg.value(metadata, metadata, metadata) nounwind readnone 6 7define i32 @tak(i32 %x, i32 %y, i32 %z) nounwind ssp !dbg !0 { 8; CHECK-LABEL: define i32 @tak( 9; CHECK: entry 10; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %x 11; CHECK: tail call void @llvm.dbg.value(metadata i32 %call 12 13entry: 14 br label %tailrecurse 15 16tailrecurse: ; preds = %if.then, %entry 17 %x.tr = phi i32 [ %x, %entry ], [ %call, %if.then ] 18 %y.tr = phi i32 [ %y, %entry ], [ %call9, %if.then ] 19 %z.tr = phi i32 [ %z, %entry ], [ %call14, %if.then ] 20 tail call void @llvm.dbg.value(metadata i32 %x.tr, metadata !6, metadata !DIExpression()), !dbg !7 21 tail call void @llvm.dbg.value(metadata i32 %y.tr, metadata !8, metadata !DIExpression()), !dbg !9 22 tail call void @llvm.dbg.value(metadata i32 %z.tr, metadata !10, metadata !DIExpression()), !dbg !11 23 %cmp = icmp slt i32 %y.tr, %x.tr, !dbg !12 24 br i1 %cmp, label %if.then, label %if.end, !dbg !12 25 26if.then: ; preds = %tailrecurse 27 %sub = sub nsw i32 %x.tr, 1, !dbg !14 28 %call = tail call i32 @tak(i32 %sub, i32 %y.tr, i32 %z.tr), !dbg !14 29 %sub6 = sub nsw i32 %y.tr, 1, !dbg !14 30 %call9 = tail call i32 @tak(i32 %sub6, i32 %z.tr, i32 %x.tr), !dbg !14 31 %sub11 = sub nsw i32 %z.tr, 1, !dbg !14 32 %call14 = tail call i32 @tak(i32 %sub11, i32 %x.tr, i32 %y.tr), !dbg !14 33 br label %tailrecurse 34 35if.end: ; preds = %tailrecurse 36 br label %return, !dbg !16 37 38return: ; preds = %if.end 39 ret i32 %z.tr, !dbg !17 40} 41 42define i32 @tak2(i32 %x, i32 %y, i32 %z) nounwind ssp !dbg !21 { 43; CHECK-LABEL: define i32 @tak2( 44; CHECK: entry 45; CHECK: tail call void @llvm.dbg.value(metadata i32 %x.tr 46; CHECK: tail call void @llvm.dbg.value(metadata i32 undef 47 48entry: 49 br label %tailrecurse 50 51tailrecurse: ; preds = %if.then, %entry 52 %x.tr = phi i32 [ %x, %entry ], [ %call, %if.then ] 53 %y.tr = phi i32 [ %y, %entry ], [ %call9, %if.then ] 54 %z.tr = phi i32 [ %z, %entry ], [ %call14, %if.then ] 55 %cmp = icmp slt i32 %y.tr, %x.tr, !dbg !22 56 br i1 %cmp, label %if.then, label %if.end, !dbg !22 57 58if.then: ; preds = %tailrecurse 59 tail call void @llvm.dbg.value(metadata i32 %x.tr, metadata !36, metadata !DIExpression()), !dbg !37 60 tail call void @llvm.dbg.value(metadata i32 %y.tr, metadata !38, metadata !DIExpression()), !dbg !39 61 tail call void @llvm.dbg.value(metadata i32 %z.tr, metadata !40, metadata !DIExpression()), !dbg !41 62 %sub = sub nsw i32 %x.tr, 1, !dbg !24 63 %call = tail call i32 @tak(i32 %sub, i32 %y.tr, i32 %z.tr), !dbg !24 64 %sub6 = sub nsw i32 %y.tr, 1, !dbg !24 65 %call9 = tail call i32 @tak(i32 %sub6, i32 %z.tr, i32 %x.tr), !dbg !24 66 %sub11 = sub nsw i32 %z.tr, 1, !dbg !24 67 %call14 = tail call i32 @tak(i32 %sub11, i32 %x.tr, i32 %y.tr), !dbg !24 68 br label %tailrecurse 69 70if.end: ; preds = %tailrecurse 71 tail call void @llvm.dbg.value(metadata i32 %x.tr, metadata !36, metadata !DIExpression()), !dbg !37 72 tail call void @llvm.dbg.value(metadata i32 %y.tr, metadata !38, metadata !DIExpression()), !dbg !39 73 tail call void @llvm.dbg.value(metadata i32 %z.tr, metadata !40, metadata !DIExpression()), !dbg !41 74 br label %return, !dbg !26 75 76return: ; preds = %if.end 77 ret i32 %z.tr, !dbg !27 78} 79 80@channelColumns = external global i64 81@horzPlane = external global i8*, align 8 82 83define void @FindFreeHorzSeg(i64 %startCol, i64 %row, i64* %rowStart) { 84; Ensure that the loop increment basic block is rotated into the tail of the 85; body, even though it contains a debug intrinsic call. 86; CHECK-LABEL: define void @FindFreeHorzSeg( 87; CHECK: %dec = add 88; CHECK-NEXT: tail call void @llvm.dbg.value 89; CHECK: %cmp = icmp 90; CHECK: br i1 %cmp 91; CHECK: phi i64 [ %{{[^,]*}}, %{{[^,]*}} ] 92; CHECK-NEXT: br label %for.end 93 94 95entry: 96 br label %for.cond 97 98for.cond: 99 %i.0 = phi i64 [ %startCol, %entry ], [ %dec, %for.inc ] 100 %cmp = icmp eq i64 %i.0, 0 101 br i1 %cmp, label %for.end, label %for.body 102 103for.body: 104 %0 = load i64, i64* @channelColumns, align 8 105 %mul = mul i64 %0, %row 106 %add = add i64 %mul, %i.0 107 %1 = load i8*, i8** @horzPlane, align 8 108 %arrayidx = getelementptr inbounds i8, i8* %1, i64 %add 109 %2 = load i8, i8* %arrayidx, align 1 110 %tobool = icmp eq i8 %2, 0 111 br i1 %tobool, label %for.inc, label %for.end 112 113for.inc: 114 %dec = add i64 %i.0, -1 115 tail call void @llvm.dbg.value(metadata i64 %dec, metadata !DILocalVariable(scope: !0), metadata !DIExpression()), !dbg !DILocation(scope: !0) 116 br label %for.cond 117 118for.end: 119 %add1 = add i64 %i.0, 1 120 store i64 %add1, i64* %rowStart, align 8 121 ret void 122} 123 124!llvm.module.flags = !{!20} 125!llvm.dbg.cu = !{!2} 126 127!0 = distinct !DISubprogram(name: "tak", line: 32, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !2, file: !18, scope: !1, type: !3) 128!1 = !DIFile(filename: "/Volumes/Lalgate/cj/llvm/projects/llvm-test/SingleSource/Benchmarks/BenchmarkGame/recursive.c", directory: "/Volumes/Lalgate/cj/D/projects/llvm-test/SingleSource/Benchmarks/BenchmarkGame") 129!2 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 2.9 (trunk 125492)", isOptimized: true, emissionKind: FullDebug, file: !18) 130!3 = !DISubroutineType(types: !4) 131!4 = !{!5} 132!5 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 133!6 = !DILocalVariable(name: "x", line: 32, arg: 1, scope: !0, file: !1, type: !5) 134!7 = !DILocation(line: 32, column: 13, scope: !0) 135!8 = !DILocalVariable(name: "y", line: 32, arg: 2, scope: !0, file: !1, type: !5) 136!9 = !DILocation(line: 32, column: 20, scope: !0) 137!10 = !DILocalVariable(name: "z", line: 32, arg: 3, scope: !0, file: !1, type: !5) 138!11 = !DILocation(line: 32, column: 27, scope: !0) 139!12 = !DILocation(line: 33, column: 3, scope: !13) 140!13 = distinct !DILexicalBlock(line: 32, column: 30, file: !18, scope: !0) 141!14 = !DILocation(line: 34, column: 5, scope: !15) 142!15 = distinct !DILexicalBlock(line: 33, column: 14, file: !18, scope: !13) 143!16 = !DILocation(line: 36, column: 3, scope: !13) 144!17 = !DILocation(line: 37, column: 1, scope: !13) 145!18 = !DIFile(filename: "/Volumes/Lalgate/cj/llvm/projects/llvm-test/SingleSource/Benchmarks/BenchmarkGame/recursive.c", directory: "/Volumes/Lalgate/cj/D/projects/llvm-test/SingleSource/Benchmarks/BenchmarkGame") 146!20 = !{i32 1, !"Debug Info Version", i32 3} 147!21 = distinct !DISubprogram(name: "tak", line: 32, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !2, file: !18, scope: !1, type: !3) 148!22 = !DILocation(line: 33, column: 3, scope: !23) 149!23 = distinct !DILexicalBlock(line: 32, column: 30, file: !18, scope: !21) 150!24 = !DILocation(line: 34, column: 5, scope: !25) 151!25 = distinct !DILexicalBlock(line: 33, column: 14, file: !18, scope: !23) 152!26 = !DILocation(line: 36, column: 3, scope: !23) 153!27 = !DILocation(line: 37, column: 1, scope: !23) 154!36 = !DILocalVariable(name: "x", line: 32, arg: 1, scope: !21, file: !1, type: !5) 155!37 = !DILocation(line: 32, column: 13, scope: !21) 156!38 = !DILocalVariable(name: "y", line: 32, arg: 2, scope: !21, file: !1, type: !5) 157!39 = !DILocation(line: 32, column: 20, scope: !21) 158!40 = !DILocalVariable(name: "z", line: 32, arg: 3, scope: !21, file: !1, type: !5) 159!41 = !DILocation(line: 32, column: 27, scope: !21) 160