Skip to content

Commit f972985

Browse files
authored
[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.
1 parent 3133c95 commit f972985

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56529,16 +56529,13 @@ static SDValue combineGatherScatter(SDNode *N, SelectionDAG &DAG,
5652956529
if (IndexWidth > 32 && DAG.ComputeNumSignBits(Index) > (IndexWidth - 32)) {
5653056530
EVT NewVT = IndexVT.changeVectorElementType(MVT::i32);
5653156531

56532-
// FIXME: We could support more than just constant vectors, but we need to
56532+
// FIXME: We could support more than just constant fold, but we need to
5653356533
// careful with costing. A truncate that can be optimized out would be
5653456534
// fine. Otherwise we might only want to create a truncate if it avoids a
5653556535
// split.
56536-
if (auto *BV = dyn_cast<BuildVectorSDNode>(Index)) {
56537-
if (BV->isConstant()) {
56538-
Index = DAG.getNode(ISD::TRUNCATE, DL, NewVT, Index);
56539-
return rebuildGatherScatter(GorS, Index, Base, Scale, DAG);
56540-
}
56541-
}
56536+
if (SDValue TruncIndex =
56537+
DAG.FoldConstantArithmetic(ISD::TRUNCATE, DL, NewVT, Index))
56538+
return rebuildGatherScatter(GorS, TruncIndex, Base, Scale, DAG);
5654256539

5654356540
// Shrink any sign/zero extends from 32 or smaller to larger than 32 if
5654456541
// there are sufficient sign bits. Only do this before legalize types to

0 commit comments

Comments
 (0)