[llvm] [X86] Fix arithmetic error in extractVector (PR #128052)
Daniel Zabawa via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 20 11:22:27 PST 2025
https://github.com/daniel-zabawa created https://github.com/llvm/llvm-project/pull/128052
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.
>From d5cfde70d4037c25704387d3abf8bdc24101d4ea Mon Sep 17 00:00:00 2001
From: "Zabawa, Daniel" <daniel.zabawa at intel.com>
Date: Thu, 20 Feb 2025 11:09:40 -0800
Subject: [PATCH] [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.
---
llvm/lib/Target/X86/X86ISelLowering.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 1c9d43ce4c062..b7a49bf3e32f6 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -4066,6 +4066,10 @@ static SDValue extractSubVector(SDValue Vec, unsigned IdxVal, SelectionDAG &DAG,
const SDLoc &dl, unsigned vectorWidth) {
EVT VT = Vec.getValueType();
EVT ElVT = VT.getVectorElementType();
+ unsigned ResultNumElts =
+ (VT.getVectorNumElements() * vectorWidth) / VT.getSizeInBits();
+ EVT ResultVT = EVT::getVectorVT(*DAG.getContext(), ElVT, ResultNumElts);
+
unsigned Factor = VT.getSizeInBits() / vectorWidth;
EVT ResultVT = EVT::getVectorVT(*DAG.getContext(), ElVT,
VT.getVectorNumElements() / Factor);
More information about the llvm-commits
mailing list