[PATCH] D98351: [llvm-opt] Bug fix within combining FP vectors

Nashe Mncube via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 10 07:25:59 PST 2021


nasherm created this revision.
Herald added a subscriber: hiraditya.
nasherm requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

A bug was found within InstCombineCasts where a function call
is only implemented to work with FixedVectors. This caused a
crash when a ScalableVector was passed to this function.
This commit introduces a regression test which recreates the
failure and a bug fix.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98351

Files:
  llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
  llvm/test/Transforms/InstCombine/instcombine-vectors.ll


Index: llvm/test/Transforms/InstCombine/instcombine-vectors.ll
===================================================================
--- /dev/null
+++ 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 <vscale x 2 x float> @foo(<vscale x 2 x double> %a) {
+  ; CHECK-LABEL: @foo
+  %1 = fadd <vscale x 2 x double> %a, shufflevector (<vscale x 2 x double> insertelement (<vscale x 2 x double> poison, double -1.000000e+00, i32 0), <vscale x 2 x double> poison, <vscale x 2 x i32> zeroinitializer)
+  %2 = fptrunc <vscale x 2 x double> %1 to <vscale x 2 x float>
+  ret <vscale x 2 x float> %2
+}
Index: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1574,7 +1574,10 @@
 
   Type *MinType = nullptr;
 
-  unsigned NumElts = cast<FixedVectorType>(CVVTy)->getNumElements();
+  unsigned NumElts = (isa<FixedVectorType>(CVVTy))
+                         ? cast<FixedVectorType>(CVVTy)->getNumElements()
+                         : cast<ScalableVectorType>(CVVTy)->getMinNumElements();
+
   for (unsigned i = 0; i != NumElts; ++i) {
     auto *CFP = dyn_cast_or_null<ConstantFP>(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<ScalableVectorType>(CVVTy));
 }
 
 /// Find the minimum FP type we can safely truncate to.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98351.329660.patch
Type: text/x-patch
Size: 1677 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210310/c2420351/attachment.bin>


More information about the llvm-commits mailing list