[VectorCombine] Fix assert on compare extract index

Extract index could be a differnet integral type.

Differential Revision: https://reviews.llvm.org/D75327
This commit is contained in:
Austin Kerbow 2020-02-28 10:08:59 -08:00
parent b4b4259a49
commit 4fa63fd452
2 changed files with 17 additions and 2 deletions

View File

@ -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();

View File

@ -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 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