[PATCH] D82049: Fix crash in VectorCombine when attempting to peephole ConstantVector sequences

Chang Lin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 19 10:19:25 PDT 2020


clin1 updated this revision to Diff 272122.
clin1 added a comment.

Return true to trigger the simplifier.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82049/new/

https://reviews.llvm.org/D82049

Files:
  llvm/lib/Transforms/Vectorize/VectorCombine.cpp
  llvm/test/Transforms/VectorCombine/X86/insert-binop-with-constant.ll


Index: llvm/test/Transforms/VectorCombine/X86/insert-binop-with-constant.ll
===================================================================
--- llvm/test/Transforms/VectorCombine/X86/insert-binop-with-constant.ll
+++ llvm/test/Transforms/VectorCombine/X86/insert-binop-with-constant.ll
@@ -726,3 +726,15 @@
   %bo = frem nnan <2 x double> %ins, <double 42.0, double -42.0>
   ret <2 x double> %bo
 }
+
+define i32 @constant_fold_crash(<4 x i32> %x) {
+; CHECK-LABEL: @constant_fold_crash(
+; CHECK-NEXT:    [[B:%.*]] = extractelement <4 x i32> [[X:%.*]], i32 0
+; CHECK-NEXT:    [[C:%.*]] = add i32 17, [[B]]
+; CHECK-NEXT:    ret i32 [[C]]
+;
+  %a = extractelement <4 x i32> <i32 16, i32 17, i32 18, i32 19>, i32 1
+  %b = extractelement <4 x i32> %x, i32 0
+  %c = add i32 %a, %b
+  ret i32 %c
+}
Index: llvm/lib/Transforms/Vectorize/VectorCombine.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -218,6 +218,11 @@
       V0->getType() != V1->getType())
     return false;
 
+  // If either extract can be constant-folded, return true to trigger
+  // InstSimplify.
+  if (isa<Constant>(Ext0->getOperand(0)) || isa<Constant>(Ext1->getOperand(0)))
+    return true;
+
   // If the scalar value 'I' is going to be re-inserted into a vector, then try
   // to create an extract to that same element. The extract/insert can be
   // reduced to a "select shuffle".


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82049.272122.patch
Type: text/x-patch
Size: 1497 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200619/c0356ec6/attachment.bin>


More information about the llvm-commits mailing list