1; This test verifies that the loop vectorizer will NOT produce a tail 2; loop with the optimize for size or the minimize size attributes. 3; REQUIRES: asserts 4; RUN: opt < %s -loop-vectorize -S | FileCheck %s 5; RUN: opt < %s -loop-vectorize -pgso -S | FileCheck %s -check-prefix=PGSO 6; RUN: opt < %s -loop-vectorize -pgso=false -S | FileCheck %s -check-prefix=NPGSO 7 8target datalayout = "E-m:e-p:32:32-i64:32-f64:32:64-a:0:32-n32-S128" 9 10@tab = common global [32 x i8] zeroinitializer, align 1 11 12define i32 @foo_optsize() #0 { 13; CHECK-LABEL: @foo_optsize( 14; CHECK-NOT: <2 x i8> 15; CHECK-NOT: <4 x i8> 16 17entry: 18 br label %for.body 19 20for.body: ; preds = %for.body, %entry 21 %i.08 = phi i32 [ 0, %entry ], [ %inc, %for.body ] 22 %arrayidx = getelementptr inbounds [32 x i8], [32 x i8]* @tab, i32 0, i32 %i.08 23 %0 = load i8, i8* %arrayidx, align 1 24 %cmp1 = icmp eq i8 %0, 0 25 %. = select i1 %cmp1, i8 2, i8 1 26 store i8 %., i8* %arrayidx, align 1 27 %inc = add nsw i32 %i.08, 1 28 %exitcond = icmp eq i32 %i.08, 202 29 br i1 %exitcond, label %for.end, label %for.body 30 31for.end: ; preds = %for.body 32 ret i32 0 33} 34 35attributes #0 = { optsize } 36 37define i32 @foo_minsize() #1 { 38; CHECK-LABEL: @foo_minsize( 39; CHECK-NOT: <2 x i8> 40; CHECK-NOT: <4 x i8> 41; CHECK-LABEL: @foo_pgso( 42 43entry: 44 br label %for.body 45 46for.body: ; preds = %for.body, %entry 47 %i.08 = phi i32 [ 0, %entry ], [ %inc, %for.body ] 48 %arrayidx = getelementptr inbounds [32 x i8], [32 x i8]* @tab, i32 0, i32 %i.08 49 %0 = load i8, i8* %arrayidx, align 1 50 %cmp1 = icmp eq i8 %0, 0 51 %. = select i1 %cmp1, i8 2, i8 1 52 store i8 %., i8* %arrayidx, align 1 53 %inc = add nsw i32 %i.08, 1 54 %exitcond = icmp eq i32 %i.08, 202 55 br i1 %exitcond, label %for.end, label %for.body 56 57for.end: ; preds = %for.body 58 ret i32 0 59} 60 61attributes #1 = { minsize } 62 63define i32 @foo_pgso() !prof !14 { 64; PGSO-LABEL: @foo_pgso( 65; PGSO-NOT: <{{[0-9]+}} x i8> 66; NPGSO-LABEL: @foo_pgso( 67; NPGSO: <{{[0-9]+}} x i8> 68 69entry: 70 br label %for.body 71 72for.body: ; preds = %for.body, %entry 73 %i.08 = phi i32 [ 0, %entry ], [ %inc, %for.body ] 74 %arrayidx = getelementptr inbounds [32 x i8], [32 x i8]* @tab, i32 0, i32 %i.08 75 %0 = load i8, i8* %arrayidx, align 1 76 %cmp1 = icmp eq i8 %0, 0 77 %. = select i1 %cmp1, i8 2, i8 1 78 store i8 %., i8* %arrayidx, align 1 79 %inc = add nsw i32 %i.08, 1 80 %exitcond = icmp eq i32 %i.08, 202 81 br i1 %exitcond, label %for.end, label %for.body 82 83for.end: ; preds = %for.body 84 ret i32 0 85} 86 87; PR43371: don't run into an assert due to emitting SCEV runtime checks 88; with OptForSize. 89; 90@cm_array = external global [2592 x i16], align 1 91 92define void @pr43371() optsize { 93; 94; CHECK-LABEL: @pr43371 95; CHECK-NOT: vector.scevcheck 96; 97; We do not want to generate SCEV predicates when optimising for size, because 98; that will lead to extra code generation such as the SCEV overflow runtime 99; checks. Not generating SCEV predicates can still result in vectorisation as 100; the non-consecutive loads/stores can be scalarized: 101; 102; CHECK: vector.body: 103; CHECK: store i16 0, i16* %{{.*}}, align 1 104; CHECK: store i16 0, i16* %{{.*}}, align 1 105; CHECK: br i1 {{.*}}, label %vector.body 106; 107entry: 108 br label %for.body29 109 110for.cond.cleanup28: 111 unreachable 112 113for.body29: 114 %i24.0170 = phi i16 [ 0, %entry], [ %inc37, %for.body29] 115 %add33 = add i16 undef, %i24.0170 116 %idxprom34 = zext i16 %add33 to i32 117 %arrayidx35 = getelementptr [2592 x i16], [2592 x i16] * @cm_array, i32 0, i32 %idxprom34 118 store i16 0, i16 * %arrayidx35, align 1 119 %inc37 = add i16 %i24.0170, 1 120 %cmp26 = icmp ult i16 %inc37, 756 121 br i1 %cmp26, label %for.body29, label %for.cond.cleanup28 122} 123 124; PR45526: don't vectorize with fold-tail if first-order-recurrence is live-out. 125; 126define i32 @pr45526() optsize { 127; 128; CHECK-LABEL: @pr45526 129; CHECK-NEXT: entry: 130; CHECK-NEXT: br label %loop 131; CHECK-EMPTY: 132; CHECK-NEXT: loop: 133; CHECK-NEXT: %piv = phi i32 [ 0, %entry ], [ %pivPlus1, %loop ] 134; CHECK-NEXT: %for = phi i32 [ 5, %entry ], [ %pivPlus1, %loop ] 135; CHECK-NEXT: %pivPlus1 = add nuw nsw i32 %piv, 1 136; CHECK-NEXT: %cond = icmp ult i32 %piv, 510 137; CHECK-NEXT: br i1 %cond, label %loop, label %exit 138; CHECK-EMPTY: 139; CHECK-NEXT: exit: 140; CHECK-NEXT: %for.lcssa = phi i32 [ %for, %loop ] 141; CHECK-NEXT: ret i32 %for.lcssa 142; 143entry: 144 br label %loop 145 146loop: 147 %piv = phi i32 [ 0, %entry ], [ %pivPlus1, %loop ] 148 %for = phi i32 [ 5, %entry ], [ %pivPlus1, %loop ] 149 %pivPlus1 = add nuw nsw i32 %piv, 1 150 %cond = icmp ult i32 %piv, 510 151 br i1 %cond, label %loop, label %exit 152 153exit: 154 ret i32 %for 155} 156 157!llvm.module.flags = !{!0} 158!0 = !{i32 1, !"ProfileSummary", !1} 159!1 = !{!2, !3, !4, !5, !6, !7, !8, !9} 160!2 = !{!"ProfileFormat", !"InstrProf"} 161!3 = !{!"TotalCount", i64 10000} 162!4 = !{!"MaxCount", i64 10} 163!5 = !{!"MaxInternalCount", i64 1} 164!6 = !{!"MaxFunctionCount", i64 1000} 165!7 = !{!"NumCounts", i64 3} 166!8 = !{!"NumFunctions", i64 3} 167!9 = !{!"DetailedSummary", !10} 168!10 = !{!11, !12, !13} 169!11 = !{i32 10000, i64 100, i32 1} 170!12 = !{i32 999000, i64 100, i32 1} 171!13 = !{i32 999999, i64 1, i32 2} 172!14 = !{!"function_entry_count", i64 0} 173