[PATCH] D92819: [TruncInstCombine] Remove scalable vector restriction

JunMa via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 8 00:19:50 PST 2020


junparser created this revision.
junparser added reviewers: efriedma, fpetrogalli, sdesmalen, ctetreau.
junparser added a project: LLVM.
Herald added a subscriber: hiraditya.
junparser requested review of this revision.
Herald added a subscriber: llvm-commits.

This simple patch removes the restriction of scalable vector type in truncinstcombine.

TestPlan: check-llvm


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92819

Files:
  llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp
  llvm/test/Transforms/AggressiveInstCombine/trunc_const_expr.ll


Index: llvm/test/Transforms/AggressiveInstCombine/trunc_const_expr.ll
===================================================================
--- llvm/test/Transforms/AggressiveInstCombine/trunc_const_expr.ll
+++ llvm/test/Transforms/AggressiveInstCombine/trunc_const_expr.ll
@@ -8,6 +8,7 @@
 
 declare i32 @use32(i32)
 declare <2 x i32> @use32_vec(<2 x i32>)
+declare <vscale x 2 x i32> @use32_scale_vec(<vscale x 2 x i32>)
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; These tests check cases where expression dag post-dominated by TruncInst
@@ -108,3 +109,35 @@
   call <2 x i32> @use32_vec(<2 x i32> %T)
   ret void
 }
+
+define void @const_expression_mul_scale_vec() {
+; CHECK-LABEL: @const_expression_mul_scale_vec(
+; CHECK-NEXT:    [[TMP1:%.*]] = call <vscale x 2 x i32> @use32_scale_vec(<vscale x 2 x i32> zeroinitializer)
+; CHECK-NEXT:    ret void
+;
+  %A = mul <vscale x 2 x i64> zeroinitializer, zeroinitializer
+  %T = trunc <vscale x 2 x i64> %A to <vscale x 2 x i32>
+  call <vscale x 2 x i32> @use32_scale_vec(<vscale x 2 x i32> %T)
+  ret void
+}
+
+define void @const_expression_zext_scale_vec() {
+; CHECK-LABEL: @const_expression_zext_scale_vec(
+; CHECK-NEXT:    [[TMP1:%.*]] = call <vscale x 2 x i32> @use32_scale_vec(<vscale x 2 x i32> zeroinitializer)
+; CHECK-NEXT:    ret void
+;
+  %A = zext <vscale x 2 x i32> zeroinitializer to <vscale x 2 x i64>
+  %T = trunc <vscale x 2 x i64> %A to <vscale x 2 x i32>
+  call <vscale x 2 x i32> @use32_scale_vec(<vscale x 2 x i32> %T)
+  ret void
+}
+
+define void @const_expression_trunc_scale_vec() {
+; CHECK-LABEL: @const_expression_trunc_scale_vec(
+; CHECK-NEXT:    [[TMP1:%.*]] = call <vscale x 2 x i32> @use32_scale_vec(<vscale x 2 x i32> zeroinitializer)
+; CHECK-NEXT:    ret void
+;
+  %T = trunc <vscale x 2 x i64> zeroinitializer to <vscale x 2 x i32>
+  call <vscale x 2 x i32> @use32_scale_vec(<vscale x 2 x i32> %T)
+  ret void
+}
Index: llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp
===================================================================
--- llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp
+++ llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp
@@ -289,11 +289,8 @@
 /// version of \p Ty, otherwise return \p Ty.
 static Type *getReducedType(Value *V, Type *Ty) {
   assert(Ty && !Ty->isVectorTy() && "Expect Scalar Type");
-  if (auto *VTy = dyn_cast<VectorType>(V->getType())) {
-    // FIXME: should this handle scalable vectors?
-    return FixedVectorType::get(Ty,
-                                cast<FixedVectorType>(VTy)->getNumElements());
-  }
+  if (auto *VTy = dyn_cast<VectorType>(V->getType()))
+    return VectorType::get(Ty, VTy->getElementCount());
   return Ty;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92819.310098.patch
Type: text/x-patch
Size: 2767 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201208/be768f56/attachment.bin>


More information about the llvm-commits mailing list