Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15274,6 +15274,50 @@ static SDValue reverseZExtICmpCombine(SDNode *N, SelectionDAG &DAG,
return DAG.getNode(ISD::ZERO_EXTEND, DL, VT, Res);
}

static SDValue reduceANDOfAtomicLoad(SDNode *N,
TargetLowering::DAGCombinerInfo &DCI) {
SelectionDAG &DAG = DCI.DAG;
if (N->getOpcode() != ISD::AND)
return SDValue();

SDValue N0 = N->getOperand(0);
if (N0.getOpcode() != ISD::ATOMIC_LOAD)
return SDValue();
if (!N0.hasOneUse())
return SDValue();

AtomicSDNode *ALoad = cast<AtomicSDNode>(N0.getNode());
if (isStrongerThanMonotonic(ALoad->getSuccessOrdering()))
return SDValue();

EVT LoadedVT = ALoad->getMemoryVT();
EVT ResultVT = N->getValueType(0);

SDValue MaskVal = N->getOperand(1);
ConstantSDNode *MaskConst = dyn_cast<ConstantSDNode>(MaskVal);
if (!MaskConst)
return SDValue();
uint64_t Mask = MaskConst->getZExtValue();
uint64_t ExpectedMask = LoadedVT.getSizeInBits() == 8 ? 0xFF
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use maskTrailingOnes<uint64_t>(LoadedVT.getSizeInBits())?

: LoadedVT.getSizeInBits() == 16 ? 0xFFFF
: LoadedVT.getSizeInBits() == 32 ? 0xFFFFFFFF
: 0xFFFFFFFFFFFFFFFF;
if (Mask != ExpectedMask)
return SDValue();

SDLoc DL(N);
SDValue Chain = ALoad->getChain();
SDValue Ptr = ALoad->getBasePtr();
MachineMemOperand *MemOp = ALoad->getMemOperand();
SDValue ZextLoad = DAG.getExtLoad(ISD::ZEXTLOAD, DL, ResultVT, Chain, Ptr,
MemOp->getPointerInfo(), LoadedVT,
MemOp->getAlign(), MemOp->getFlags());
DCI.CombineTo(N, ZextLoad);
DAG.ReplaceAllUsesOfValueWith(SDValue(N0.getNode(), 1), ZextLoad.getValue(1));
DCI.recursivelyDeleteUnusedNodes(N0.getNode());
return SDValue(N, 0);
}

// Combines two comparison operation and logic operation to one selection
// operation(min, max) and logic operation. Returns new constructed Node if
// conditions for optimization are satisfied.
Expand Down Expand Up @@ -15308,6 +15352,8 @@ static SDValue performANDCombine(SDNode *N,
return V;
if (SDValue V = combineBinOpOfExtractToReduceTree(N, DAG, Subtarget))
return V;
if (SDValue V = reduceANDOfAtomicLoad(N, DCI))
return V;

if (DCI.isAfterLegalizeDAG())
if (SDValue V = combineDeMorganOfBoolean(N, DAG))
Expand Down
Loading
Loading