Skip to content

Commit 94f16e6

Browse files
Rohit AggarwalRohit Aggarwal
authored andcommitted
Code movement to if(IndexWidth > 32) condition
1 parent 7ca7d48 commit 94f16e6

File tree

1 file changed

+39
-38
lines changed

1 file changed

+39
-38
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -56683,49 +56683,50 @@ static SDValue combineGatherScatter(SDNode *N, SelectionDAG &DAG,
5668356683
}
5668456684
unsigned IndexWidth = Index.getScalarValueSizeInBits();
5668556685

56686-
// If the index is a left shift, \ComputeNumSignBits we are recomputing the
56687-
// number of sign bits from the shifted value. We are trying to enable the
56688-
// optimization in which we can shrink indices if they are larger than
56689-
// 32-bits. Using the existing fold techniques implemented below.
56690-
unsigned ComputeNumSignBits = DAG.ComputeNumSignBits(Index);
56691-
if (Index.getOpcode() == ISD::SHL) {
56692-
if (auto MinShAmt = DAG.getValidMinimumShiftAmount(Index)) {
56693-
if (DAG.ComputeNumSignBits(Index.getOperand(0)) > 1) {
56694-
ComputeNumSignBits += *MinShAmt;
56695-
}
56696-
}
56697-
}
56698-
5669956686
// Shrink indices if they are larger than 32-bits.
5670056687
// Only do this before legalize types since v2i64 could become v2i32.
5670156688
// FIXME: We could check that the type is legal if we're after legalize
5670256689
// types, but then we would need to construct test cases where that happens.
5670356690
// \ComputeNumSignBits value is recomputed for the shift Index
56704-
if (IndexWidth > 32 && ComputeNumSignBits > (IndexWidth - 32)) {
56705-
EVT NewVT = IndexVT.changeVectorElementType(MVT::i32);
56706-
56707-
// FIXME: We could support more than just constant fold, but we need to
56708-
// careful with costing. A truncate that can be optimized out would be
56709-
// fine. Otherwise we might only want to create a truncate if it avoids a
56710-
// split.
56711-
if (SDValue TruncIndex =
56712-
DAG.FoldConstantArithmetic(ISD::TRUNCATE, DL, NewVT, Index))
56713-
return rebuildGatherScatter(GorS, TruncIndex, Base, Scale, DAG);
56714-
56715-
// Shrink any sign/zero extends from 32 or smaller to larger than 32 if
56716-
// there are sufficient sign bits. Only do this before legalize types to
56717-
// avoid creating illegal types in truncate.
56718-
if ((Index.getOpcode() == ISD::SIGN_EXTEND ||
56719-
Index.getOpcode() == ISD::ZERO_EXTEND) &&
56720-
Index.getOperand(0).getScalarValueSizeInBits() <= 32) {
56721-
Index = DAG.getNode(ISD::TRUNCATE, DL, NewVT, Index);
56722-
return rebuildGatherScatter(GorS, Index, Base, Scale, DAG);
56723-
}
56724-
56725-
// Shrink if we remove an illegal type.
56726-
if (!TLI.isTypeLegal(Index.getValueType()) && TLI.isTypeLegal(NewVT)) {
56727-
Index = DAG.getNode(ISD::TRUNCATE, DL, NewVT, Index);
56728-
return rebuildGatherScatter(GorS, Index, Base, Scale, DAG);
56691+
if (IndexWidth > 32) {
56692+
// If the index is a left shift, \ComputeNumSignBits we are recomputing
56693+
// the number of sign bits from the shifted value. We are trying to enable
56694+
// the optimization in which we can shrink indices if they are larger than
56695+
// 32-bits. Using the existing fold techniques implemented below.
56696+
unsigned ComputeNumSignBits = DAG.ComputeNumSignBits(Index);
56697+
if (Index.getOpcode() == ISD::SHL) {
56698+
if (auto MinShAmt = DAG.getValidMinimumShiftAmount(Index)) {
56699+
if (DAG.ComputeNumSignBits(Index.getOperand(0)) > 1) {
56700+
ComputeNumSignBits += *MinShAmt;
56701+
}
56702+
}
56703+
}
56704+
if (ComputeNumSignBits > (IndexWidth - 32)) {
56705+
EVT NewVT = IndexVT.changeVectorElementType(MVT::i32);
56706+
56707+
// FIXME: We could support more than just constant fold, but we need to
56708+
// careful with costing. A truncate that can be optimized out would be
56709+
// fine. Otherwise we might only want to create a truncate if it avoids
56710+
// a split.
56711+
if (SDValue TruncIndex =
56712+
DAG.FoldConstantArithmetic(ISD::TRUNCATE, DL, NewVT, Index))
56713+
return rebuildGatherScatter(GorS, TruncIndex, Base, Scale, DAG);
56714+
56715+
// Shrink any sign/zero extends from 32 or smaller to larger than 32 if
56716+
// there are sufficient sign bits. Only do this before legalize types to
56717+
// avoid creating illegal types in truncate.
56718+
if ((Index.getOpcode() == ISD::SIGN_EXTEND ||
56719+
Index.getOpcode() == ISD::ZERO_EXTEND) &&
56720+
Index.getOperand(0).getScalarValueSizeInBits() <= 32) {
56721+
Index = DAG.getNode(ISD::TRUNCATE, DL, NewVT, Index);
56722+
return rebuildGatherScatter(GorS, Index, Base, Scale, DAG);
56723+
}
56724+
56725+
// Shrink if we remove an illegal type.
56726+
if (!TLI.isTypeLegal(Index.getValueType()) && TLI.isTypeLegal(NewVT)) {
56727+
Index = DAG.getNode(ISD::TRUNCATE, DL, NewVT, Index);
56728+
return rebuildGatherScatter(GorS, Index, Base, Scale, DAG);
56729+
}
5672956730
}
5673056731
}
5673156732
}

0 commit comments

Comments
 (0)