-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[RISCV] Remove AND mask generated by ( zext ( atomic_load ) ) by replacing the load with zextload for orderings not stronger then monotonic.
#136502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
9678b8e
22bf5ce
ee4d0c0
c149a41
ec3df98
fbdbcf7
14f212e
9c794c5
9537656
a1d2098
ce6f04f
c969abf
78ecf8a
769d14f
5c55d98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15267,6 +15267,48 @@ 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(); | ||
|
|
||
| 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 | ||
| : 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()); | ||
| DAG.ReplaceAllUsesOfValueWith(SDValue(N, 0), 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. | ||
|
|
@@ -15301,6 +15343,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)) | ||
|
|
||
There was a problem hiding this comment.
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())?