[PATCH] D125512: [NVPTX] Enable AtomicExpandPass for NVPTX, and add the check for atomicrmw
Shilei Tian via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 12 19:33:33 PDT 2022
tianshilei1992 created this revision.
tianshilei1992 added reviewers: jdoerfert, tra.
Herald added subscribers: mattd, gchakrabarti, asavonic, hiraditya, jholewinski.
Herald added a project: All.
tianshilei1992 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This patch enables `AtomicExpandPass` for NVPTX, and also adds the check
for whether `atomicrmw` should be expanded because NVPTX cannot support all of
them apparently.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D125512
Files:
llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
llvm/lib/Target/NVPTX/NVPTXISelLowering.h
llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
Index: llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
===================================================================
--- llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
+++ llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
@@ -330,6 +330,8 @@
addStraightLineScalarOptimizationPasses();
}
+ addPass(createAtomicExpandPass());
+
// === LSR and other generic IR passes ===
TargetPassConfig::addIRPasses();
// EarlyCSE is not always strong enough to clean up what LSR produces. For
Index: llvm/lib/Target/NVPTX/NVPTXISelLowering.h
===================================================================
--- llvm/lib/Target/NVPTX/NVPTXISelLowering.h
+++ llvm/lib/Target/NVPTX/NVPTXISelLowering.h
@@ -561,6 +561,9 @@
// instruction, so we say that ctlz is cheap to speculate.
bool isCheapToSpeculateCtlz() const override { return true; }
+ AtomicExpansionKind
+ shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override;
+
private:
const NVPTXSubtarget &STI; // cache the subtarget here
SDValue getParamSymbol(SelectionDAG &DAG, int idx, EVT) const;
Index: llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
===================================================================
--- llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
+++ llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
@@ -5125,6 +5125,46 @@
}
}
+NVPTXTargetLowering::AtomicExpansionKind
+NVPTXTargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const {
+ Type *Ty = AI->getValOperand()->getType();
+ if (AI->isFloatingPointOperation()) {
+ if (AI->getOperation() == AtomicRMWInst::BinOp::FAdd) {
+ if (Ty->isFloatTy())
+ return AtomicExpansionKind::None;
+ if (Ty->isDoubleTy() && STI.hasAtomAddF64())
+ return AtomicExpansionKind::None;
+ }
+ return AtomicExpansionKind::CmpXChg;
+ }
+
+ switch (AI->getOperation()) {
+ default:
+ return AtomicExpansionKind::CmpXChg;
+ case AtomicRMWInst::BinOp::Add:
+ case AtomicRMWInst::BinOp::Sub:
+ case AtomicRMWInst::BinOp::Max:
+ case AtomicRMWInst::BinOp::Min:
+ case AtomicRMWInst::BinOp::UMax:
+ case AtomicRMWInst::BinOp::UMin:
+ case AtomicRMWInst::BinOp::Xchg:
+ case AtomicRMWInst::BinOp::And:
+ case AtomicRMWInst::BinOp::Or:
+ case AtomicRMWInst::BinOp::Xor:
+ assert(Ty->isIntegerTy());
+ switch (cast<llvm::IntegerType>(Ty)->getBitWidth()) {
+ case 32:
+ return AtomicExpansionKind::None;
+ case 64:
+ return AtomicExpansionKind::None;
+ default:
+ return AtomicExpansionKind::CmpXChg;
+ }
+ }
+
+ return AtomicExpansionKind::CmpXChg;
+}
+
// Pin NVPTXTargetObjectFile's vtables to this file.
NVPTXTargetObjectFile::~NVPTXTargetObjectFile() = default;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125512.429119.patch
Type: text/x-patch
Size: 2682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220513/d22a83c9/attachment.bin>
More information about the llvm-commits
mailing list