diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -1574,7 +1574,10 @@ Type *MinType = nullptr; - unsigned NumElts = cast(CVVTy)->getNumElements(); + unsigned NumElts = (isa(CVVTy)) + ? cast(CVVTy)->getNumElements() + : cast(CVVTy)->getMinNumElements(); + for (unsigned i = 0; i != NumElts; ++i) { auto *CFP = dyn_cast_or_null(CV->getAggregateElement(i)); if (!CFP) @@ -1591,7 +1594,7 @@ } // Make a vector type from the minimal type. - return FixedVectorType::get(MinType, NumElts); + return VectorType::get(MinType, NumElts, isa(CVVTy)); } /// Find the minimum FP type we can safely truncate to. diff --git a/llvm/test/Transforms/InstCombine/instcombine-vectors.ll b/llvm/test/Transforms/InstCombine/instcombine-vectors.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/InstCombine/instcombine-vectors.ll @@ -0,0 +1,8 @@ +; RUN: opt -instcombine -march=armv8.1-a+sve -S -o - < %s | FileCheck %s + +define @foo( %a) { + ; CHECK-LABEL: @foo + %1 = fadd %a, shufflevector ( insertelement ( poison, double -1.000000e+00, i32 0), poison, zeroinitializer) + %2 = fptrunc %1 to + ret %2 +}