[llvm] 4fa63fd - [VectorCombine] Fix assert on compare extract index

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


Author: Austin Kerbow
Date: 2020-02-28T10:37:08-08:00
New Revision: 4fa63fd4524c9818dab2fc0d3ea3a8d65d3bc22b

URL: https://github.com/llvm/llvm-project/commit/4fa63fd4524c9818dab2fc0d3ea3a8d65d3bc22b
DIFF: https://github.com/llvm/llvm-project/commit/4fa63fd4524c9818dab2fc0d3ea3a8d65d3bc22b.diff

LOG: [VectorCombine] Fix assert on compare extract index

Extract index could be a differnet integral type.

Differential Revision: https://reviews.llvm.org/D75327

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index 76c63dd23850..ed7415d45c31 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -46,8 +46,9 @@ static cl::opt<bool> DisableVectorCombine(
 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();

diff  --git a/llvm/test/Transforms/VectorCombine/X86/extract-binop.ll b/llvm/test/Transforms/VectorCombine/X86/extract-binop.ll
index 30d0475437bd..078cf7b02cf4 100644
--- a/llvm/test/Transforms/VectorCombine/X86/extract-binop.ll
+++ b/llvm/test/Transforms/VectorCombine/X86/extract-binop.ll
@@ -147,6 +147,20 @@ define i32 @ext1_ext1_add_same_vec_cse(<4 x i32> %x) {
   ret i32 %r
 }
 
+; Don't assert if extract indices have 
diff erent 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


        


More information about the llvm-commits mailing list