Skip to content

Commit 9836917

Browse files
committed
[SelectionDAGBuilder] Don't set MachinePointerInfo for gather when we find a uniform base
I believe we were previously calculating a pointer info with the scalar base and an offset of 0. But that's not really where the gather is pointing. The offset is a function of the indices of the GEP we looked through. Also set the size of the MachineMemOperand to UnknownSize Differential Revision: https://reviews.llvm.org/D76157
1 parent 9e2715a commit 9836917

File tree

1 file changed

+18
-34
lines changed

1 file changed

+18
-34
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4377,7 +4377,7 @@ void SelectionDAGBuilder::visitMaskedStore(const CallInst &I,
43774377
// are looking for. If first operand of the GEP is a splat vector - we
43784378
// extract the splat value and use it as a uniform base.
43794379
// In all other cases the function returns 'false'.
4380-
static bool getUniformBase(const Value *&Ptr, SDValue &Base, SDValue &Index,
4380+
static bool getUniformBase(const Value *Ptr, SDValue &Base, SDValue &Index,
43814381
ISD::MemIndexType &IndexType, SDValue &Scale,
43824382
SelectionDAGBuilder *SDB) {
43834383
SelectionDAG& DAG = SDB->DAG;
@@ -4388,11 +4388,12 @@ static bool getUniformBase(const Value *&Ptr, SDValue &Base, SDValue &Index,
43884388
if (!GEP)
43894389
return false;
43904390

4391-
const Value *GEPPtr = GEP->getPointerOperand();
4392-
if (!GEPPtr->getType()->isVectorTy())
4393-
Ptr = GEPPtr;
4394-
else if (!(Ptr = getSplatValue(GEPPtr)))
4395-
return false;
4391+
const Value *BasePtr = GEP->getPointerOperand();
4392+
if (BasePtr->getType()->isVectorTy()) {
4393+
BasePtr = getSplatValue(BasePtr);
4394+
if (!BasePtr)
4395+
return false;
4396+
}
43964397

43974398
unsigned FinalIndex = GEP->getNumOperands() - 1;
43984399
Value *IndexVal = GEP->getOperand(FinalIndex);
@@ -4412,7 +4413,7 @@ static bool getUniformBase(const Value *&Ptr, SDValue &Base, SDValue &Index,
44124413

44134414
// The operands of the GEP may be defined in another basic block.
44144415
// In this case we'll not find nodes for the operands.
4415-
if (!SDB->findValue(Ptr))
4416+
if (!SDB->findValue(BasePtr))
44164417
return false;
44174418
Constant *C = dyn_cast<Constant>(IndexVal);
44184419
if (!C && !SDB->findValue(IndexVal))
@@ -4434,7 +4435,7 @@ static bool getUniformBase(const Value *&Ptr, SDValue &Base, SDValue &Index,
44344435
SDB->getCurSDLoc(), TLI.getPointerTy(DL));
44354436
Index = SDB->getValue(IndexVal);
44364437
}
4437-
Base = SDB->getValue(Ptr);
4438+
Base = SDB->getValue(BasePtr);
44384439
IndexType = ISD::SIGNED_SCALED;
44394440

44404441
if (STy || !Index.getValueType().isVector()) {
@@ -4465,17 +4466,15 @@ void SelectionDAGBuilder::visitMaskedScatter(const CallInst &I) {
44654466
SDValue Index;
44664467
ISD::MemIndexType IndexType;
44674468
SDValue Scale;
4468-
const Value *BasePtr = Ptr;
4469-
bool UniformBase = getUniformBase(BasePtr, Base, Index, IndexType, Scale,
4470-
this);
4469+
bool UniformBase = getUniformBase(Ptr, Base, Index, IndexType, Scale, this);
44714470

4472-
const Value *MemOpBasePtr = UniformBase ? BasePtr : nullptr;
4471+
unsigned AS = Ptr->getType()->getScalarType()->getPointerAddressSpace();
44734472
MachineMemOperand *MMO = DAG.getMachineFunction().
4474-
getMachineMemOperand(MachinePointerInfo(MemOpBasePtr),
4473+
getMachineMemOperand(MachinePointerInfo(AS),
44754474
MachineMemOperand::MOStore,
44764475
// TODO: Make MachineMemOperands aware of scalable
44774476
// vectors.
4478-
VT.getStoreSize().getKnownMinSize(),
4477+
MemoryLocation::UnknownSize,
44794478
Alignment, AAInfo);
44804479
if (!UniformBase) {
44814480
Base = DAG.getConstant(0, sdl, TLI.getPointerTy(DAG.getDataLayout()));
@@ -4582,28 +4581,15 @@ void SelectionDAGBuilder::visitMaskedGather(const CallInst &I) {
45824581
SDValue Index;
45834582
ISD::MemIndexType IndexType;
45844583
SDValue Scale;
4585-
const Value *BasePtr = Ptr;
4586-
bool UniformBase = getUniformBase(BasePtr, Base, Index, IndexType, Scale,
4587-
this);
4588-
bool ConstantMemory = false;
4589-
if (UniformBase && AA &&
4590-
AA->pointsToConstantMemory(
4591-
MemoryLocation(BasePtr,
4592-
LocationSize::precise(
4593-
DAG.getDataLayout().getTypeStoreSize(I.getType())),
4594-
AAInfo))) {
4595-
// Do not serialize (non-volatile) loads of constant memory with anything.
4596-
Root = DAG.getEntryNode();
4597-
ConstantMemory = true;
4598-
}
4599-
4584+
bool UniformBase = getUniformBase(Ptr, Base, Index, IndexType, Scale, this);
4585+
unsigned AS = Ptr->getType()->getScalarType()->getPointerAddressSpace();
46004586
MachineMemOperand *MMO =
46014587
DAG.getMachineFunction().
4602-
getMachineMemOperand(MachinePointerInfo(UniformBase ? BasePtr : nullptr),
4588+
getMachineMemOperand(MachinePointerInfo(AS),
46034589
MachineMemOperand::MOLoad,
46044590
// TODO: Make MachineMemOperands aware of scalable
46054591
// vectors.
4606-
VT.getStoreSize().getKnownMinSize(),
4592+
MemoryLocation::UnknownSize,
46074593
Alignment, AAInfo, Ranges);
46084594

46094595
if (!UniformBase) {
@@ -4616,9 +4602,7 @@ void SelectionDAGBuilder::visitMaskedGather(const CallInst &I) {
46164602
SDValue Gather = DAG.getMaskedGather(DAG.getVTList(VT, MVT::Other), VT, sdl,
46174603
Ops, MMO, IndexType);
46184604

4619-
SDValue OutChain = Gather.getValue(1);
4620-
if (!ConstantMemory)
4621-
PendingLoads.push_back(OutChain);
4605+
PendingLoads.push_back(Gather.getValue(1));
46224606
setValue(&I, Gather);
46234607
}
46244608

0 commit comments

Comments
 (0)