Skip to content

Commit

Permalink
[X86] Add calculation for elements in structures in getting uniform b…
Browse files Browse the repository at this point in the history
…ase for the Gather/Scatter intrinsic.

Summary: Add calculation for elements in structures in getting uniform
base for the Gather/Scatter intrinsic.

Reviewers: craig.topper, c-rhodes, RKSimon

Subscribers: hiraditya, llvm-commits, annita.zhang, LuoYuanke

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D71442
  • Loading branch information
phoebewang committed Dec 18, 2019
1 parent 1949235 commit 8cc0b58
Show file tree
Hide file tree
Showing 2 changed files with 763 additions and 6 deletions.
34 changes: 28 additions & 6 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Expand Up @@ -4353,9 +4353,10 @@ static bool getUniformBase(const Value *&Ptr, SDValue &Base, SDValue &Index,

unsigned FinalIndex = GEP->getNumOperands() - 1;
Value *IndexVal = GEP->getOperand(FinalIndex);
gep_type_iterator GTI = gep_type_begin(*GEP);

// Ensure all the other indices are 0.
for (unsigned i = 1; i < FinalIndex; ++i) {
for (unsigned i = 1; i < FinalIndex; ++i, ++GTI) {
auto *C = dyn_cast<Constant>(GEP->getOperand(i));
if (!C)
return false;
Expand All @@ -4368,18 +4369,39 @@ static bool getUniformBase(const Value *&Ptr, SDValue &Base, SDValue &Index,

// The operands of the GEP may be defined in another basic block.
// In this case we'll not find nodes for the operands.
if (!SDB->findValue(Ptr) || !SDB->findValue(IndexVal))
if (!SDB->findValue(Ptr))
return false;
Constant *C = dyn_cast<Constant>(IndexVal);
if (!C && !SDB->findValue(IndexVal))
return false;

const TargetLowering &TLI = DAG.getTargetLoweringInfo();
const DataLayout &DL = DAG.getDataLayout();
Scale = DAG.getTargetConstant(DL.getTypeAllocSize(GEP->getResultElementType()),
SDB->getCurSDLoc(), TLI.getPointerTy(DL));
StructType *STy = GTI.getStructTypeOrNull();

if (STy) {
const StructLayout *SL = DL.getStructLayout(STy);
if (isa<VectorType>(C->getType())) {
C = C->getSplatValue();
// FIXME: If getSplatValue may return nullptr for a structure?
// If not, the following check can be removed.
if (!C)
return false;
}
auto *CI = cast<ConstantInt>(C);
Scale = DAG.getTargetConstant(1, SDB->getCurSDLoc(), TLI.getPointerTy(DL));
Index = DAG.getTargetConstant(SL->getElementOffset(CI->getZExtValue()),
SDB->getCurSDLoc(), TLI.getPointerTy(DL));
} else {
Scale = DAG.getTargetConstant(
DL.getTypeAllocSize(GEP->getResultElementType()),
SDB->getCurSDLoc(), TLI.getPointerTy(DL));
Index = SDB->getValue(IndexVal);
}
Base = SDB->getValue(Ptr);
Index = SDB->getValue(IndexVal);
IndexType = ISD::SIGNED_SCALED;

if (!Index.getValueType().isVector()) {
if (STy || !Index.getValueType().isVector()) {
unsigned GEPWidth = GEP->getType()->getVectorNumElements();
EVT VT = EVT::getVectorVT(Context, Index.getValueType(), GEPWidth);
Index = DAG.getSplatBuildVector(VT, SDLoc(Index), Index);
Expand Down

0 comments on commit 8cc0b58

Please sign in to comment.