llvm.org GIT mirror llvm / 569cd21
Preserve loop metadata when folding branches to a common destination. Differential Revision: https://reviews.llvm.org/D27830 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289992 91177308-0d34-0410-b5e6-96231b3b80d8 Michael Kuperstein 2 years ago
2 changed file(s) with 33 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
27912791 PBI = New_PBI;
27922792 }
27932793
2794 // If BI was a loop latch, it may have had associated loop metadata.
2795 // We need to copy it to the new latch, that is, PBI.
2796 if (MDNode *LoopMD = BI->getMetadata(LLVMContext::MD_loop))
2797 PBI->setMetadata(LLVMContext::MD_loop, LoopMD);
2798
27942799 // TODO: If BB is reachable from all paths through PredBlock, then we
27952800 // could replace PBI's branch probabilities with BI's.
27962801
0 ; RUN: opt -loop-simplify -S < %s | FileCheck %s
11
2 ; CHECK-LABEL: @test1
23 define void @test1(i32 %n) {
34 entry:
45 br label %while.cond
3435 ; CHECK: if.else
3536 ; CHECK-NOT: br {{.*}}!llvm.loop{{.*}}
3637
38 ; CHECK-LABEL: @test2
39 ; CHECK: for.body:
40 ; CHECK: br i1 %{{.*}}, label %for.body, label %cleanup.loopexit, !llvm.loop !0
41 define void @test2(i32 %k) {
42 entry:
43 %cmp9 = icmp sgt i32 %k, 0
44 br i1 %cmp9, label %for.body.preheader, label %cleanup
45
46 for.body.preheader: ; preds = %entry
47 br label %for.body
48
49 for.cond: ; preds = %for.body
50 %cmp = icmp slt i32 %inc, %k
51 br i1 %cmp, label %for.body, label %cleanup.loopexit, !llvm.loop !0
52
53 for.body: ; preds = %for.body.preheader, %for.cond
54 %i.010 = phi i32 [ %inc, %for.cond ], [ 0, %for.body.preheader ]
55 %cmp3 = icmp sgt i32 %i.010, 3
56 %inc = add nsw i32 %i.010, 1
57 br i1 %cmp3, label %cleanup.loopexit, label %for.cond
58
59 cleanup.loopexit: ; preds = %for.body, %for.cond
60 br label %cleanup
61
62 cleanup: ; preds = %cleanup.loopexit, %entry
63 ret void
64 }
3765
3866 !0 = distinct !{!0, !1}
3967 !1 = !{!"llvm.loop.distribute.enable", i1 true}