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