[llvm] 890beda - [X86] combineArithReduction - pull out (near) duplicate v4i8/v8i8 widening code. NFC.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 13 13:03:04 PST 2022
Author: Simon Pilgrim
Date: 2022-02-13T21:02:50Z
New Revision: 890beda4e1794f8b5cf13d3fcd158c37b65c684e
URL: https://github.com/llvm/llvm-project/commit/890beda4e1794f8b5cf13d3fcd158c37b65c684e
DIFF: https://github.com/llvm/llvm-project/commit/890beda4e1794f8b5cf13d3fcd158c37b65c684e.diff
LOG: [X86] combineArithReduction - pull out (near) duplicate v4i8/v8i8 widening code. NFC.
Added:
Modified:
llvm/lib/Target/X86/X86ISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 8d43afb9cde11..3366b45615bab 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -42964,6 +42964,24 @@ static SDValue combineArithReduction(SDNode *ExtElt, SelectionDAG &DAG,
SDLoc DL(ExtElt);
+ // Extend v4i8/v8i8 vector to v16i8, with undef upper 64-bits.
+ auto WidenToV16I8 = [&](SDValue V, bool ZeroExtend) {
+ if (VecVT == MVT::v4i8) {
+ if (ZeroExtend && Subtarget.hasSSE41()) {
+ V = DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, MVT::v4i32,
+ DAG.getConstant(0, DL, MVT::v4i32),
+ DAG.getBitcast(MVT::i32, V),
+ DAG.getIntPtrConstant(0, DL));
+ return DAG.getBitcast(MVT::v16i8, V);
+ }
+ V = DAG.getNode(ISD::CONCAT_VECTORS, DL, MVT::v8i8, V,
+ ZeroExtend ? DAG.getConstant(0, DL, MVT::v4i8)
+ : DAG.getUNDEF(MVT::v4i8));
+ }
+ return DAG.getNode(ISD::CONCAT_VECTORS, DL, MVT::v16i8, V,
+ DAG.getUNDEF(MVT::v8i8));
+ };
+
// vXi8 mul reduction - promote to vXi16 mul reduction.
if (Opc == ISD::MUL) {
unsigned NumElts = VecVT.getVectorNumElements();
@@ -42981,11 +42999,7 @@ static SDValue combineArithReduction(SDNode *ExtElt, SelectionDAG &DAG,
Rdx = DAG.getNode(Opc, DL, Lo.getValueType(), Lo, Hi);
}
} else {
- if (VecVT == MVT::v4i8)
- Rdx = DAG.getNode(ISD::CONCAT_VECTORS, DL, MVT::v8i8, Rdx,
- DAG.getUNDEF(MVT::v4i8));
- Rdx = DAG.getNode(ISD::CONCAT_VECTORS, DL, MVT::v16i8, Rdx,
- DAG.getUNDEF(MVT::v8i8));
+ Rdx = WidenToV16I8(Rdx, false);
Rdx = getUnpackl(DAG, DL, MVT::v16i8, Rdx, DAG.getUNDEF(MVT::v16i8));
Rdx = DAG.getBitcast(MVT::v8i16, Rdx);
}
@@ -43005,24 +43019,7 @@ static SDValue combineArithReduction(SDNode *ExtElt, SelectionDAG &DAG,
// vXi8 add reduction - sub 128-bit vector.
if (VecVT == MVT::v4i8 || VecVT == MVT::v8i8) {
- if (VecVT == MVT::v4i8) {
- // Pad with zero.
- if (Subtarget.hasSSE41()) {
- Rdx = DAG.getBitcast(MVT::i32, Rdx);
- Rdx = DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, MVT::v4i32,
- DAG.getConstant(0, DL, MVT::v4i32), Rdx,
- DAG.getIntPtrConstant(0, DL));
- Rdx = DAG.getBitcast(MVT::v16i8, Rdx);
- } else {
- Rdx = DAG.getNode(ISD::CONCAT_VECTORS, DL, MVT::v8i8, Rdx,
- DAG.getConstant(0, DL, VecVT));
- }
- }
- if (Rdx.getValueType() == MVT::v8i8) {
- // Pad with undef.
- Rdx = DAG.getNode(ISD::CONCAT_VECTORS, DL, MVT::v16i8, Rdx,
- DAG.getUNDEF(MVT::v8i8));
- }
+ Rdx = WidenToV16I8(Rdx, true);
Rdx = DAG.getNode(X86ISD::PSADBW, DL, MVT::v2i64, Rdx,
DAG.getConstant(0, DL, MVT::v16i8));
Rdx = DAG.getBitcast(MVT::v16i8, Rdx);
More information about the llvm-commits
mailing list