[llvm] 79fec2f - [AtomicExpand][RISCV] Call shouldExpandAtomicRMWInIR before widenPartwordAtomicRMW (#80947)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 7 08:24:53 PST 2024
Author: Craig Topper
Date: 2024-02-07T08:24:50-08:00
New Revision: 79fec2f8ba8ea0b0b1c2f13fb6355cb395e1d3af
URL: https://github.com/llvm/llvm-project/commit/79fec2f8ba8ea0b0b1c2f13fb6355cb395e1d3af
DIFF: https://github.com/llvm/llvm-project/commit/79fec2f8ba8ea0b0b1c2f13fb6355cb395e1d3af.diff
LOG: [AtomicExpand][RISCV] Call shouldExpandAtomicRMWInIR before widenPartwordAtomicRMW (#80947)
This gives the target a chance to keep an atomicrmw op that is smaller
than the minimum cmpxchg size. This is needed to support the Zabha
extension for RISC-V which provides i8/i16 atomicrmw operations, but
does not provide an i8/i16 cmpxchg or LR/SC instructions.
This moves the widening until after the target requests
LLSC/CmpXChg/MaskedIntrinsic expansion. Once we widen, we call
shouldExpandAtomicRMWInIR again to give the target another chance to
make a decision about the widened operation.
I considered making the targets return AtomicExpansionKind::Expand or a
new expansion kind for And/Or/Xor, but that required the targets to
special case And/Or/Xor which they weren't currently doing.
Added:
Modified:
llvm/lib/CodeGen/AtomicExpandPass.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AtomicExpandPass.cpp b/llvm/lib/CodeGen/AtomicExpandPass.cpp
index ccf3e9ec649210..faa3edb2b03c88 100644
--- a/llvm/lib/CodeGen/AtomicExpandPass.cpp
+++ b/llvm/lib/CodeGen/AtomicExpandPass.cpp
@@ -322,16 +322,6 @@ bool AtomicExpand::runOnFunction(Function &F) {
if (isIdempotentRMW(RMWI) && simplifyIdempotentRMW(RMWI)) {
MadeChange = true;
} else {
- AtomicRMWInst::BinOp Op = RMWI->getOperation();
- unsigned MinCASSize = TLI->getMinCmpXchgSizeInBits() / 8;
- unsigned ValueSize = getAtomicOpSize(RMWI);
- if (ValueSize < MinCASSize &&
- (Op == AtomicRMWInst::Or || Op == AtomicRMWInst::Xor ||
- Op == AtomicRMWInst::And)) {
- RMWI = widenPartwordAtomicRMW(RMWI);
- MadeChange = true;
- }
-
MadeChange |= tryExpandAtomicRMW(RMWI);
}
} else if (CASI)
@@ -607,6 +597,17 @@ bool AtomicExpand::tryExpandAtomicRMW(AtomicRMWInst *AI) {
return true;
}
case TargetLoweringBase::AtomicExpansionKind::MaskedIntrinsic: {
+ unsigned MinCASSize = TLI->getMinCmpXchgSizeInBits() / 8;
+ unsigned ValueSize = getAtomicOpSize(AI);
+ if (ValueSize < MinCASSize) {
+ AtomicRMWInst::BinOp Op = AI->getOperation();
+ // Widen And/Or/Xor and give the target another chance at expanding it.
+ if (Op == AtomicRMWInst::Or || Op == AtomicRMWInst::Xor ||
+ Op == AtomicRMWInst::And) {
+ tryExpandAtomicRMW(widenPartwordAtomicRMW(AI));
+ return true;
+ }
+ }
expandAtomicRMWToMaskedIntrinsic(AI);
return true;
}
@@ -845,6 +846,14 @@ static Value *performMaskedAtomicOp(AtomicRMWInst::BinOp Op,
/// part of the value.
void AtomicExpand::expandPartwordAtomicRMW(
AtomicRMWInst *AI, TargetLoweringBase::AtomicExpansionKind ExpansionKind) {
+ // Widen And/Or/Xor and give the target another chance at expanding it.
+ AtomicRMWInst::BinOp Op = AI->getOperation();
+ if (Op == AtomicRMWInst::Or || Op == AtomicRMWInst::Xor ||
+ Op == AtomicRMWInst::And) {
+ tryExpandAtomicRMW(widenPartwordAtomicRMW(AI));
+ return;
+ }
+
AtomicOrdering MemOpOrder = AI->getOrdering();
SyncScope::ID SSID = AI->getSyncScopeID();
@@ -855,18 +864,16 @@ void AtomicExpand::expandPartwordAtomicRMW(
AI->getAlign(), TLI->getMinCmpXchgSizeInBits() / 8);
Value *ValOperand_Shifted = nullptr;
- if (AI->getOperation() == AtomicRMWInst::Xchg ||
- AI->getOperation() == AtomicRMWInst::Add ||
- AI->getOperation() == AtomicRMWInst::Sub ||
- AI->getOperation() == AtomicRMWInst::Nand) {
+ if (Op == AtomicRMWInst::Xchg || Op == AtomicRMWInst::Add ||
+ Op == AtomicRMWInst::Sub || Op == AtomicRMWInst::Nand) {
ValOperand_Shifted =
Builder.CreateShl(Builder.CreateZExt(AI->getValOperand(), PMV.WordType),
PMV.ShiftAmt, "ValOperand_Shifted");
}
auto PerformPartwordOp = [&](IRBuilderBase &Builder, Value *Loaded) {
- return performMaskedAtomicOp(AI->getOperation(), Builder, Loaded,
- ValOperand_Shifted, AI->getValOperand(), PMV);
+ return performMaskedAtomicOp(Op, Builder, Loaded, ValOperand_Shifted,
+ AI->getValOperand(), PMV);
};
Value *OldResult;
More information about the llvm-commits
mailing list