diff --git a/llvm/lib/Target/RISCV/RISCVSubtarget.h b/llvm/lib/Target/RISCV/RISCVSubtarget.h --- a/llvm/lib/Target/RISCV/RISCVSubtarget.h +++ b/llvm/lib/Target/RISCV/RISCVSubtarget.h @@ -62,6 +62,7 @@ bool EnableSaveRestore = false; unsigned XLen = 32; MVT XLenVT = MVT::i32; + uint8_t MaxInterleaveFactor = 2; RISCVABI::ABI TargetABI = RISCVABI::ABI_Unknown; BitVector UserReservedRegister; RISCVFrameLowering FrameLowering; @@ -134,6 +135,7 @@ assert(i < RISCV::NUM_TARGET_REGS && "Register out of range"); return UserReservedRegister[i]; } + unsigned getMaxInterleaveFactor() const { return MaxInterleaveFactor; } protected: // GlobalISel related APIs. diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h --- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h +++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h @@ -131,6 +131,11 @@ bool isLegalMaskedScatter(Type *DataType, Align Alignment) { return isLegalMaskedGatherScatter(DataType, Alignment); } + + bool enableInterleavedAccessVectorization() { return true; } + unsigned getMaxInterleaveFactor(unsigned VF) { + return ST->getMaxInterleaveFactor(); + } }; } // end namespace llvm diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/riscv-interleaved.ll b/llvm/test/Transforms/LoopVectorize/RISCV/riscv-interleaved.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/LoopVectorize/RISCV/riscv-interleaved.ll @@ -0,0 +1,63 @@ +; RUN: opt -loop-vectorize -dce -instcombine -mtriple riscv64-linux-gnu -mattr=+experimental-v -debug-only=loop-vectorize -riscv-v-vector-bits-min=128 -S < %s 2>&1 | FileCheck %s + +; CHECK-LABEL: foo +; CHECK: LV: IC is 2 + +target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128" +target triple = "riscv64-unknown-unknown-elf" + +; Function Attrs: nofree norecurse nosync nounwind writeonly +define dso_local void @foo(i32 signext %n, i32* nocapture %A) local_unnamed_addr #0 !dbg !8 { +entry: + %cmp5 = icmp sgt i32 %n, 0, !dbg !10 + br i1 %cmp5, label %for.body.preheader, label %for.cond.cleanup, !dbg !11 + +for.body.preheader: ; preds = %entry + %wide.trip.count = zext i32 %n to i64, !dbg !10 + br label %for.body, !dbg !11 + +for.cond.cleanup.loopexit: ; preds = %for.body + br label %for.cond.cleanup, !dbg !12 + +for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry + ret void, !dbg !12 + +for.body: ; preds = %for.body.preheader, %for.body + %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ] + %arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv, !dbg !13 + %0 = trunc i64 %indvars.iv to i32, !dbg !14 + store i32 %0, i32* %arrayidx, align 4, !dbg !14, !tbaa !15 + %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !19 + %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count, !dbg !10 + br i1 %exitcond.not, label %for.cond.cleanup.loopexit, label %for.body, !dbg !11, !llvm.loop !20 +} + +attributes #0 = { nofree norecurse nosync nounwind writeonly "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+a,+c,+m,+relax,-save-restore" } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5, !6} +!llvm.ident = !{!7} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 13.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: NoDebug, enums: !2, splitDebugInlining: false, nameTableKind: None) +!1 = !DIFile(filename: "riscv-interleaved.c", directory: "llvm-project") +!2 = !{} +!3 = !{i32 2, !"Debug Info Version", i32 3} +!4 = !{i32 1, !"wchar_size", i32 4} +!5 = !{i32 1, !"target-abi", !"lp64"} +!6 = !{i32 1, !"SmallDataLimit", i32 8} +!7 = !{!"clang version 13.0.0"} +!8 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 12, type: !9, scopeLine: 13, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) +!9 = !DISubroutineType(types: !2) +!10 = !DILocation(line: 15, column: 23, scope: !8) +!11 = !DILocation(line: 15, column: 5, scope: !8) +!12 = !DILocation(line: 17, column: 1, scope: !8) +!13 = !DILocation(line: 16, column: 9, scope: !8) +!14 = !DILocation(line: 16, column: 14, scope: !8) +!15 = !{!16, !16, i64 0} +!16 = !{!"int", !17, i64 0} +!17 = !{!"omnipotent char", !18, i64 0} +!18 = !{!"Simple C/C++ TBAA"} +!19 = !DILocation(line: 15, column: 29, scope: !8) +!20 = distinct !{!20, !11, !21, !22} +!21 = !DILocation(line: 16, column: 16, scope: !8) +!22 = !{!"llvm.loop.mustprogress"}