diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -4956,6 +4956,21 @@ } break; } + case Instruction::ExtractValue: { + auto *EVI = cast(&I); + setDebugLocFromInst(EVI); + + Type *DestTy = + VF.isScalar() ? EVI->getType() : VectorType::get(EVI->getType(), VF); + for (unsigned Part = 0; Part < UF; ++Part) { + Value *Val = Builder.CreateExtractValue(EVI->getAggregateOperand(), + EVI->getIndices()); + Value *VecVal = Builder.CreateVectorSplat(VF, Val); + State.set(Def, VecVal, Part); + addMetadata(VecVal, &I); + } + break; + } default: // This instruction is not vectorized by simple widening. LLVM_DEBUG(dbgs() << "LV: Found an unhandled instruction: " << I); @@ -8882,6 +8897,7 @@ case Instruction::And: case Instruction::AShr: case Instruction::BitCast: + case Instruction::ExtractValue: case Instruction::FAdd: case Instruction::FCmp: case Instruction::FDiv: diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/extractvalue-no-scalarization-required.ll b/llvm/test/Transforms/LoopVectorize/AArch64/extractvalue-no-scalarization-required.ll --- a/llvm/test/Transforms/LoopVectorize/AArch64/extractvalue-no-scalarization-required.ll +++ b/llvm/test/Transforms/LoopVectorize/AArch64/extractvalue-no-scalarization-required.ll @@ -18,21 +18,19 @@ ; FORCED-NEXT: %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ] ; FORCED-NEXT: %0 = add i32 %index, 0 ; FORCED-NEXT: %1 = extractvalue { i64, i64 } %sv, 0 -; FORCED-NEXT: %2 = extractvalue { i64, i64 } %sv, 0 -; FORCED-NEXT: %3 = insertelement <2 x i64> poison, i64 %1, i32 0 -; FORCED-NEXT: %4 = insertelement <2 x i64> %3, i64 %2, i32 1 -; FORCED-NEXT: %5 = extractvalue { i64, i64 } %sv, 1 -; FORCED-NEXT: %6 = extractvalue { i64, i64 } %sv, 1 -; FORCED-NEXT: %7 = insertelement <2 x i64> poison, i64 %5, i32 0 -; FORCED-NEXT: %8 = insertelement <2 x i64> %7, i64 %6, i32 1 -; FORCED-NEXT: %9 = getelementptr i64, i64* %dst, i32 %0 -; FORCED-NEXT: %10 = add <2 x i64> %4, %8 -; FORCED-NEXT: %11 = getelementptr i64, i64* %9, i32 0 -; FORCED-NEXT: %12 = bitcast i64* %11 to <2 x i64>* -; FORCED-NEXT: store <2 x i64> %10, <2 x i64>* %12, align 4 +; FORCED-NEXT: %.splatinsert = insertelement <2 x i64> poison, i64 %1, i32 0 +; FORCED-NEXT: %.splat = shufflevector <2 x i64> %.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer +; FORCED-NEXT: %2 = extractvalue { i64, i64 } %sv, 1 +; FORCED-NEXT: %.splatinsert1 = insertelement <2 x i64> poison, i64 %2, i32 0 +; FORCED-NEXT: %.splat2 = shufflevector <2 x i64> %.splatinsert1, <2 x i64> poison, <2 x i32> zeroinitializer +; FORCED-NEXT: %3 = getelementptr i64, i64* %dst, i32 %0 +; FORCED-NEXT: %4 = add <2 x i64> %.splat, %.splat2 +; FORCED-NEXT: %5 = getelementptr i64, i64* %3, i32 0 +; FORCED-NEXT: %6 = bitcast i64* %5 to <2 x i64>* +; FORCED-NEXT: store <2 x i64> %4, <2 x i64>* %6, align 4 ; FORCED-NEXT: %index.next = add nuw i32 %index, 2 -; FORCED-NEXT: %13 = icmp eq i32 %index.next, 0 -; FORCED-NEXT: br i1 %13, label %middle.block, label %vector.body, !llvm.loop !0 +; FORCED-NEXT: %7 = icmp eq i32 %index.next, 0 +; FORCED-NEXT: br i1 %7, label %middle.block, label %vector.body, !llvm.loop !0 define void @test1(i64* %dst, {i64, i64} %sv) { entry: @@ -67,21 +65,19 @@ ; FORCED-NEXT: %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ] ; FORCED-NEXT: %0 = add i32 %index, 0 ; FORCED-NEXT: %1 = extractvalue { float, float } %sv, 0 -; FORCED-NEXT: %2 = extractvalue { float, float } %sv, 0 -; FORCED-NEXT: %3 = insertelement <2 x float> poison, float %1, i32 0 -; FORCED-NEXT: %4 = insertelement <2 x float> %3, float %2, i32 1 -; FORCED-NEXT: %5 = extractvalue { float, float } %sv, 1 -; FORCED-NEXT: %6 = extractvalue { float, float } %sv, 1 -; FORCED-NEXT: %7 = insertelement <2 x float> poison, float %5, i32 0 -; FORCED-NEXT: %8 = insertelement <2 x float> %7, float %6, i32 1 -; FORCED-NEXT: %9 = getelementptr float, float* %dst, i32 %0 -; FORCED-NEXT: %10 = call <2 x float> @llvm.pow.v2f32(<2 x float> %4, <2 x float> %8) -; FORCED-NEXT: %11 = getelementptr float, float* %9, i32 0 -; FORCED-NEXT: %12 = bitcast float* %11 to <2 x float>* -; FORCED-NEXT: store <2 x float> %10, <2 x float>* %12, align 4 +; FORCED-NEXT: %.splatinsert = insertelement <2 x float> poison, float %1, i32 0 +; FORCED-NEXT: %.splat = shufflevector <2 x float> %.splatinsert, <2 x float> poison, <2 x i32> zeroinitializer +; FORCED-NEXT: %2 = extractvalue { float, float } %sv, 1 +; FORCED-NEXT: %.splatinsert1 = insertelement <2 x float> poison, float %2, i32 0 +; FORCED-NEXT: %.splat2 = shufflevector <2 x float> %.splatinsert1, <2 x float> poison, <2 x i32> zeroinitializer +; FORCED-NEXT: %3 = getelementptr float, float* %dst, i32 %0 +; FORCED-NEXT: %4 = call <2 x float> @llvm.pow.v2f32(<2 x float> %.splat, <2 x float> %.splat2) +; FORCED-NEXT: %5 = getelementptr float, float* %3, i32 0 +; FORCED-NEXT: %6 = bitcast float* %5 to <2 x float>* +; FORCED-NEXT: store <2 x float> %4, <2 x float>* %6, align 4 ; FORCED-NEXT: %index.next = add nuw i32 %index, 2 -; FORCED-NEXT: %13 = icmp eq i32 %index.next, 0 -; FORCED-NEXT: br i1 %13, label %middle.block, label %vector.body, !llvm.loop !4 +; FORCED-NEXT: %7 = icmp eq i32 %index.next, 0 +; FORCED-NEXT: br i1 %7, label %middle.block, label %vector.body, !llvm.loop !4 define void @test_getVectorCallCost(float* %dst, {float, float} %sv) { entry: diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-extractvalue.ll b/llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-extractvalue.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-extractvalue.ll @@ -0,0 +1,41 @@ +; RUN: opt -S -loop-vectorize -scalable-vectorization=on < %s | FileCheck %s + +target triple = "aarch64-unknown-linux-gnu" + +define void @widen_extractvalue(i64* %dst, {i64, i64} %sv) #0 { +; CHECK-LABEL: @widen_extractvalue( +; CHECK: vector.body: +; CHECK: [[EXTRACT0:%.*]] = extractvalue { i64, i64 } [[SV:%.*]], 0 +; CHECK: [[DOTSPLATINSERT:%.*]] = insertelement poison, i64 [[EXTRACT0]], i32 0 +; CHECK: [[DOTSPLAT:%.*]] = shufflevector [[DOTSPLATINSERT]], poison, zeroinitializer +; CHECK: [[EXTRACT1:%.*]] = extractvalue { i64, i64 } [[SV]], 1 +; CHECK: [[DOTSPLATINSERT1:%.*]] = insertelement poison, i64 [[EXTRACT1]], i32 0 +; CHECK: [[DOTSPLAT2:%.*]] = shufflevector [[DOTSPLATINSERT1]], poison, zeroinitializer +; CHECK: [[ADD:%.*]] = add [[DOTSPLAT]], [[DOTSPLAT2]] +entry: + br label %loop.body + +loop.body: + %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.body ] + %a = extractvalue { i64, i64 } %sv, 0 + %b = extractvalue { i64, i64 } %sv, 1 + %addr = getelementptr i64, i64* %dst, i32 %iv + %add = add i64 %a, %b + store i64 %add, i64* %addr + %iv.next = add nsw i32 %iv, 1 + %cond = icmp ne i32 %iv.next, 0 + br i1 %cond, label %loop.body, label %exit, !llvm.loop !0 + +exit: + ret void +} + +attributes #0 = { "target-features"="+sve" } + +!0 = distinct !{!0, !1, !2, !3, !4, !5} +!1 = !{!"llvm.loop.mustprogress"} +!2 = !{!"llvm.loop.vectorize.width", i32 2} +!3 = !{!"llvm.loop.vectorize.scalable.enable", i1 true} +!4 = !{!"llvm.loop.interleave.count", i32 1} +!5 = !{!"llvm.loop.vectorize.enable", i1 true} +