diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -1717,10 +1717,15 @@ MadeChange |= scalarizeLoadExtract(I); break; default: - MadeChange |= scalarizeBinopOrCmp(I); break; } } + + // This transform works with scalable and fixed vectors + // TODO: Identify and allow other scalable transforms + if (isa(I.getType())) + MadeChange |= scalarizeBinopOrCmp(I); + if (Opcode == Instruction::Store) MadeChange |= foldSingleElementStore(I); diff --git a/llvm/test/Transforms/VectorCombine/AArch64/scalarize-scalable.ll b/llvm/test/Transforms/VectorCombine/AArch64/scalarize-scalable.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/VectorCombine/AArch64/scalarize-scalable.ll @@ -0,0 +1,48 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -passes=vector-combine -S %s | FileCheck %s + +define @scalarize_scalable(float %0, float %1, float %2, float %3) { +; CHECK-LABEL: @scalarize_scalable( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[DOTSCALAR:%.*]] = fadd fast float [[TMP1:%.*]], [[TMP0:%.*]] +; CHECK-NEXT: [[DOTSCALAR1:%.*]] = fadd fast float [[TMP2:%.*]], [[DOTSCALAR]] +; CHECK-NEXT: [[DOTSCALAR2:%.*]] = fadd fast float [[TMP3:%.*]], [[DOTSCALAR1]] +; CHECK-NEXT: [[TMP4:%.*]] = insertelement poison, float [[DOTSCALAR2]], i64 0 +; CHECK-NEXT: [[TMP5:%.*]] = shufflevector [[TMP4]], poison, zeroinitializer +; CHECK-NEXT: ret [[TMP5]] +; +entry: + %broadcast.splatinsert = insertelement poison, float %0, i64 0 + %broadcast.splatinsert28 = insertelement poison, float %1, i64 0 + %broadcast.splatinsert30 = insertelement poison, float %2, i64 0 + %broadcast.splatinsert32 = insertelement poison, float %3, i64 0 + %4 = fadd fast %broadcast.splatinsert28, %broadcast.splatinsert + %5 = fadd fast %broadcast.splatinsert30, %4 + %6 = fadd fast %broadcast.splatinsert32, %5 + %7 = shufflevector %6, poison, zeroinitializer + ret %7 +} + +define @scalarize_scalable_udiv(i32 %x, i32 %y) { +; CHECK-LABEL: @scalarize_scalable_udiv( +; CHECK-NEXT: [[R_SCALAR:%.*]] = udiv i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[R:%.*]] = insertelement poison, i32 [[R_SCALAR]], i64 0 +; CHECK-NEXT: ret [[R]] +; + %splatx = insertelement poison, i32 %x, i64 0 + %splaty = insertelement poison, i32 %y, i64 0 + %r = udiv %splatx, %splaty + ret %r +} + +define @scalarize_scalable_icmp(i32 %x, i32 %y) { +; CHECK-LABEL: @scalarize_scalable_icmp( +; CHECK-NEXT: [[R_SCALAR:%.*]] = icmp sgt i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[R:%.*]] = insertelement poison, i1 [[R_SCALAR]], i64 0 +; CHECK-NEXT: ret [[R]] +; + %splatx = insertelement poison, i32 %x, i64 0 + %splaty = insertelement poison, i32 %y, i64 0 + %r = icmp sgt %splatx, %splaty + ret %r +}