aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/AtomicExpandPass.cpp
diff options
context:
space:
mode:
authorKai Luo <lkail@cn.ibm.com>2022-08-31 09:23:32 +0800
committerKai Luo <lkail@cn.ibm.com>2022-08-31 09:54:58 +0800
commitad2f7fd286f15b6ff10f35bc3a9e069e48fb98de (patch)
tree1c34a885555a84565c1752564dbeaf833bebebf6 /llvm/lib/CodeGen/AtomicExpandPass.cpp
parent146ae4138a081a9a10e4901bbec61b629331da8a (diff)
downloadllvm-ad2f7fd286f15b6ff10f35bc3a9e069e48fb98de.zip
llvm-ad2f7fd286f15b6ff10f35bc3a9e069e48fb98de.tar.gz
llvm-ad2f7fd286f15b6ff10f35bc3a9e069e48fb98de.tar.bz2
[AtomicExpand] Make floating point conversion happens before fence insertion
IIUC, the conversion part is not part of atomic operations and fences should be put around converted atomic operations. This also fixes atomic load of floating point values which requires fence on PowerPC. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D127609
Diffstat (limited to 'llvm/lib/CodeGen/AtomicExpandPass.cpp')
-rw-r--r--llvm/lib/CodeGen/AtomicExpandPass.cpp78
1 files changed, 30 insertions, 48 deletions
diff --git a/llvm/lib/CodeGen/AtomicExpandPass.cpp b/llvm/lib/CodeGen/AtomicExpandPass.cpp
index ad51bab..0c89560 100644
--- a/llvm/lib/CodeGen/AtomicExpandPass.cpp
+++ b/llvm/lib/CodeGen/AtomicExpandPass.cpp
@@ -221,6 +221,31 @@ bool AtomicExpand::runOnFunction(Function &F) {
}
}
+ if (LI && TLI->shouldCastAtomicLoadInIR(LI) ==
+ TargetLoweringBase::AtomicExpansionKind::CastToInteger) {
+ I = LI = convertAtomicLoadToIntegerType(LI);
+ MadeChange = true;
+ } else if (SI &&
+ TLI->shouldCastAtomicStoreInIR(SI) ==
+ TargetLoweringBase::AtomicExpansionKind::CastToInteger) {
+ I = SI = convertAtomicStoreToIntegerType(SI);
+ MadeChange = true;
+ } else if (RMWI &&
+ TLI->shouldCastAtomicRMWIInIR(RMWI) ==
+ TargetLoweringBase::AtomicExpansionKind::CastToInteger) {
+ I = RMWI = convertAtomicXchgToIntegerType(RMWI);
+ MadeChange = true;
+ } else if (CASI) {
+ // TODO: when we're ready to make the change at the IR level, we can
+ // extend convertCmpXchgToInteger for floating point too.
+ if (CASI->getCompareOperand()->getType()->isPointerTy()) {
+ // TODO: add a TLI hook to control this so that each target can
+ // convert to lowering the original type one at a time.
+ I = CASI = convertCmpXchgToIntegerType(CASI);
+ MadeChange = true;
+ }
+ }
+
if (TLI->shouldInsertFencesForAtomic(I)) {
auto FenceOrdering = AtomicOrdering::Monotonic;
if (LI && isAcquireOrStronger(LI->getOrdering())) {
@@ -253,31 +278,11 @@ bool AtomicExpand::runOnFunction(Function &F) {
}
}
- if (LI) {
- if (TLI->shouldCastAtomicLoadInIR(LI) ==
- TargetLoweringBase::AtomicExpansionKind::CastToInteger) {
- // TODO: add a TLI hook to control this so that each target can
- // convert to lowering the original type one at a time.
- LI = convertAtomicLoadToIntegerType(LI);
- assert(LI->getType()->isIntegerTy() && "invariant broken");
- MadeChange = true;
- }
-
+ if (LI)
MadeChange |= tryExpandAtomicLoad(LI);
- } else if (SI) {
- if (TLI->shouldCastAtomicStoreInIR(SI) ==
- TargetLoweringBase::AtomicExpansionKind::CastToInteger) {
- // TODO: add a TLI hook to control this so that each target can
- // convert to lowering the original type one at a time.
- SI = convertAtomicStoreToIntegerType(SI);
- assert(SI->getValueOperand()->getType()->isIntegerTy() &&
- "invariant broken");
- MadeChange = true;
- }
-
- if (tryExpandAtomicStore(SI))
- MadeChange = true;
- } else if (RMWI) {
+ else if (SI)
+ MadeChange |= tryExpandAtomicStore(SI);
+ else if (RMWI) {
// There are two different ways of expanding RMW instructions:
// - into a load if it is idempotent
// - into a Cmpxchg/LL-SC loop otherwise
@@ -287,15 +292,6 @@ bool AtomicExpand::runOnFunction(Function &F) {
MadeChange = true;
} else {
AtomicRMWInst::BinOp Op = RMWI->getOperation();
- if (TLI->shouldCastAtomicRMWIInIR(RMWI) ==
- TargetLoweringBase::AtomicExpansionKind::CastToInteger) {
- // TODO: add a TLI hook to control this so that each target can
- // convert to lowering the original type one at a time.
- RMWI = convertAtomicXchgToIntegerType(RMWI);
- assert(RMWI->getValOperand()->getType()->isIntegerTy() &&
- "invariant broken");
- MadeChange = true;
- }
unsigned MinCASSize = TLI->getMinCmpXchgSizeInBits() / 8;
unsigned ValueSize = getAtomicOpSize(RMWI);
if (ValueSize < MinCASSize &&
@@ -307,22 +303,8 @@ bool AtomicExpand::runOnFunction(Function &F) {
MadeChange |= tryExpandAtomicRMW(RMWI);
}
- } else if (CASI) {
- // TODO: when we're ready to make the change at the IR level, we can
- // extend convertCmpXchgToInteger for floating point too.
- assert(!CASI->getCompareOperand()->getType()->isFloatingPointTy() &&
- "unimplemented - floating point not legal at IR level");
- if (CASI->getCompareOperand()->getType()->isPointerTy()) {
- // TODO: add a TLI hook to control this so that each target can
- // convert to lowering the original type one at a time.
- CASI = convertCmpXchgToIntegerType(CASI);
- assert(CASI->getCompareOperand()->getType()->isIntegerTy() &&
- "invariant broken");
- MadeChange = true;
- }
-
+ } else if (CASI)
MadeChange |= tryExpandAtomicCmpXchg(CASI);
- }
}
return MadeChange;
}