brintos

brintos / llvm-project-archived public Read only

0
0
Text · 14.6 KiB · 939554f Raw
324 lines · plain
1; RUN: opt -S -passes=loop-rotate -verify-memoryssa < %s | FileCheck %s --implicit-check-not=dbg_value2 3declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone4declare void @llvm.dbg.value(metadata, metadata, metadata) nounwind readnone5 6 7; This function rotates the exit conditon into the entry block, moving the8; dbg.values with it. Check that they resolve through the PHIs to the arguments9; only in the entry block. In the loop block, the dbg.values shift down below10; the calls and resolve to them. Then even more dbg.values are inserted on the11; newly produced PHIs at the start.12 13define i32 @tak(i32 %x, i32 %y, i32 %z) nounwind ssp !dbg !0 {14; CHECK-LABEL: define i32 @tak(15; CHECK: entry16; CHECK-NEXT: #dbg_value(i32 %x17; CHECK-NEXT: #dbg_value(i32 %y18; CHECK-NEXT: #dbg_value(i32 %z19; CHECK: if.then.lr.ph:20; CHECK: if.then:21; CHECK-NEXT: %z.tr4 = phi22; CHECK-NEXT: %y.tr3 = phi23; CHECK-NEXT: %x.tr2 = phi24; CHECK-NEXT: #dbg_value(i32 %z.tr425; CHECK-NEXT: #dbg_value(i32 %y.tr326; CHECK-NEXT: #dbg_value(i32 %x.tr227; CHECK:      %call = tail call i32 @tak(i3228; CHECK:      %call9 = tail call i32 @tak(i3229; CHECK:      %call14 = tail call i32 @tak(i3230; CHECK-NEXT: #dbg_value(i32 %call31; CHECK-NEXT: #dbg_value(i32 %call932; CHECK-NEXT: #dbg_value(i32 %call1433entry:34  br label %tailrecurse35 36tailrecurse:                                      ; preds = %if.then, %entry37  %x.tr = phi i32 [ %x, %entry ], [ %call, %if.then ]38  %y.tr = phi i32 [ %y, %entry ], [ %call9, %if.then ]39  %z.tr = phi i32 [ %z, %entry ], [ %call14, %if.then ]40  tail call void @llvm.dbg.value(metadata i32 %x.tr, metadata !6, metadata !DIExpression()), !dbg !741  tail call void @llvm.dbg.value(metadata i32 %y.tr, metadata !8, metadata !DIExpression()), !dbg !942  tail call void @llvm.dbg.value(metadata i32 %z.tr, metadata !10, metadata !DIExpression()), !dbg !1143  %cmp = icmp slt i32 %y.tr, %x.tr, !dbg !1244  br i1 %cmp, label %if.then, label %if.end, !dbg !1245 46if.then:                                          ; preds = %tailrecurse47  %sub = sub nsw i32 %x.tr, 1, !dbg !1448  %call = tail call i32 @tak(i32 %sub, i32 %y.tr, i32 %z.tr), !dbg !1449  %sub6 = sub nsw i32 %y.tr, 1, !dbg !1450  %call9 = tail call i32 @tak(i32 %sub6, i32 %z.tr, i32 %x.tr), !dbg !1451  %sub11 = sub nsw i32 %z.tr, 1, !dbg !1452  %call14 = tail call i32 @tak(i32 %sub11, i32 %x.tr, i32 %y.tr), !dbg !1453  br label %tailrecurse54 55if.end:                                           ; preds = %tailrecurse56  br label %return, !dbg !1657 58return:                                           ; preds = %if.end59  ret i32 %z.tr, !dbg !1760}61 62; Repeat of the tak function, with only one DILocalVariable, checking that we63; don't insert duplicate debug intrinsics. The initial duplicates are preserved.64; FIXME: this test checks for the de-duplication behaviour that loop-rotate65; has today, however it might not be correct. In the if.then block the preserved66; dbg.value is for %x -- should not the _last_dbg.value, for %z, have been67; preserved?68define i32 @tak_dup(i32 %x, i32 %y, i32 %z) nounwind ssp !dbg !50 {69; CHECK-LABEL: define i32 @tak_dup(70; CHECK: entry71; CHECK-NEXT: #dbg_value(i32 %x72; CHECK-NEXT: #dbg_value(i32 %y73; CHECK-NEXT: #dbg_value(i32 %z74; CHECK: if.then.lr.ph:75; CHECK: if.then:76; CHECK-NEXT: %z.tr4 = phi77; CHECK-NEXT: %y.tr3 = phi78; CHECK-NEXT: %x.tr2 = phi79; CHECK-NEXT: #dbg_value(i32 %x.tr280; CHECK:      %call = tail call i32 @tak(i3281; CHECK:      %call9 = tail call i32 @tak(i3282; CHECK:      %call14 = tail call i32 @tak(i3283; CHECK-NEXT: #dbg_value(i32 %call1484entry:85  br label %tailrecurse86 87tailrecurse:                                      ; preds = %if.then, %entry88  %x.tr = phi i32 [ %x, %entry ], [ %call, %if.then ]89  %y.tr = phi i32 [ %y, %entry ], [ %call9, %if.then ]90  %z.tr = phi i32 [ %z, %entry ], [ %call14, %if.then ]91  tail call void @llvm.dbg.value(metadata i32 %x.tr, metadata !60, metadata !DIExpression()), !dbg !6192  tail call void @llvm.dbg.value(metadata i32 %y.tr, metadata !60, metadata !DIExpression()), !dbg !6193  tail call void @llvm.dbg.value(metadata i32 %z.tr, metadata !60, metadata !DIExpression()), !dbg !6194  %cmp = icmp slt i32 %y.tr, %x.tr, !dbg !6295  br i1 %cmp, label %if.then, label %if.end, !dbg !6296 97if.then:                                          ; preds = %tailrecurse98  %sub = sub nsw i32 %x.tr, 1, !dbg !6499  %call = tail call i32 @tak(i32 %sub, i32 %y.tr, i32 %z.tr), !dbg !64100  %sub6 = sub nsw i32 %y.tr, 1, !dbg !64101  %call9 = tail call i32 @tak(i32 %sub6, i32 %z.tr, i32 %x.tr), !dbg !64102  %sub11 = sub nsw i32 %z.tr, 1, !dbg !64103  %call14 = tail call i32 @tak(i32 %sub11, i32 %x.tr, i32 %y.tr), !dbg !64104  br label %tailrecurse105 106if.end:                                           ; preds = %tailrecurse107  br label %return, !dbg !66108 109return:                                           ; preds = %if.end110  ret i32 %z.tr, !dbg !67111}112 113; Check that the dbg.values move up to being immediately below the PHIs,114; using their Values. However once we exit the loop, the x and y values115; become irrelevant and poison, only z gets an LCSSA PHI to preserve it.116;117; Note that while the icmp is initially undominated by any dbg.value and thus118; shouldn't get a variable location, the first iteration is peeled off into the119; entry block. It's then safe to have it dominated by subsequent dbg.values as120; every path to the icmp is preceeded by a dbg.value.121;122; FIXME: could we choose to preserve more information about the loop, x and y123; might not be live out of the loop, but they might still be dominated by a124; describable Value.125 126define i32 @tak2(i32 %x, i32 %y, i32 %z) nounwind ssp !dbg !21 {127; CHECK-LABEL: define i32 @tak2(128; CHECK: if.then:129; CHECK-NEXT: %z.tr4 = phi i32130; CHECK-NEXT: %y.tr3 = phi i32131; CHECK-NEXT: %x.tr2 = phi i32132; CHECK-NEXT: #dbg_value(i32 %x.tr2133; CHECK-NEXT: #dbg_value(i32 %y.tr3134; CHECK-NEXT: #dbg_value(i32 %z.tr4135; CHECK:      tail call i32 @tak(i32136; CHECK:      tail call i32 @tak(i32137; CHECK:      tail call i32 @tak(i32138; CHECK: if.end:139; CHECK-NEXT: z.tr.lcssa = phi i32140; CHECK-NEXT: #dbg_value(i32 poison141; CHECK-NEXT: #dbg_value(i32 poison142; CHECK-NEXT: #dbg_value(i32 %z.tr.lcssa143entry:144  br label %tailrecurse145 146tailrecurse:                                      ; preds = %if.then, %entry147  %x.tr = phi i32 [ %x, %entry ], [ %call, %if.then ]148  %y.tr = phi i32 [ %y, %entry ], [ %call9, %if.then ]149  %z.tr = phi i32 [ %z, %entry ], [ %call14, %if.then ]150  %cmp = icmp slt i32 %y.tr, %x.tr, !dbg !22151  br i1 %cmp, label %if.then, label %if.end, !dbg !22152 153if.then:                                          ; preds = %tailrecurse154  tail call void @llvm.dbg.value(metadata i32 %x.tr, metadata !36, metadata !DIExpression()), !dbg !37155  tail call void @llvm.dbg.value(metadata i32 %y.tr, metadata !38, metadata !DIExpression()), !dbg !39156  tail call void @llvm.dbg.value(metadata i32 %z.tr, metadata !40, metadata !DIExpression()), !dbg !41157  %sub = sub nsw i32 %x.tr, 1, !dbg !24158  %call = tail call i32 @tak(i32 %sub, i32 %y.tr, i32 %z.tr), !dbg !24159  %sub6 = sub nsw i32 %y.tr, 1, !dbg !24160  %call9 = tail call i32 @tak(i32 %sub6, i32 %z.tr, i32 %x.tr), !dbg !24161  %sub11 = sub nsw i32 %z.tr, 1, !dbg !24162  %call14 = tail call i32 @tak(i32 %sub11, i32 %x.tr, i32 %y.tr), !dbg !24163  br label %tailrecurse164 165if.end:                                           ; preds = %tailrecurse166  tail call void @llvm.dbg.value(metadata i32 %x.tr, metadata !36, metadata !DIExpression()), !dbg !37167  tail call void @llvm.dbg.value(metadata i32 %y.tr, metadata !38, metadata !DIExpression()), !dbg !39168  tail call void @llvm.dbg.value(metadata i32 %z.tr, metadata !40, metadata !DIExpression()), !dbg !41169  br label %return, !dbg !26170 171return:                                           ; preds = %if.end172  ret i32 %z.tr, !dbg !27173}174 175@channelColumns = external global i64176@horzPlane = external global ptr, align 8177 178define void @FindFreeHorzSeg(i64 %startCol, i64 %row, ptr %rowStart) {179; Ensure that the loop increment basic block is rotated into the tail of the180; body, even though it contains a debug intrinsic call.181; CHECK-LABEL: define void @FindFreeHorzSeg(182; CHECK: %dec = add183; CHECK-NEXT: #dbg_value184; CHECK: %cmp = icmp185; CHECK: br i1 %cmp186; CHECK: phi i64 [ %{{[^,]*}}, %{{[^,]*}} ]187; CHECK-NEXT: br label %for.end188 189 190entry:191  br label %for.cond192 193for.cond:194  %i.0 = phi i64 [ %startCol, %entry ], [ %dec, %for.inc ]195  %cmp = icmp eq i64 %i.0, 0196  br i1 %cmp, label %for.end, label %for.body197 198for.body:199  %0 = load i64, ptr @channelColumns, align 8200  %mul = mul i64 %0, %row201  %add = add i64 %mul, %i.0202  %1 = load ptr, ptr @horzPlane, align 8203  %arrayidx = getelementptr inbounds i8, ptr %1, i64 %add204  %2 = load i8, ptr %arrayidx, align 1205  %tobool = icmp eq i8 %2, 0206  br i1 %tobool, label %for.inc, label %for.end207 208for.inc:209  %dec = add i64 %i.0, -1210  tail call void @llvm.dbg.value(metadata i64 %dec, metadata !DILocalVariable(scope: !0), metadata !DIExpression()), !dbg !DILocation(scope: !0)211  br label %for.cond212 213for.end:214  %add1 = add i64 %i.0, 1215  store i64 %add1, ptr %rowStart, align 8216  ret void217}218 219; Test that dbg.value intrinsincs adjacent to the `icmp slt i32 0, 0` get220; rotated as expected. The icmp is loop-invariant and so gets hoisted to the221; preheader via a different code path. This is more difficult for DbgVariableRecord222; debug-info records to handle, because they have to get detached and moved223; somewhere else during rotation.224define void @invariant_hoist() !dbg !70 {225; CHECK-LABEL: define void @invariant_hoist()226; CHECK: entry:227; CHECK-NEXT: br label %L0.preheader228; CHECK: L0.preheader:229; CHECK-NEXT: #dbg_value(i32 0,230; CHECK-NEXT: %cmp = icmp slt i32 0, 0,231; CHECK: L1.preheader:232; CHECK-NEXT: %spec.select3 = phi i32233; CHECK-NEXT: %k.02 = phi i32234; CHECK-NEXT: #dbg_value(i32 %k.02,235; CHECK: L0.latch:236; CHECK-NEXT: #dbg_value(i32 %spec.select3,237entry:238  br label %L0.preheader, !dbg !77239 240L0.preheader:241  br label %L0, !dbg !77242 243L0:244  %k.0 = phi i32 [ 0, %L0.preheader ], [ %spec.select, %L0.latch ]245  call void @llvm.dbg.value(metadata i32 %k.0, metadata !80, metadata !DIExpression()), !dbg !77246  %cmp = icmp slt i32 0, 0, !dbg !77247  %inc = zext i1 %cmp to i32, !dbg !77248  %spec.select = add nsw i32 %k.0, %inc, !dbg !77249  %tobool3.not = icmp eq i32 %spec.select, 0, !dbg !77250  br i1 %tobool3.not, label %L0.preheader, label %L1.preheader, !dbg !77251 252L1.preheader:253  %tobool8.not = icmp eq i32 %k.0, 0, !dbg !77254  br label %L1, !dbg !77255 256L1:257  br i1 %tobool8.not, label %L1.latch, label %L0.latch, !dbg !77258 259L1.latch:260  br i1 false, label %L1, label %L0.latch, !dbg !77261 262L0.latch:263  br label %L0, !dbg !77264}265 266!llvm.module.flags = !{!20}267!llvm.dbg.cu = !{!2}268 269!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)270!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")271!2 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 2.9 (trunk 125492)", isOptimized: true, emissionKind: FullDebug, file: !18)272!3 = !DISubroutineType(types: !4)273!4 = !{!5}274!5 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)275!6 = !DILocalVariable(name: "x", line: 32, arg: 1, scope: !0, file: !1, type: !5)276!7 = !DILocation(line: 32, column: 13, scope: !0)277!8 = !DILocalVariable(name: "y", line: 32, arg: 2, scope: !0, file: !1, type: !5)278!9 = !DILocation(line: 32, column: 20, scope: !0)279!10 = !DILocalVariable(name: "z", line: 32, arg: 3, scope: !0, file: !1, type: !5)280!11 = !DILocation(line: 32, column: 27, scope: !0)281!12 = !DILocation(line: 33, column: 3, scope: !13)282!13 = distinct !DILexicalBlock(line: 32, column: 30, file: !18, scope: !0)283!14 = !DILocation(line: 34, column: 5, scope: !15)284!15 = distinct !DILexicalBlock(line: 33, column: 14, file: !18, scope: !13)285!16 = !DILocation(line: 36, column: 3, scope: !13)286!17 = !DILocation(line: 37, column: 1, scope: !13)287!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")288!20 = !{i32 1, !"Debug Info Version", i32 3}289!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)290!22 = !DILocation(line: 33, column: 3, scope: !23)291!23 = distinct !DILexicalBlock(line: 32, column: 30, file: !18, scope: !21)292!24 = !DILocation(line: 34, column: 5, scope: !25)293!25 = distinct !DILexicalBlock(line: 33, column: 14, file: !18, scope: !23)294!26 = !DILocation(line: 36, column: 3, scope: !23)295!27 = !DILocation(line: 37, column: 1, scope: !23)296!36 = !DILocalVariable(name: "x", line: 32, arg: 1, scope: !21, file: !1, type: !5)297!37 = !DILocation(line: 32, column: 13, scope: !21)298!38 = !DILocalVariable(name: "y", line: 32, arg: 2, scope: !21, file: !1, type: !5)299!39 = !DILocation(line: 32, column: 20, scope: !21)300!40 = !DILocalVariable(name: "z", line: 32, arg: 3, scope: !21, file: !1, type: !5)301!41 = !DILocation(line: 32, column: 27, scope: !21)302!50 = distinct !DISubprogram(name: "tak_dup", line: 32, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !2, file: !18, scope: !1, type: !3)303!57 = !DILocation(line: 32, column: 13, scope: !50)304!59 = !DILocation(line: 32, column: 20, scope: !50)305!60 = !DILocalVariable(name: "z", line: 32, arg: 3, scope: !50, file: !1, type: !5)306!61 = !DILocation(line: 32, column: 27, scope: !50)307!62 = !DILocation(line: 33, column: 3, scope: !63)308!63 = distinct !DILexicalBlock(line: 32, column: 30, file: !18, scope: !50)309!64 = !DILocation(line: 34, column: 5, scope: !65)310!65 = distinct !DILexicalBlock(line: 33, column: 14, file: !18, scope: !63)311!66 = !DILocation(line: 36, column: 3, scope: !63)312!67 = !DILocation(line: 37, column: 1, scope: !63)313!70 = distinct !DISubprogram(name: "invariant_hoist", line: 32, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !2, file: !18, scope: !1, type: !3)314!77 = !DILocation(line: 32, column: 13, scope: !70)315!79 = !DILocation(line: 32, column: 20, scope: !70)316!80 = !DILocalVariable(name: "z", line: 32, arg: 3, scope: !70, file: !1, type: !5)317!81 = !DILocation(line: 32, column: 27, scope: !70)318!82 = !DILocation(line: 33, column: 3, scope: !83)319!83 = distinct !DILexicalBlock(line: 32, column: 30, file: !18, scope: !70)320!84 = !DILocation(line: 34, column: 5, scope: !85)321!85 = distinct !DILexicalBlock(line: 33, column: 14, file: !18, scope: !83)322!86 = !DILocation(line: 36, column: 3, scope: !83)323!87 = !DILocation(line: 37, column: 1, scope: !83)324