Skip to content

Commit d5cfde7

Browse files
committed
[X86] Fix arithmetic error in extractVector
The computation of the element count for the result VT in extractVector is incorrect when vector width does not divide VT.getSizeInBits(), which can occur when the source vector element count is not a power of two, e.g. extracting a vectorWidth 256b vector from a 384b source. This rewrites the expression so the division is exact given that vectorWidth is a multiple of the source element size.
1 parent be51ef4 commit d5cfde7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4066,6 +4066,10 @@ static SDValue extractSubVector(SDValue Vec, unsigned IdxVal, SelectionDAG &DAG,
40664066
const SDLoc &dl, unsigned vectorWidth) {
40674067
EVT VT = Vec.getValueType();
40684068
EVT ElVT = VT.getVectorElementType();
4069+
unsigned ResultNumElts =
4070+
(VT.getVectorNumElements() * vectorWidth) / VT.getSizeInBits();
4071+
EVT ResultVT = EVT::getVectorVT(*DAG.getContext(), ElVT, ResultNumElts);
4072+
40694073
unsigned Factor = VT.getSizeInBits() / vectorWidth;
40704074
EVT ResultVT = EVT::getVectorVT(*DAG.getContext(), ElVT,
40714075
VT.getVectorNumElements() / Factor);

0 commit comments

Comments
 (0)