brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.9 KiB · 28202bb Raw
150 lines · plain
1; RUN: opt < %s -passes=loop-unroll -S | FileCheck %s2;3; Verify that the unrolling pass removes existing unroll count metadata4; and adds a disable unrolling node after unrolling is complete.5 6target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"7target triple = "x86_64-unknown-linux-gnu"8 9; #pragma clang loop  vectorize(enable) unroll_count(4) vectorize_width(8)10;11; Unroll count metadata should be replaced with unroll(disable).  Vectorize12; metadata should be untouched.13;14; CHECK-LABEL: @unroll_count_4(15; CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_1:.*]]16define void @unroll_count_4(ptr nocapture %a) {17entry:18  br label %for.body19 20for.body:                                         ; preds = %for.body, %entry21  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]22  %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv23  %0 = load i32, ptr %arrayidx, align 424  %inc = add nsw i32 %0, 125  store i32 %inc, ptr %arrayidx, align 426  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 127  %exitcond = icmp eq i64 %indvars.iv.next, 6428  br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !129 30for.end:                                          ; preds = %for.body31  ret void32}33!1 = !{!1, !2, !3, !4}34!2 = !{!"llvm.loop.vectorize.enable", i1 true}35!3 = !{!"llvm.loop.unroll.count", i32 4}36!4 = !{!"llvm.loop.vectorize.width", i32 8}37 38; #pragma clang loop unroll(full)39;40; An unroll disable metadata node is only added for the unroll count case.41; In this case, the loop has a full unroll metadata but can't be fully unrolled42; because the trip count is dynamic.  The full unroll metadata should remain43; after unrolling.44;45; CHECK-LABEL: @unroll_full(46; CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_2:.*]]47define void @unroll_full(ptr nocapture %a, i32 %b) {48entry:49  %cmp3 = icmp sgt i32 %b, 050  br i1 %cmp3, label %for.body, label %for.end, !llvm.loop !551 52for.body:                                         ; preds = %entry, %for.body53  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]54  %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv55  %0 = load i32, ptr %arrayidx, align 456  %inc = add nsw i32 %0, 157  store i32 %inc, ptr %arrayidx, align 458  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 159  %lftr.wideiv = trunc i64 %indvars.iv.next to i3260  %exitcond = icmp eq i32 %lftr.wideiv, %b61  br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !562 63for.end:                                          ; preds = %for.body, %entry64  ret void65}66!5 = !{!5, !6}67!6 = !{!"llvm.loop.unroll.full"}68 69; #pragma clang loop unroll(disable)70;71; Unroll metadata should not change.72;73; CHECK-LABEL: @unroll_disable(74; CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_3:.*]]75define void @unroll_disable(ptr nocapture %a) {76entry:77  br label %for.body78 79for.body:                                         ; preds = %for.body, %entry80  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]81  %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv82  %0 = load i32, ptr %arrayidx, align 483  %inc = add nsw i32 %0, 184  store i32 %inc, ptr %arrayidx, align 485  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 186  %exitcond = icmp eq i64 %indvars.iv.next, 6487  br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !788 89for.end:                                          ; preds = %for.body90  ret void91}92!7 = !{!7, !8}93!8 = !{!"llvm.loop.unroll.disable"}94 95; This function contains two loops which share the same llvm.loop metadata node96; with an llvm.loop.unroll.count 2 hint.  Both loops should be unrolled.  This97; verifies that adding disable metadata to a loop after unrolling doesn't affect98; other loops which previously shared the same llvm.loop metadata.99;100; CHECK-LABEL: @shared_metadata(101; CHECK: store i32102; CHECK: store i32103; CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_4:.*]]104; CHECK: store i32105; CHECK: store i32106; CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[LOOP_5:.*]]107define void @shared_metadata(ptr nocapture %List) #0 {108entry:109  br label %for.body3110 111for.body3:                                        ; preds = %for.body3, %entry112  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body3 ]113  %arrayidx = getelementptr inbounds i32, ptr %List, i64 %indvars.iv114  %0 = load i32, ptr %arrayidx, align 4115  %add4 = add nsw i32 %0, 10116  store i32 %add4, ptr %arrayidx, align 4117  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1118  %exitcond = icmp eq i64 %indvars.iv.next, 4119  br i1 %exitcond, label %for.body3.1.preheader, label %for.body3, !llvm.loop !9120 121for.body3.1.preheader:                            ; preds = %for.body3122  br label %for.body3.1123 124for.body3.1:                                      ; preds = %for.body3.1.preheader, %for.body3.1125  %indvars.iv.1 = phi i64 [ %1, %for.body3.1 ], [ 0, %for.body3.1.preheader ]126  %1 = add nsw i64 %indvars.iv.1, 1127  %arrayidx.1 = getelementptr inbounds i32, ptr %List, i64 %1128  %2 = load i32, ptr %arrayidx.1, align 4129  %add4.1 = add nsw i32 %2, 10130  store i32 %add4.1, ptr %arrayidx.1, align 4131  %exitcond.1 = icmp eq i64 %1, 4132  br i1 %exitcond.1, label %for.inc5.1, label %for.body3.1, !llvm.loop !9133 134for.inc5.1:                                       ; preds = %for.body3.1135  ret void136}137!9 = !{!9, !10}138!10 = !{!"llvm.loop.unroll.count", i32 2}139 140 141; CHECK: ![[LOOP_1]] = distinct !{![[LOOP_1]], ![[VEC_ENABLE:.*]], ![[WIDTH_8:.*]], ![[UNROLL_DISABLE:.*]]}142; CHECK: ![[VEC_ENABLE]] = !{!"llvm.loop.vectorize.enable", i1 true}143; CHECK: ![[WIDTH_8]] = !{!"llvm.loop.vectorize.width", i32 8}144; CHECK: ![[UNROLL_DISABLE]] = !{!"llvm.loop.unroll.disable"}145; CHECK: ![[LOOP_2]] = distinct !{![[LOOP_2]], ![[UNROLL_FULL:.*]]}146; CHECK: ![[UNROLL_FULL]] = !{!"llvm.loop.unroll.full"}147; CHECK: ![[LOOP_3]] = distinct !{![[LOOP_3]], ![[UNROLL_DISABLE:.*]]}148; CHECK: ![[LOOP_4]] = distinct !{![[LOOP_4]], ![[UNROLL_DISABLE:.*]]}149; CHECK: ![[LOOP_5]] = distinct !{![[LOOP_5]], ![[UNROLL_DISABLE:.*]]}150