[PATCH] D92046: [InstSimplify] Clarify use of FixedVectorType in SimplifySelectInst

Cullen Rhodes via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 24 10:32:44 PST 2020

c-rhodes created this revision.
c-rhodes added reviewers: sdesmalen, RKSimon, spatel, efriedma.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
c-rhodes requested review of this revision.

Folding a select of vector constants that include undef elements only
applies to fixed vectors, but there's no earlier check the type is not
scalable so it crashes for scalable vectors. This adds a check so this
optimization is only attempted for fixed vectors.

  rG LLVM Github Monorepo



Index: llvm/test/Transforms/InstSimplify/select.ll
--- llvm/test/Transforms/InstSimplify/select.ll
+++ llvm/test/Transforms/InstSimplify/select.ll
@@ -957,3 +957,14 @@
   ret i32 %r1.sroa.0.1
 declare i32 @llvm.cttz.i32(i32, i1 immarg)
+; Partial undef scalable vectors should be ignored.
+define <vscale x 2 x i1> @ignore_scalable_undef(<vscale x 2 x i1> %cond) {
+; CHECK-LABEL: @ignore_scalable_undef(
+; CHECK-NEXT:    [[S:%.*]] = select <vscale x 2 x i1> [[COND:%.*]], <vscale x 2 x i1> undef, <vscale x 2 x i1> insertelement (<vscale x 2 x i1> undef, i1 true, i32 0)
+; CHECK-NEXT:    ret <vscale x 2 x i1> [[S]]
+  %vec = insertelement <vscale x 2 x i1> undef, i1 true, i32 0
+  %s = select <vscale x 2 x i1> %cond, <vscale x 2 x i1> undef, <vscale x 2 x i1> %vec
+  ret <vscale x 2 x i1> %s
Index: llvm/lib/Analysis/InstructionSimplify.cpp
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4136,7 +4136,8 @@
   // Deal with partial undef vector constants: select ?, VecC, VecC' --> VecC''
   Constant *TrueC, *FalseC;
-  if (TrueVal->getType()->isVectorTy() && match(TrueVal, m_Constant(TrueC)) &&
+  if (isa<FixedVectorType>(TrueVal->getType()) &&
+      match(TrueVal, m_Constant(TrueC)) &&
       match(FalseVal, m_Constant(FalseC))) {
     unsigned NumElts =

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92046.307407.patch
Type: text/x-patch
Size: 1534 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201124/d669e8a5/attachment.bin>

More information about the llvm-commits mailing list