Skip to content

Commit 2b79bbe

Browse files
Rohit AggarwalRohit Aggarwal
authored andcommitted
Handle the case for gather where index is SHL
1 parent 4f107cd commit 2b79bbe

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56710,12 +56710,23 @@ static SDValue combineGatherScatter(SDNode *N, SelectionDAG &DAG,
5671056710

5671156711
if (DCI.isBeforeLegalize()) {
5671256712
unsigned IndexWidth = Index.getScalarValueSizeInBits();
56713-
56713+
// If the index is a left shift, \ComputeNumSignBits we are recomputing
56714+
// the number of sign bits from the shifted value. We are trying to enable
56715+
// the optimization in which we can shrink indices if they are larger than
56716+
// 32-bits. Using the existing fold techniques implemented below.
56717+
unsigned ComputeNumSignBits = DAG.ComputeNumSignBits(Index);
56718+
if (Index.getOpcode() == ISD::SHL) {
56719+
if (auto MinShAmt = DAG.getValidMinimumShiftAmount(Index)) {
56720+
if (DAG.ComputeNumSignBits(Index.getOperand(0)) > 1) {
56721+
ComputeNumSignBits += *MinShAmt;
56722+
}
56723+
}
56724+
}
5671456725
// Shrink indices if they are larger than 32-bits.
5671556726
// Only do this before legalize types since v2i64 could become v2i32.
5671656727
// FIXME: We could check that the type is legal if we're after legalize
5671756728
// types, but then we would need to construct test cases where that happens.
56718-
if (IndexWidth > 32 && DAG.ComputeNumSignBits(Index) > (IndexWidth - 32)) {
56729+
if (IndexWidth > 32 && ComputeNumSignBits > (IndexWidth - 32)) {
5671956730
EVT NewVT = IndexVT.changeVectorElementType(MVT::i32);
5672056731

5672156732
// FIXME: We could support more than just constant fold, but we need to

0 commit comments

Comments
 (0)