[llvm] f972985 - [X86] combineGatherScatter - use FoldConstantArithmetic for truncation of constant build vectors (#136033)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 17 10:40:52 PDT 2025
Author: Simon Pilgrim
Date: 2025-04-17T18:40:48+01:00
New Revision: f9729859446180c1f0afc386513f7476f5f220e0
URL: https://github.com/llvm/llvm-project/commit/f9729859446180c1f0afc386513f7476f5f220e0
DIFF: https://github.com/llvm/llvm-project/commit/f9729859446180c1f0afc386513f7476f5f220e0.diff
LOG: [X86] combineGatherScatter - use FoldConstantArithmetic for truncation of constant build vectors (#136033)
No need to explicitly check with BuildVectorSDNode::isConstant - FoldConstantArithmetic can handle this, including through bitcasts etc.
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 3adeb4628eabf..024b653f78cb5 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -56529,16 +56529,13 @@ static SDValue combineGatherScatter(SDNode *N, SelectionDAG &DAG,
if (IndexWidth > 32 && DAG.ComputeNumSignBits(Index) > (IndexWidth - 32)) {
EVT NewVT = IndexVT.changeVectorElementType(MVT::i32);
- // FIXME: We could support more than just constant vectors, but we need to
+ // FIXME: We could support more than just constant fold, but we need to
// careful with costing. A truncate that can be optimized out would be
// fine. Otherwise we might only want to create a truncate if it avoids a
// split.
- if (auto *BV = dyn_cast<BuildVectorSDNode>(Index)) {
- if (BV->isConstant()) {
- Index = DAG.getNode(ISD::TRUNCATE, DL, NewVT, Index);
- return rebuildGatherScatter(GorS, Index, Base, Scale, DAG);
- }
- }
+ if (SDValue TruncIndex =
+ DAG.FoldConstantArithmetic(ISD::TRUNCATE, DL, NewVT, Index))
+ return rebuildGatherScatter(GorS, TruncIndex, Base, Scale, DAG);
// Shrink any sign/zero extends from 32 or smaller to larger than 32 if
// there are sufficient sign bits. Only do this before legalize types to
More information about the llvm-commits
mailing list