Skip to content

Commit 41bf6cb

Browse files
Mel-Chenjoaosaffran
authored and
joaosaffran
committed
[LV][EVL] Enhance fixed-order recurrence tests for tail folding with EVL. NFC (llvm#126507)
Test that we do not vectorize the loop using folding by EVL, when a fixed-order recurrence has external users. TODO: Support external users by extractelement the EVL-th lane.
1 parent 17fec8a commit 41bf6cb

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

llvm/test/Transforms/LoopVectorize/RISCV/vectorize-force-tail-with-evl-fixed-order-recurrence.ll

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,109 @@ for.end:
542542
ret void
543543
}
544544

545+
define i32 @FOR_reduction(ptr noalias %A, ptr noalias %B, i64 %TC) {
546+
; IF-EVL-LABEL: define i32 @FOR_reduction(
547+
; IF-EVL-SAME: ptr noalias [[A:%.*]], ptr noalias [[B:%.*]], i64 [[TC:%.*]]) #[[ATTR0]] {
548+
; IF-EVL-NEXT: [[ENTRY:.*]]:
549+
; IF-EVL-NEXT: br label %[[FOR_BODY:.*]]
550+
; IF-EVL: [[FOR_BODY]]:
551+
; IF-EVL-NEXT: [[INDVARS:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[INDVARS_NEXT:%.*]], %[[FOR_BODY]] ]
552+
; IF-EVL-NEXT: [[FOR1:%.*]] = phi i32 [ 33, %[[ENTRY]] ], [ [[TMP0:%.*]], %[[FOR_BODY]] ]
553+
; IF-EVL-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds nuw i32, ptr [[A]], i64 [[INDVARS]]
554+
; IF-EVL-NEXT: [[TMP0]] = load i32, ptr [[ARRAYIDX]], align 4
555+
; IF-EVL-NEXT: [[ADD:%.*]] = add nsw i32 [[FOR1]], [[TMP0]]
556+
; IF-EVL-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds nuw i32, ptr [[B]], i64 [[INDVARS]]
557+
; IF-EVL-NEXT: store i32 [[ADD]], ptr [[ARRAYIDX2]], align 4
558+
; IF-EVL-NEXT: [[INDVARS_NEXT]] = add nuw nsw i64 [[INDVARS]], 1
559+
; IF-EVL-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDVARS_NEXT]], [[TC]]
560+
; IF-EVL-NEXT: br i1 [[EXITCOND_NOT]], label %[[FOR_END:.*]], label %[[FOR_BODY]], !llvm.loop [[LOOP8:![0-9]+]]
561+
; IF-EVL: [[FOR_END]]:
562+
; IF-EVL-NEXT: [[FOR1_LCSSA:%.*]] = phi i32 [ [[FOR1]], %[[FOR_BODY]] ]
563+
; IF-EVL-NEXT: ret i32 [[FOR1_LCSSA]]
564+
;
565+
; NO-VP-LABEL: define i32 @FOR_reduction(
566+
; NO-VP-SAME: ptr noalias [[A:%.*]], ptr noalias [[B:%.*]], i64 [[TC:%.*]]) #[[ATTR0]] {
567+
; NO-VP-NEXT: [[ENTRY:.*]]:
568+
; NO-VP-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
569+
; NO-VP-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 4
570+
; NO-VP-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TC]], [[TMP1]]
571+
; NO-VP-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
572+
; NO-VP: [[VECTOR_PH]]:
573+
; NO-VP-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
574+
; NO-VP-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 4
575+
; NO-VP-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[TC]], [[TMP3]]
576+
; NO-VP-NEXT: [[N_VEC:%.*]] = sub i64 [[TC]], [[N_MOD_VF]]
577+
; NO-VP-NEXT: [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
578+
; NO-VP-NEXT: [[TMP5:%.*]] = mul i64 [[TMP4]], 4
579+
; NO-VP-NEXT: [[TMP6:%.*]] = call i32 @llvm.vscale.i32()
580+
; NO-VP-NEXT: [[TMP7:%.*]] = mul i32 [[TMP6]], 4
581+
; NO-VP-NEXT: [[TMP8:%.*]] = sub i32 [[TMP7]], 1
582+
; NO-VP-NEXT: [[VECTOR_RECUR_INIT:%.*]] = insertelement <vscale x 4 x i32> poison, i32 33, i32 [[TMP8]]
583+
; NO-VP-NEXT: br label %[[VECTOR_BODY:.*]]
584+
; NO-VP: [[VECTOR_BODY]]:
585+
; NO-VP-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
586+
; NO-VP-NEXT: [[VECTOR_RECUR:%.*]] = phi <vscale x 4 x i32> [ [[VECTOR_RECUR_INIT]], %[[VECTOR_PH]] ], [ [[WIDE_LOAD:%.*]], %[[VECTOR_BODY]] ]
587+
; NO-VP-NEXT: [[TMP9:%.*]] = add i64 [[INDEX]], 0
588+
; NO-VP-NEXT: [[TMP10:%.*]] = getelementptr inbounds nuw i32, ptr [[A]], i64 [[TMP9]]
589+
; NO-VP-NEXT: [[TMP11:%.*]] = getelementptr inbounds nuw i32, ptr [[TMP10]], i32 0
590+
; NO-VP-NEXT: [[WIDE_LOAD]] = load <vscale x 4 x i32>, ptr [[TMP11]], align 4
591+
; NO-VP-NEXT: [[TMP12:%.*]] = call <vscale x 4 x i32> @llvm.vector.splice.nxv4i32(<vscale x 4 x i32> [[VECTOR_RECUR]], <vscale x 4 x i32> [[WIDE_LOAD]], i32 -1)
592+
; NO-VP-NEXT: [[TMP13:%.*]] = add nsw <vscale x 4 x i32> [[TMP12]], [[WIDE_LOAD]]
593+
; NO-VP-NEXT: [[TMP14:%.*]] = getelementptr inbounds nuw i32, ptr [[B]], i64 [[TMP9]]
594+
; NO-VP-NEXT: [[TMP15:%.*]] = getelementptr inbounds nuw i32, ptr [[TMP14]], i32 0
595+
; NO-VP-NEXT: store <vscale x 4 x i32> [[TMP13]], ptr [[TMP15]], align 4
596+
; NO-VP-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
597+
; NO-VP-NEXT: [[TMP16:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
598+
; NO-VP-NEXT: br i1 [[TMP16]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP8:![0-9]+]]
599+
; NO-VP: [[MIDDLE_BLOCK]]:
600+
; NO-VP-NEXT: [[TMP17:%.*]] = call i32 @llvm.vscale.i32()
601+
; NO-VP-NEXT: [[TMP18:%.*]] = mul i32 [[TMP17]], 4
602+
; NO-VP-NEXT: [[TMP19:%.*]] = sub i32 [[TMP18]], 2
603+
; NO-VP-NEXT: [[VECTOR_RECUR_EXTRACT_FOR_PHI:%.*]] = extractelement <vscale x 4 x i32> [[WIDE_LOAD]], i32 [[TMP19]]
604+
; NO-VP-NEXT: [[TMP20:%.*]] = call i32 @llvm.vscale.i32()
605+
; NO-VP-NEXT: [[TMP21:%.*]] = mul i32 [[TMP20]], 4
606+
; NO-VP-NEXT: [[TMP22:%.*]] = sub i32 [[TMP21]], 1
607+
; NO-VP-NEXT: [[VECTOR_RECUR_EXTRACT:%.*]] = extractelement <vscale x 4 x i32> [[WIDE_LOAD]], i32 [[TMP22]]
608+
; NO-VP-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[TC]], [[N_VEC]]
609+
; NO-VP-NEXT: br i1 [[CMP_N]], label %[[FOR_END:.*]], label %[[SCALAR_PH]]
610+
; NO-VP: [[SCALAR_PH]]:
611+
; NO-VP-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
612+
; NO-VP-NEXT: [[SCALAR_RECUR_INIT:%.*]] = phi i32 [ [[VECTOR_RECUR_EXTRACT]], %[[MIDDLE_BLOCK]] ], [ 33, %[[ENTRY]] ]
613+
; NO-VP-NEXT: br label %[[FOR_BODY:.*]]
614+
; NO-VP: [[FOR_BODY]]:
615+
; NO-VP-NEXT: [[INDVARS:%.*]] = phi i64 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[INDVARS_NEXT:%.*]], %[[FOR_BODY]] ]
616+
; NO-VP-NEXT: [[FOR1:%.*]] = phi i32 [ [[SCALAR_RECUR_INIT]], %[[SCALAR_PH]] ], [ [[TMP23:%.*]], %[[FOR_BODY]] ]
617+
; NO-VP-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds nuw i32, ptr [[A]], i64 [[INDVARS]]
618+
; NO-VP-NEXT: [[TMP23]] = load i32, ptr [[ARRAYIDX]], align 4
619+
; NO-VP-NEXT: [[ADD:%.*]] = add nsw i32 [[FOR1]], [[TMP23]]
620+
; NO-VP-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds nuw i32, ptr [[B]], i64 [[INDVARS]]
621+
; NO-VP-NEXT: store i32 [[ADD]], ptr [[ARRAYIDX2]], align 4
622+
; NO-VP-NEXT: [[INDVARS_NEXT]] = add nuw nsw i64 [[INDVARS]], 1
623+
; NO-VP-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDVARS_NEXT]], [[TC]]
624+
; NO-VP-NEXT: br i1 [[EXITCOND_NOT]], label %[[FOR_END]], label %[[FOR_BODY]], !llvm.loop [[LOOP9:![0-9]+]]
625+
; NO-VP: [[FOR_END]]:
626+
; NO-VP-NEXT: [[FOR1_LCSSA:%.*]] = phi i32 [ [[FOR1]], %[[FOR_BODY]] ], [ [[VECTOR_RECUR_EXTRACT_FOR_PHI]], %[[MIDDLE_BLOCK]] ]
627+
; NO-VP-NEXT: ret i32 [[FOR1_LCSSA]]
628+
;
629+
entry:
630+
br label %for.body
631+
632+
for.body:
633+
%iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
634+
%for1 = phi i32 [ 33, %entry ], [ %0, %for.body ]
635+
%arrayidx = getelementptr inbounds nuw i32, ptr %A, i64 %iv
636+
%0 = load i32, ptr %arrayidx, align 4
637+
%add = add nsw i32 %for1, %0
638+
%arrayidx2 = getelementptr inbounds nuw i32, ptr %B, i64 %iv
639+
store i32 %add, ptr %arrayidx2, align 4
640+
%iv.next = add nuw nsw i64 %iv, 1
641+
%exitcond.not = icmp eq i64 %iv.next, %TC
642+
br i1 %exitcond.not, label %for.end, label %for.body, !llvm.loop !0
643+
644+
for.end:
645+
ret i32 %for1
646+
}
647+
545648
!0 = distinct !{!0, !1}
546649
!1 = !{!"llvm.loop.vectorize.enable", i1 true}
547650
;.
@@ -553,6 +656,8 @@ for.end:
553656
; IF-EVL: [[LOOP5]] = distinct !{[[LOOP5]], [[META2]], [[META1]]}
554657
; IF-EVL: [[LOOP6]] = distinct !{[[LOOP6]], [[META1]], [[META2]]}
555658
; IF-EVL: [[LOOP7]] = distinct !{[[LOOP7]], [[META2]], [[META1]]}
659+
; IF-EVL: [[LOOP8]] = distinct !{[[LOOP8]], [[META9:![0-9]+]]}
660+
; IF-EVL: [[META9]] = !{!"llvm.loop.vectorize.enable", i1 true}
556661
;.
557662
; NO-VP: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]]}
558663
; NO-VP: [[META1]] = !{!"llvm.loop.isvectorized", i32 1}
@@ -562,4 +667,6 @@ for.end:
562667
; NO-VP: [[LOOP5]] = distinct !{[[LOOP5]], [[META2]], [[META1]]}
563668
; NO-VP: [[LOOP6]] = distinct !{[[LOOP6]], [[META1]], [[META2]]}
564669
; NO-VP: [[LOOP7]] = distinct !{[[LOOP7]], [[META2]], [[META1]]}
670+
; NO-VP: [[LOOP8]] = distinct !{[[LOOP8]], [[META1]], [[META2]]}
671+
; NO-VP: [[LOOP9]] = distinct !{[[LOOP9]], [[META2]], [[META1]]}
565672
;.

0 commit comments

Comments
 (0)