[PATCH] D75327: [VectorCombine] Fix assert on compare extract index

Austin Kerbow via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 28 10:42:09 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG4fa63fd4524c: [VectorCombine] Fix assert on compare extract index (authored by kerbowa).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75327

Files:
  llvm/lib/Transforms/Vectorize/VectorCombine.cpp
  llvm/test/Transforms/VectorCombine/X86/extract-binop.ll


Index: llvm/test/Transforms/VectorCombine/X86/extract-binop.ll
===================================================================
--- llvm/test/Transforms/VectorCombine/X86/extract-binop.ll
+++ llvm/test/Transforms/VectorCombine/X86/extract-binop.ll
@@ -147,6 +147,20 @@
   ret i32 %r
 }
 
+; Don't assert if extract indices have different types.
+
+define i32 @ext1_ext1_add_same_vec_diff_idx_ty(<4 x i32> %x) {
+; CHECK-LABEL: @ext1_ext1_add_same_vec_diff_idx_ty(
+; CHECK-NEXT:    [[TMP1:%.*]] = add <4 x i32> [[X:%.*]], [[X]]
+; CHECK-NEXT:    [[TMP2:%.*]] = extractelement <4 x i32> [[TMP1]], i32 1
+; CHECK-NEXT:    ret i32 [[TMP2]]
+;
+  %e0 = extractelement <4 x i32> %x, i32 1
+  %e1 = extractelement <4 x i32> %x, i64 1
+  %r = add i32 %e0, %e1
+  ret i32 %r
+}
+
 declare void @use_i8(i8)
 
 ; Negative test - same vector operand; scalar code is cheaper than general case
Index: llvm/lib/Transforms/Vectorize/VectorCombine.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -46,8 +46,9 @@
 static bool isExtractExtractCheap(Instruction *Ext0, Instruction *Ext1,
                                   unsigned Opcode,
                                   const TargetTransformInfo &TTI) {
-  assert(Ext0->getOperand(1) == Ext1->getOperand(1) &&
-         isa<ConstantInt>(Ext0->getOperand(1)) &&
+  assert(isa<ConstantInt>(Ext0->getOperand(1)) &&
+         (cast<ConstantInt>(Ext0->getOperand(1))->getZExtValue() ==
+          cast<ConstantInt>(Ext1->getOperand(1))->getZExtValue()) &&
          "Expected same constant extract index");
 
   Type *ScalarTy = Ext0->getType();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75327.247313.patch
Type: text/x-patch
Size: 1710 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200228/3d2a2871/attachment.bin>


More information about the llvm-commits mailing list