1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2 2 3; RUN: opt < %s -passes='require<profile-summary>,function(loop-mssa(simple-loop-unswitch<nontrivial>))' -S | FileCheck %s 4 5;; Check that non-trivial loop unswitching is not applied to a cold loop in a 6;; cold loop nest. 7 8;; IR was generated from the following loop nest, profiled when called 9;; with M=0 and N=0. 10;; void hotFunction(bool cond, int M, int N, int * A, int *B, int *C) { 11;; for (unsigned j = 0; j < M; j++) 12;; for (unsigned i=0; i < N; i++) { 13;; A[i] = B[i] + C[i]; 14;; if (cond) do_something(); 15;; } 16;; } 17 18define void @_Z11hotFunctionbiiPiS_S_(i1 %cond, i32 %M, i32 %N, ptr %A, ptr %B, ptr %C) !prof !36 { 19; CHECK-LABEL: define void @_Z11hotFunctionbiiPiS_S_ 20; CHECK-SAME: (i1 [[COND:%.*]], i32 [[M:%.*]], i32 [[N:%.*]], ptr [[A:%.*]], ptr [[B:%.*]], ptr [[C:%.*]]) !prof [[PROF16:![0-9]+]] { 21; CHECK-NEXT: entry: 22; CHECK-NEXT: [[CMP19_NOT:%.*]] = icmp eq i32 [[M]], 0 23; CHECK-NEXT: br i1 [[CMP19_NOT]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_COND1_PREHEADER_LR_PH:%.*]], !prof [[PROF17:![0-9]+]] 24; CHECK: for.cond1.preheader.lr.ph: 25; CHECK-NEXT: [[CMP217_NOT:%.*]] = icmp eq i32 [[N]], 0 26; CHECK-NEXT: br label [[FOR_COND1_PREHEADER:%.*]] 27; CHECK: for.cond1.preheader: 28; CHECK-NEXT: [[J_020:%.*]] = phi i32 [ 0, [[FOR_COND1_PREHEADER_LR_PH]] ], [ [[INC10:%.*]], [[FOR_COND_CLEANUP3:%.*]] ] 29; CHECK-NEXT: br i1 [[CMP217_NOT]], label [[FOR_COND_CLEANUP3]], label [[FOR_BODY4_PREHEADER:%.*]] 30; CHECK: for.body4.preheader: 31; CHECK-NEXT: br label [[FOR_BODY4:%.*]] 32; CHECK: for.cond.cleanup.loopexit: 33; CHECK-NEXT: br label [[FOR_COND_CLEANUP]] 34; CHECK: for.cond.cleanup: 35; CHECK-NEXT: ret void 36; CHECK: for.cond.cleanup3.loopexit: 37; CHECK-NEXT: br label [[FOR_COND_CLEANUP3]] 38; CHECK: for.cond.cleanup3: 39; CHECK-NEXT: [[INC10]] = add nuw i32 [[J_020]], 1 40; CHECK-NEXT: [[EXITCOND22_NOT:%.*]] = icmp eq i32 [[INC10]], [[M]] 41; CHECK-NEXT: br i1 [[EXITCOND22_NOT]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[FOR_COND1_PREHEADER]], !prof [[PROF17]] 42; CHECK: for.body4: 43; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_INC:%.*]] ], [ 0, [[FOR_BODY4_PREHEADER]] ] 44; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[B]], i64 [[INDVARS_IV]] 45; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[ARRAYIDX]], align 4 46; CHECK-NEXT: [[ARRAYIDX6:%.*]] = getelementptr inbounds i32, ptr [[C]], i64 [[INDVARS_IV]] 47; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[ARRAYIDX6]], align 4 48; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP1]], [[TMP0]] 49; CHECK-NEXT: [[ARRAYIDX8:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[INDVARS_IV]] 50; CHECK-NEXT: store i32 [[ADD]], ptr [[ARRAYIDX8]], align 4 51; CHECK-NEXT: br i1 [[COND]], label [[IF_THEN:%.*]], label [[FOR_INC]] 52; CHECK: if.then: 53; CHECK-NEXT: tail call void @_Z12do_somethingv() 54; CHECK-NEXT: br label [[FOR_INC]] 55; CHECK: for.inc: 56; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[N]] to i64 57; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1 58; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[WIDE_TRIP_COUNT]] 59; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP3_LOOPEXIT:%.*]], label [[FOR_BODY4]] 60; 61entry: 62 %cmp19.not = icmp eq i32 %M, 0 63 br i1 %cmp19.not, label %for.cond.cleanup, label %for.cond1.preheader.lr.ph, !prof !37 64 65for.cond1.preheader.lr.ph: 66 %cmp217.not = icmp eq i32 %N, 0 67 br label %for.cond1.preheader 68 69for.cond1.preheader: 70 %j.020 = phi i32 [ 0, %for.cond1.preheader.lr.ph ], [ %inc10, %for.cond.cleanup3 ] 71 br i1 %cmp217.not, label %for.cond.cleanup3, label %for.body4 72 73for.cond.cleanup: 74 ret void 75 76for.cond.cleanup3: 77 %inc10 = add nuw i32 %j.020, 1 78 %exitcond22.not = icmp eq i32 %inc10, %M 79 br i1 %exitcond22.not, label %for.cond.cleanup, label %for.cond1.preheader, !prof !37 80 81for.body4: 82 %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %for.cond1.preheader ] 83 %arrayidx = getelementptr inbounds i32, ptr %B, i64 %indvars.iv 84 %0 = load i32, ptr %arrayidx, align 4 85 %arrayidx6 = getelementptr inbounds i32, ptr %C, i64 %indvars.iv 86 %1 = load i32, ptr %arrayidx6, align 4 87 %add = add nsw i32 %1, %0 88 %arrayidx8 = getelementptr inbounds i32, ptr %A, i64 %indvars.iv 89 store i32 %add, ptr %arrayidx8, align 4 90 br i1 %cond, label %if.then, label %for.inc 91 92if.then: 93 tail call void @_Z12do_somethingv() 94 br label %for.inc 95 96for.inc: 97 %wide.trip.count = zext i32 %N to i64 98 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 99 %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count 100 br i1 %exitcond.not, label %for.cond.cleanup3, label %for.body4 101} 102 103declare void @_Z12do_somethingv() 104 105!llvm.module.flags = !{!6} 106 107!6 = !{i32 1, !"ProfileSummary", !7} 108!7 = !{!8, !9, !10, !11, !12, !13, !14, !15, !16, !17} 109!8 = !{!"ProfileFormat", !"InstrProf"} 110!9 = !{!"TotalCount", i64 1002} 111!10 = !{!"MaxCount", i64 1000} 112!11 = !{!"MaxInternalCount", i64 1000} 113!12 = !{!"MaxFunctionCount", i64 1} 114!13 = !{!"NumCounts", i64 6} 115!14 = !{!"NumFunctions", i64 3} 116!15 = !{!"IsPartialProfile", i64 0} 117!16 = !{!"PartialProfileRatio", double 0.000000e+00} 118!17 = !{!"DetailedSummary", !18} 119!18 = !{!19, !31, !34} 120!19 = !{i32 10000, i64 1000, i32 1} 121!31 = !{i32 999000, i64 1000, i32 1} 122!34 = !{i32 999999, i64 1, i32 3} 123!36 = !{!"function_entry_count", i64 1} 124!37 = !{!"branch_weights", i32 1, i32 0} 125