161 lines · plain
1; Test branch weight metadata, estimated trip count metadata, and block2; frequencies after loop unrolling with an epilogue.3 4; ------------------------------------------------------------------------------5; Define substitutions.6;7; Check original loop body frequency.8; DEFINE: %{bf-fc} = opt %s -S -passes='print<block-freq>' 2>&1 | \9; DEFINE: FileCheck %s -check-prefixes10;11; Unroll loops and then check block frequency. The -implicit-check-not options12; make sure that no additional labels or @f calls show up.13; DEFINE: %{ur-bf} = opt %s -S -passes='loop-unroll,print<block-freq>' 2>&114; DEFINE: %{fc} = FileCheck %s \15; DEFINE: -implicit-check-not='{{^( *- )?[^ ;]*:}}' \16; DEFINE: -implicit-check-not='call void @f' -check-prefixes17 18; ------------------------------------------------------------------------------19; Check various interesting unroll count values relative to the original loop's20; estimated trip count of 11 (e.g., minimum and boundary values).21;22; RUN: %{bf-fc} ALL,ORIG23; RUN: %{ur-bf} -unroll-count=2 -unroll-runtime | %{fc} ALL,UR,UR224; RUN: %{ur-bf} -unroll-count=4 -unroll-runtime | %{fc} ALL,UR,UR425; RUN: %{ur-bf} -unroll-count=10 -unroll-runtime | %{fc} ALL,UR,UR1026; RUN: %{ur-bf} -unroll-count=11 -unroll-runtime | %{fc} ALL,UR,UR1127; RUN: %{ur-bf} -unroll-count=12 -unroll-runtime | %{fc} ALL,UR,UR1228 29; ------------------------------------------------------------------------------30; Check the iteration frequencies, which, when each is multiplied by the number31; of original loop bodies that execute within it, should sum to almost exactly32; the original loop body frequency.33;34; ALL-LABEL: block-frequency-info: test35;36; ORIG: - [[ENTRY:.*]]:37; ORIG: - [[DO_BODY:.*]]: float = 11.0,38; ORIG: - [[DO_END:.*]]:39;40; UR: - [[ENTRY:.*]]:41; UR: - [[ENTRY_NEW:.*]]:42; UR2: - [[DO_BODY:.*]]: float = 5.2381,43; UR4: - [[DO_BODY:.*]]: float = 2.3702,44; UR10: - [[DO_BODY:.*]]: float = 0.6902,45; UR11: - [[DO_BODY:.*]]: float = 0.59359,46; UR12: - [[DO_BODY:.*]]: float = 0.5144,47; UR: - [[DO_END_UNR_LCSSA:.*]]:48; UR: - [[DO_BODY_EPIL_PREHEADER:.*]]:49; UR2: - [[DO_BODY_EPIL:.*]]: float = 0.52381,50; UR4: - [[DO_BODY_EPIL:.*]]: float = 1.5193,51; UR10: - [[DO_BODY_EPIL:.*]]: float = 4.098,52; UR11: - [[DO_BODY_EPIL:.*]]: float = 4.4705,53; UR12: - [[DO_BODY_EPIL:.*]]: float = 4.8272,54; UR4: - [[DO_END_EPILOG_LCSSA:.*]]:55; UR10: - [[DO_END_EPILOG_LCSSA:.*]]:56; UR11: - [[DO_END_EPILOG_LCSSA:.*]]:57; UR12: - [[DO_END_EPILOG_LCSSA:.*]]:58; UR: - [[DO_END:.*]]:59 60; ------------------------------------------------------------------------------61; Check the CFGs, including the number of original loop bodies that appear62; within each unrolled iteration.63;64; UR-LABEL: define void @test(i32 %{{.*}}) {65; UR: [[ENTRY]]:66; UR: br i1 %{{.*}}, label %[[DO_BODY_EPIL_PREHEADER]], label %[[ENTRY_NEW]], !prof ![[#PROF_UR_GUARD:]]{{$}}67; UR: [[ENTRY_NEW]]:68; UR: br label %[[DO_BODY]]69; UR: [[DO_BODY]]:70; UR2-COUNT-2: call void @f71; UR4-COUNT-4: call void @f72; UR10-COUNT-10: call void @f73; UR11-COUNT-11: call void @f74; UR12-COUNT-12: call void @f75; UR: br i1 %{{.*}}, label %[[DO_END_UNR_LCSSA]], label %[[DO_BODY]], !prof ![[#PROF_UR_LATCH:]], !llvm.loop ![[#LOOP_UR_LATCH:]]{{$}}76; UR: [[DO_END_UNR_LCSSA]]:77; UR: br i1 %{{.*}}, label %[[DO_BODY_EPIL_PREHEADER]], label %[[DO_END:.*]], !prof ![[#PROF_RM_GUARD:]]{{$}}78; UR: [[DO_BODY_EPIL_PREHEADER]]:79; UR: br label %[[DO_BODY_EPIL]]80; UR: [[DO_BODY_EPIL]]:81; UR: call void @f82; UR4: br i1 %{{.*}}, label %[[DO_BODY_EPIL]], label %[[DO_END_EPILOG_LCSSA]], !prof ![[#PROF_RM_LATCH:]], !llvm.loop ![[#LOOP_RM_LATCH:]]{{$}}83; UR10: br i1 %{{.*}}, label %[[DO_BODY_EPIL]], label %[[DO_END_EPILOG_LCSSA]], !prof ![[#PROF_RM_LATCH:]], !llvm.loop ![[#LOOP_RM_LATCH:]]{{$}}84; UR11: br i1 %{{.*}}, label %[[DO_BODY_EPIL]], label %[[DO_END_EPILOG_LCSSA]], !prof ![[#PROF_RM_LATCH:]], !llvm.loop ![[#LOOP_RM_LATCH:]]{{$}}85; UR12: br i1 %{{.*}}, label %[[DO_BODY_EPIL]], label %[[DO_END_EPILOG_LCSSA]], !prof ![[#PROF_RM_LATCH:]], !llvm.loop ![[#LOOP_RM_LATCH:]]{{$}}86; UR4: [[DO_END_EPILOG_LCSSA]]:87; UR10: [[DO_END_EPILOG_LCSSA]]:88; UR11: [[DO_END_EPILOG_LCSSA]]:89; UR12: [[DO_END_EPILOG_LCSSA]]:90; UR: br label %[[DO_END]]91; UR: [[DO_END]]:92; UR: ret void93 94declare void @f(i32)95 96define void @test(i32 %n) {97entry:98 br label %do.body99 100do.body:101 %i = phi i32 [ 0, %entry ], [ %inc, %do.body ]102 %inc = add i32 %i, 1103 call void @f(i32 %i)104 %c = icmp sge i32 %inc, %n105 br i1 %c, label %do.end, label %do.body, !prof !0106 107do.end:108 ret void109}110 111!0 = !{!"branch_weights", i32 1, i32 10}112 113; ------------------------------------------------------------------------------114; Check branch weight metadata and estimated trip count metadata.115;116; UR2: ![[#PROF_UR_GUARD]] = !{!"branch_weights", i32 195225786, i32 1952257862}117; UR4: ![[#PROF_UR_GUARD]] = !{!"branch_weights", i32 534047398, i32 1613436250}118; UR10: ![[#PROF_UR_GUARD]] = !{!"branch_weights", i32 1236740947, i32 910742701}119; UR11: ![[#PROF_UR_GUARD]] = !{!"branch_weights", i32 1319535738, i32 827947910}120; UR12: ![[#PROF_UR_GUARD]] = !{!"branch_weights", i32 1394803730, i32 752679918}121;122; UR2: ![[#PROF_UR_LATCH]] = !{!"branch_weights", i32 372703773, i32 1774779875}123; UR4: ![[#PROF_UR_LATCH]] = !{!"branch_weights", i32 680723421, i32 1466760227}124; UR10: ![[#PROF_UR_LATCH]] = !{!"branch_weights", i32 1319535738, i32 827947910}125; UR11: ![[#PROF_UR_LATCH]] = !{!"branch_weights", i32 1394803730, i32 752679918}126; UR12: ![[#PROF_UR_LATCH]] = !{!"branch_weights", i32 1463229177, i32 684254471}127;128; UR2: ![[#LOOP_UR_LATCH]] = distinct !{![[#LOOP_UR_LATCH]], ![[#LOOP_UR_TC:]], ![[#DISABLE:]]}129; UR4: ![[#LOOP_UR_LATCH]] = distinct !{![[#LOOP_UR_LATCH]], ![[#LOOP_UR_TC:]], ![[#DISABLE:]]}130; UR10: ![[#LOOP_UR_LATCH]] = distinct !{![[#LOOP_UR_LATCH]], ![[#LOOP_UR_TC:]], ![[#DISABLE:]]}131; UR11: ![[#LOOP_UR_LATCH]] = distinct !{![[#LOOP_UR_LATCH]], ![[#LOOP_UR_TC:]], ![[#DISABLE:]]}132; UR12: ![[#LOOP_UR_LATCH]] = distinct !{![[#LOOP_UR_LATCH]], ![[#LOOP_UR_TC:]], ![[#DISABLE:]]}133;134; UR2: ![[#LOOP_UR_TC]] = !{!"llvm.loop.estimated_trip_count", i32 5}135; UR4: ![[#LOOP_UR_TC]] = !{!"llvm.loop.estimated_trip_count", i32 2}136; UR10: ![[#LOOP_UR_TC]] = !{!"llvm.loop.estimated_trip_count", i32 1}137; UR11: ![[#LOOP_UR_TC]] = !{!"llvm.loop.estimated_trip_count", i32 1}138; UR12: ![[#LOOP_UR_TC]] = !{!"llvm.loop.estimated_trip_count", i32 0}139; UR: ![[#DISABLE]] = !{!"llvm.loop.unroll.disable"}140;141; UR2: ![[#PROF_RM_GUARD]] = !{!"branch_weights", i32 1022611260, i32 1124872388}142; UR4: ![[#PROF_RM_GUARD]] = !{!"branch_weights", i32 1531603292, i32 615880356}143; UR10: ![[#PROF_RM_GUARD]] = !{!"branch_weights", i32 1829762672, i32 317720976}144; UR11: ![[#PROF_RM_GUARD]] = !{!"branch_weights", i32 1846907894, i32 300575754}145; UR12: ![[#PROF_RM_GUARD]] = !{!"branch_weights", i32 1860963812, i32 286519836}146;147; UR4: ![[#PROF_RM_LATCH]] = !{!"branch_weights", i32 1038564635, i32 1108919013}148; UR10: ![[#PROF_RM_LATCH]] = !{!"branch_weights", i32 1656332913, i32 491150735}149; UR11: ![[#PROF_RM_LATCH]] = !{!"branch_weights", i32 1693034047, i32 454449601}150; UR12: ![[#PROF_RM_LATCH]] = !{!"branch_weights", i32 1723419551, i32 424064097}151 152; UR4: ![[#LOOP_RM_LATCH]] = distinct !{![[#LOOP_RM_LATCH]], ![[#LOOP_RM_TC:]], ![[#DISABLE:]]}153; UR10: ![[#LOOP_RM_LATCH]] = distinct !{![[#LOOP_RM_LATCH]], ![[#LOOP_UR_TC:]], ![[#DISABLE:]]}154; UR11: ![[#LOOP_RM_LATCH]] = distinct !{![[#LOOP_RM_LATCH]], ![[#LOOP_RM_TC:]], ![[#DISABLE:]]}155; UR12: ![[#LOOP_RM_LATCH]] = distinct !{![[#LOOP_RM_LATCH]], ![[#LOOP_RM_TC:]], ![[#DISABLE:]]}156;157; UR4: ![[#LOOP_RM_TC]] = !{!"llvm.loop.estimated_trip_count", i32 3}158; For UR10, llvm.loop.estimated_trip_count is the same for both loops.159; UR11: ![[#LOOP_RM_TC]] = !{!"llvm.loop.estimated_trip_count", i32 0}160; UR12: ![[#LOOP_RM_TC]] = !{!"llvm.loop.estimated_trip_count", i32 11}161