| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6 | |
| ; RUN: opt -passes=loop-vectorize -force-vector-width=4 -enable-vplan-native-path -S %s | FileCheck %s | |
| ; Vectorize explict marked outer loop using vplan native path. Inner loop | |
| ; contains simple double add reduction. IR is compiled and modified by hand | |
| ; from following C code: | |
| ; void inner_loop_reduction(const ptr restrict in_a, const ptr restrict in_b, ptr restrict out) | |
| ; { | |
| ; #pragma clang loop vectorize(enable) | |
| ; for (int i = 0; i < 1000; ++i) { | |
| ; double a = in_a[i]; | |
| ; double b = in_b[i]; | |
| ; for (int j = 0; j < 10000; ++j) { | |
| ; a = a + b; | |
| ; } | |
| ; out[i] = a; | |
| ; } | |
| ; } | |
| define void @inner_loop_reduction(ptr noalias nocapture readonly %a.in, ptr noalias nocapture readonly %b.in, ptr noalias nocapture %c.out) { | |
| ; CHECK-LABEL: define void @inner_loop_reduction( | |
| ; CHECK-SAME: ptr noalias readonly captures(none) [[A_IN:%.*]], ptr noalias readonly captures(none) [[B_IN:%.*]], ptr noalias captures(none) [[C_OUT:%.*]]) { | |
| ; CHECK-NEXT: [[ENTRY:.*:]] | |
| ; CHECK-NEXT: br label %[[VECTOR_PH:.*]] | |
| ; CHECK: [[VECTOR_PH]]: | |
| ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]] | |
| ; CHECK: [[VECTOR_BODY]]: | |
| ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_LATCH:.*]] ] | |
| ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds double, ptr [[A_IN]], i64 [[INDEX]] | |
| ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x double>, ptr [[TMP1]], align 8 | |
| ; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds double, ptr [[B_IN]], i64 [[INDEX]] | |
| ; CHECK-NEXT: [[WIDE_LOAD1:%.*]] = load <4 x double>, ptr [[TMP3]], align 8 | |
| ; CHECK-NEXT: br label %[[FOR2_HEADER2:.*]] | |
| ; CHECK: [[FOR2_HEADER2]]: | |
| ; CHECK-NEXT: [[INDVAR23:%.*]] = phi <4 x i32> [ zeroinitializer, %[[VECTOR_BODY]] ], [ [[TMP5:%.*]], %[[FOR2_HEADER2]] ] | |
| ; CHECK-NEXT: [[A_REDUCTION4:%.*]] = phi <4 x double> [ [[WIDE_LOAD]], %[[VECTOR_BODY]] ], [ [[TMP4:%.*]], %[[FOR2_HEADER2]] ] | |
| ; CHECK-NEXT: [[TMP4]] = fadd <4 x double> [[WIDE_LOAD1]], [[A_REDUCTION4]] | |
| ; CHECK-NEXT: [[TMP5]] = add nuw nsw <4 x i32> [[INDVAR23]], splat (i32 1) | |
| ; CHECK-NEXT: [[TMP6:%.*]] = icmp eq <4 x i32> [[TMP5]], splat (i32 10000) | |
| ; CHECK-NEXT: [[TMP7:%.*]] = extractelement <4 x i1> [[TMP6]], i64 0 | |
| ; CHECK-NEXT: br i1 [[TMP7]], label %[[VECTOR_LATCH]], label %[[FOR2_HEADER2]] | |
| ; CHECK: [[VECTOR_LATCH]]: | |
| ; CHECK-NEXT: [[TMP9:%.*]] = getelementptr inbounds double, ptr [[C_OUT]], i64 [[INDEX]] | |
| ; CHECK-NEXT: store <4 x double> [[TMP4]], ptr [[TMP9]], align 8 | |
| ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4 | |
| ; CHECK-NEXT: [[TMP10:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1000 | |
| ; CHECK-NEXT: br i1 [[TMP10]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]] | |
| ; CHECK: [[MIDDLE_BLOCK]]: | |
| ; CHECK-NEXT: br label %[[EXIT:.*]] | |
| ; CHECK: [[EXIT]]: | |
| ; CHECK-NEXT: ret void | |
| ; | |
| entry: | |
| br label %for1.header | |
| for1.header: | |
| %indvar1 = phi i64 [ 0, %entry ], [ %indvar11, %for1.latch ] | |
| %a.ptr = getelementptr inbounds double, ptr %a.in, i64 %indvar1 | |
| %a = load double, ptr %a.ptr, align 8 | |
| %b.ptr = getelementptr inbounds double, ptr %b.in, i64 %indvar1 | |
| %b = load double, ptr %b.ptr, align 8 | |
| br label %for2.header | |
| for2.header: | |
| %indvar2 = phi i32 [ 0, %for1.header ], [ %indvar21, %for2.header ] | |
| %a.reduction = phi double [ %a, %for1.header ], [ %a.reduction1, %for2.header ] | |
| %a.reduction1 = fadd double %b, %a.reduction | |
| %indvar21 = add nuw nsw i32 %indvar2, 1 | |
| %for2.cond = icmp eq i32 %indvar21, 10000 | |
| br i1 %for2.cond, label %for1.latch, label %for2.header | |
| for1.latch: | |
| %c.ptr = getelementptr inbounds double, ptr %c.out, i64 %indvar1 | |
| store double %a.reduction1, ptr %c.ptr, align 8 | |
| %indvar11 = add nuw nsw i64 %indvar1, 1 | |
| %for1.cond = icmp eq i64 %indvar11, 1000 | |
| br i1 %for1.cond, label %exit, label %for1.header, !llvm.loop !0 | |
| exit: | |
| ret void | |
| } | |
| !0 = distinct !{!0, !1} | |
| !1 = !{!"llvm.loop.vectorize.enable"} | |
| ;. | |
| ; CHECK: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]]} | |
| ; CHECK: [[META1]] = !{!"llvm.loop.isvectorized", i32 1} | |
| ; CHECK: [[META2]] = !{!"llvm.loop.unroll.runtime.disable"} | |
| ;. |