brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.8 KiB · 1fe802f Raw
123 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 52; RUN: opt -passes='loop-vectorize' -force-vector-width=4 -S < %s | FileCheck %s3 4; Test if the follow-up metadata for loops works fine. The original code is5; something like below. In this case, the unrolling metadata from the original6; loop should be applied to the vector loop as well.7;8; void f(float *a, float x) {9;   #pragma clang loop vectorize(enable) unroll_count(8)10;   for (int i = 0; i < 1024; i++) {11;     a[i] *= x;12;   }13; }14;15define void @scalar_loop_dead(ptr noundef captures(none) %a, float noundef %x) {16; CHECK-LABEL: define void @scalar_loop_dead(17; CHECK-SAME: ptr noundef captures(none) [[A:%.*]], float noundef [[X:%.*]]) {18; CHECK-NEXT:  [[ENTRY:.*:]]19; CHECK-NEXT:    br label %[[VECTOR_PH:.*]]20; CHECK:       [[VECTOR_PH]]:21; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x float> poison, float [[X]], i64 022; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x float> [[BROADCAST_SPLATINSERT]], <4 x float> poison, <4 x i32> zeroinitializer23; CHECK-NEXT:    br label %[[VECTOR_BODY:.*]]24; CHECK:       [[VECTOR_BODY]]:25; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]26; CHECK-NEXT:    [[TMP0:%.*]] = getelementptr inbounds nuw float, ptr [[A]], i64 [[INDEX]]27; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP0]], align 428; CHECK-NEXT:    [[TMP1:%.*]] = fmul <4 x float> [[BROADCAST_SPLAT]], [[WIDE_LOAD]]29; CHECK-NEXT:    store <4 x float> [[TMP1]], ptr [[TMP0]], align 430; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 431; CHECK-NEXT:    [[TMP2:%.*]] = icmp eq i64 [[INDEX_NEXT]], 102432; CHECK-NEXT:    br i1 [[TMP2]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]33; CHECK:       [[MIDDLE_BLOCK]]:34; CHECK-NEXT:    br label %[[EXIT:.*]]35; CHECK:       [[EXIT]]:36; CHECK-NEXT:    ret void37;38entry:39  br label %loop40 41loop:42  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]43  %arrayidx = getelementptr inbounds nuw float, ptr %a, i64 %iv44  %load = load float, ptr %arrayidx, align 445  %mul = fmul float %x, %load46  store float %mul, ptr %arrayidx, align 447  %iv.next = add nuw nsw i64 %iv, 148  %comp = icmp eq i64 %iv.next, 102449  br i1 %comp, label %exit, label %loop, !llvm.loop !050 51exit:52  ret void53}54 55define void @scalar_loop_live(ptr noundef captures(none) %a, float noundef %x, i64 %n) {56; CHECK-LABEL: define void @scalar_loop_live(57; CHECK-SAME: ptr noundef captures(none) [[A:%.*]], float noundef [[X:%.*]], i64 [[N:%.*]]) {58; CHECK-NEXT:  [[ENTRY:.*]]:59; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], 460; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]61; CHECK:       [[VECTOR_PH]]:62; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[N]], 463; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 [[N]], [[N_MOD_VF]]64; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x float> poison, float [[X]], i64 065; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x float> [[BROADCAST_SPLATINSERT]], <4 x float> poison, <4 x i32> zeroinitializer66; CHECK-NEXT:    br label %[[VECTOR_BODY:.*]]67; CHECK:       [[VECTOR_BODY]]:68; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]69; CHECK-NEXT:    [[TMP0:%.*]] = getelementptr inbounds nuw float, ptr [[A]], i64 [[INDEX]]70; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP0]], align 471; CHECK-NEXT:    [[TMP1:%.*]] = fmul <4 x float> [[BROADCAST_SPLAT]], [[WIDE_LOAD]]72; CHECK-NEXT:    store <4 x float> [[TMP1]], ptr [[TMP0]], align 473; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 474; CHECK-NEXT:    [[TMP2:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]75; CHECK-NEXT:    br i1 [[TMP2]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]76; CHECK:       [[MIDDLE_BLOCK]]:77; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]]78; CHECK-NEXT:    br i1 [[CMP_N]], label %[[EXIT:.*]], label %[[SCALAR_PH]]79; CHECK:       [[SCALAR_PH]]:80; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]81; CHECK-NEXT:    br label %[[LOOP:.*]]82; CHECK:       [[LOOP]]:83; CHECK-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]84; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds nuw float, ptr [[A]], i64 [[IV]]85; CHECK-NEXT:    [[LOAD:%.*]] = load float, ptr [[ARRAYIDX]], align 486; CHECK-NEXT:    [[MUL:%.*]] = fmul float [[X]], [[LOAD]]87; CHECK-NEXT:    store float [[MUL]], ptr [[ARRAYIDX]], align 488; CHECK-NEXT:    [[IV_NEXT]] = add nuw nsw i64 [[IV]], 189; CHECK-NEXT:    [[COMP:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]90; CHECK-NEXT:    br i1 [[COMP]], label %[[EXIT]], label %[[LOOP]], !llvm.loop [[LOOP5:![0-9]+]]91; CHECK:       [[EXIT]]:92; CHECK-NEXT:    ret void93;94entry:95  br label %loop96 97loop:98  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]99  %arrayidx = getelementptr inbounds nuw float, ptr %a, i64 %iv100  %load = load float, ptr %arrayidx, align 4101  %mul = fmul float %x, %load102  store float %mul, ptr %arrayidx, align 4103  %iv.next = add nuw nsw i64 %iv, 1104  %comp = icmp eq i64 %iv.next, %n105  br i1 %comp, label %exit, label %loop, !llvm.loop !0106 107exit:108  ret void109}110!0 = distinct !{!0, !1, !2}111!1 = !{!"llvm.loop.vectorize.enable", i1 true}112!2 = !{!"llvm.loop.vectorize.followup_all", !3, !4}113!3 = !{!"llvm.loop.isvectorized"}114!4 = !{!"llvm.loop.unroll.count", i32 8}115;.116; CHECK: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]], [[META3:![0-9]+]]}117; CHECK: [[META1]] = !{!"llvm.loop.isvectorized"}118; CHECK: [[META2]] = !{!"llvm.loop.unroll.count", i32 8}119; CHECK: [[META3]] = !{!"llvm.loop.unroll.runtime.disable"}120; CHECK: [[LOOP4]] = distinct !{[[LOOP4]], [[META1]], [[META2]], [[META3]]}121; CHECK: [[LOOP5]] = distinct !{[[LOOP5]], [[META1]], [[META2]]}122;.123