Skip to content

Commit da1978a

Browse files
committed
fix wrong boundary check
1 parent 58ac80b commit da1978a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,8 @@ bool VectorCombine::foldInsExtFNeg(Instruction &I) {
689689
// one element
690690
unsigned NumDstElts = DstVecTy->getNumElements();
691691
unsigned NumSrcElts = SrcVecTy->getNumElements();
692-
if (InsIdx >= NumDstElts || ExtIdx >= NumSrcElts || NumDstElts == 1)
692+
if (ExtIdx > NumSrcElts || InsIdx >= NumDstElts ||
693+
NumDstElts == 1)
693694
return false;
694695

695696
// We are inserting the negated element into the same lane that we extracted

llvm/test/Transforms/VectorCombine/X86/extract-fneg-insert.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ define <4 x float> @ext2_v4f32(<4 x float> %x, <4 x float> %y) {
4747

4848
define <4 x float> @ext2_v2f32v4f32(<2 x float> %x, <4 x float> %y) {
4949
; CHECK-LABEL: @ext2_v2f32v4f32(
50-
; CHECK-NEXT: [[E:%.*]] = extractelement <2 x float> [[X:%.*]], i32 2
51-
; CHECK-NEXT: [[N:%.*]] = fneg float [[E]]
52-
; CHECK-NEXT: [[R:%.*]] = insertelement <4 x float> [[Y:%.*]], float [[N]], i32 2
50+
; CHECK-NEXT: [[TMP1:%.*]] = fneg <2 x float> [[X:%.*]]
51+
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> poison, <4 x i32> <i32 poison, i32 poison, i32 2, i32 poison>
52+
; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[Y:%.*]], <4 x float> [[TMP2]], <4 x i32> <i32 0, i32 1, i32 6, i32 3>
5353
; CHECK-NEXT: ret <4 x float> [[R]]
5454
;
5555
%e = extractelement <2 x float> %x, i32 2

0 commit comments

Comments
 (0)