-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[CodeGen] Add SSID & Atomic Ordering to IntrinsicInfo #140896
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
Conversation
getTgtMemIntrinsic should be able to propagate such information to the MMO
@llvm/pr-subscribers-llvm-selectiondag @llvm/pr-subscribers-llvm-globalisel Author: Pierre van Houtryve (Pierre-vh) ChangesgetTgtMemIntrinsic should be able to propagate such information to the MMO Full diff: https://github.com/llvm/llvm-project/pull/140896.diff 3 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h
index 03099e9ad44dc..ef44c117acd1a 100644
--- a/llvm/include/llvm/CodeGen/TargetLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetLowering.h
@@ -1214,6 +1214,9 @@ class TargetLoweringBase {
struct IntrinsicInfo {
unsigned opc = 0; // target opcode
EVT memVT; // memory VT
+ SyncScope::ID ssid = SyncScope::System;
+ AtomicOrdering order = AtomicOrdering::NotAtomic;
+ AtomicOrdering failureOrder = AtomicOrdering::NotAtomic;
// value representing memory location
PointerUnion<const Value *, const PseudoSourceValue *> ptrVal;
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 8ab2533afc15f..051d220255876 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -2847,8 +2847,9 @@ bool IRTranslator::translateCall(const User &U, MachineIRBuilder &MIRBuilder) {
MPI = MachinePointerInfo(Info.ptrVal, Info.offset);
else if (Info.fallbackAddressSpace)
MPI = MachinePointerInfo(*Info.fallbackAddressSpace);
- MIB.addMemOperand(
- MF->getMachineMemOperand(MPI, Info.flags, MemTy, Alignment, CI.getAAMetadata()));
+ MIB.addMemOperand(MF->getMachineMemOperand(
+ MPI, Info.flags, MemTy, Alignment, CI.getAAMetadata(),
+ /*Ranges=*/nullptr, Info.ssid, Info.order, Info.failureOrder));
}
if (CI.isConvergent()) {
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index e32fcfe6148df..434484b671bf2 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -5305,9 +5305,16 @@ void SelectionDAGBuilder::visitTargetIntrinsic(const CallInst &I,
MPI = MachinePointerInfo(Info.ptrVal, Info.offset);
else if (Info.fallbackAddressSpace)
MPI = MachinePointerInfo(*Info.fallbackAddressSpace);
- Result = DAG.getMemIntrinsicNode(
- Info.opc, getCurSDLoc(), VTs, Ops, Info.memVT, MPI, Info.align,
- Info.flags, LocationSize::precise(Info.size), I.getAAMetadata());
+ EVT MemVT = Info.memVT;
+ LocationSize Size = LocationSize::precise(Info.size);
+ if (Size.hasValue() && !Size.getValue())
+ Size = LocationSize::precise(MemVT.getStoreSize());
+ Align Alignment = Info.align.value_or(DAG.getEVTAlign(MemVT));
+ MachineMemOperand *MMO = DAG.getMachineFunction().getMachineMemOperand(
+ MPI, Info.flags, Size, Alignment, I.getAAMetadata(), /*Ranges=*/nullptr,
+ Info.ssid, Info.order, Info.failureOrder);
+ Result =
+ DAG.getMemIntrinsicNode(Info.opc, getCurSDLoc(), VTs, Ops, MemVT, MMO);
} else if (!HasChain) {
Result = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, getCurSDLoc(), VTs, Ops);
} else if (!I.getType()->isVoidTy()) {
|
LocationSize Size = LocationSize::precise(Info.size); | ||
if (Size.hasValue() && !Size.getValue()) | ||
Size = LocationSize::precise(MemVT.getStoreSize()); | ||
Align Alignment = Info.align.value_or(DAG.getEVTAlign(MemVT)); |
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.
MaybeAlign should not exist. Particularly in this case, where the MaybeAlign is initialized to a concrete Align(1)
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.
Some targets use .reset()
to make TLI infer the size based on memVT
AMDGPU, NVPTX and AArch64 all do it
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.
Which just shouldn't be done
if (Size.hasValue() && !Size.getValue()) | ||
Size = LocationSize::precise(MemVT.getStoreSize()); |
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.
I don't understand why you need to do anything related to the size here
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.
This is borrowed from SelectionDAG::getMemIntrinsicNode
. Without it, I get size mismatches because there is an expectation that the value is initialized if it's zero.
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.
I think this whole API needs an overhaul, it's a collection of hacking around making changes to existing implementations. It would be better if LocationSize was directly constructed from MemVT in the first place
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.
In a follow up we should start reporting atomicity for the image atomic intrinsics
if (Size.hasValue() && !Size.getValue()) | ||
Size = LocationSize::precise(MemVT.getStoreSize()); |
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.
I think this whole API needs an overhaul, it's a collection of hacking around making changes to existing implementations. It would be better if LocationSize was directly constructed from MemVT in the first place
getTgtMemIntrinsic should be able to propagate such information to the MMO
getTgtMemIntrinsic should be able to propagate such information to the MMO
getTgtMemIntrinsic should be able to propagate such information to the MMO