Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,11 @@ Instruction *InstCombinerImpl::visitExtractElementInst(ExtractElementInst &EI) {
else
Idx = PoisonValue::get(Ty);
return replaceInstUsesWith(EI, Idx);
}
} else if (IID == Intrinsic::vector_extract)
// If II is a subvector starting at index 0, extract from the wider
// source vector
if (cast<ConstantInt>(II->getArgOperand(1))->getZExtValue() == 0)
return ExtractElementInst::Create(II->getArgOperand(0), Index);
}

// InstSimplify should handle cases where the index is invalid.
Expand Down
13 changes: 13 additions & 0 deletions llvm/test/Transforms/InstCombine/scalable-extract-subvec-elt.ll
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a negative test with non-zero vector.extract?

Also test a variable index extract?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @nikic, while adding a variable index test I realised this case wasn't handled.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -S -passes=instcombine < %s | FileCheck %s

define i1 @scalable_test(<vscale x 4 x i1> %a) {
; CHECK-LABEL: define i1 @scalable_test(
; CHECK-SAME: <vscale x 4 x i1> [[A:%.*]]) {
; CHECK-NEXT: [[ELT:%.*]] = extractelement <vscale x 4 x i1> [[A]], i64 1
; CHECK-NEXT: ret i1 [[ELT]]
;
%subvec = call <vscale x 2 x i1> @llvm.vector.extract.nxv2i1.nxv4i1.i64(<vscale x 4 x i1> %a, i64 0)
%elt = extractelement <vscale x 2 x i1> %subvec, i32 1
ret i1 %elt
}