[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
Thu Jun 18 13:38:55 PDT 2020


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

Good clarification: InstCombine vs. InstSimplify.
Merged and reduced test, full diff included.
If the patch is OK, could I ask you one more favor: to commit it? I do not have commit access to the project.


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
@@ -333,9 +333,7 @@
 
 define <2 x i64> @urem_constant_op1(i64 %x) {
 ; CHECK-LABEL: @urem_constant_op1(
-; CHECK-NEXT:    [[BO_SCALAR:%.*]] = urem i64 [[X:%.*]], 2
-; CHECK-NEXT:    [[BO:%.*]] = insertelement <2 x i64> <i64 undef, i64 0>, i64 [[BO_SCALAR]], i64 1
-; CHECK-NEXT:    ret <2 x i64> [[BO]]
+; CHECK-NEXT:    ret <2 x i64> undef
 ;
   %ins = insertelement <2 x i64> undef, i64 %x, i32 1
   %bo = urem <2 x i64> %ins, <i64 undef, i64 2>
@@ -377,9 +375,7 @@
 
 define <2 x i64> @srem_constant_op1(i64 %x) {
 ; CHECK-LABEL: @srem_constant_op1(
-; CHECK-NEXT:    [[BO_SCALAR:%.*]] = srem i64 [[X:%.*]], 2
-; CHECK-NEXT:    [[BO:%.*]] = insertelement <2 x i64> <i64 undef, i64 0>, i64 [[BO_SCALAR]], i64 1
-; CHECK-NEXT:    ret <2 x i64> [[BO]]
+; CHECK-NEXT:    ret <2 x i64> undef
 ;
   %ins = insertelement <2 x i64> undef, i64 %x, i32 1
   %bo = srem <2 x i64> %ins, <i64 undef, i64 2>
@@ -421,9 +417,7 @@
 
 define <2 x i64> @udiv_constant_op1(i64 %x) {
 ; CHECK-LABEL: @udiv_constant_op1(
-; CHECK-NEXT:    [[BO_SCALAR:%.*]] = udiv i64 [[X:%.*]], 2
-; CHECK-NEXT:    [[BO:%.*]] = insertelement <2 x i64> <i64 undef, i64 0>, i64 [[BO_SCALAR]], i64 1
-; CHECK-NEXT:    ret <2 x i64> [[BO]]
+; CHECK-NEXT:    ret <2 x i64> undef
 ;
   %ins = insertelement <2 x i64> undef, i64 %x, i32 1
   %bo = udiv <2 x i64> %ins, <i64 undef, i64 2>
@@ -465,9 +459,7 @@
 
 define <2 x i64> @sdiv_constant_op1(i64 %x) {
 ; CHECK-LABEL: @sdiv_constant_op1(
-; CHECK-NEXT:    [[BO_SCALAR:%.*]] = sdiv exact i64 [[X:%.*]], 2
-; CHECK-NEXT:    [[BO:%.*]] = insertelement <2 x i64> <i64 undef, i64 0>, i64 [[BO_SCALAR]], i64 1
-; CHECK-NEXT:    ret <2 x i64> [[BO]]
+; CHECK-NEXT:    ret <2 x i64> undef
 ;
   %ins = insertelement <2 x i64> undef, i64 %x, i32 1
   %bo = sdiv exact <2 x i64> %ins, <i64 undef, i64 2>
@@ -726,3 +718,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
@@ -416,6 +416,11 @@
     // Ignore unreachable basic blocks.
     if (!DT.isReachableFromEntry(&BB))
       continue;
+
+    // Fold what can be folded, to avoid Constants showing up in unexpected
+    // places.
+    MadeChange |= SimplifyInstructionsInBlock(&BB);
+
     // Do not delete instructions under here and invalidate the iterator.
     // Walk the block forwards to enable simple iterative chains of transforms.
     // TODO: It could be more efficient to remove dead instructions


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


More information about the llvm-commits mailing list