Skip to content
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

[AMDGPU] Respect existing glue when lowering convergence tokens #90834

Merged
merged 1 commit into from
May 14, 2024

Conversation

ssahasra
Copy link
Collaborator

@ssahasra ssahasra commented May 2, 2024

No description provided.

@llvmbot
Copy link
Collaborator

llvmbot commented May 2, 2024

@llvm/pr-subscribers-backend-amdgpu

Author: Sameer Sahasrabuddhe (ssahasra)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/90834.diff

1 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/SIISelLowering.cpp (+10-11)
diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index cb4efdc7cf657c..68dffdf8060486 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -3859,20 +3859,19 @@ SDValue SITargetLowering::LowerCall(CallLoweringInfo &CLI,
   assert(Mask && "Missing call preserved mask for calling convention");
   Ops.push_back(DAG.getRegisterMask(Mask));
 
-  if (InGlue.getNode())
-    Ops.push_back(InGlue);
-
-  // NOTE: This potentially results in *two* glue operands, and the wrong one
-  // might possibly show up where the other was intended. In particular,
-  // Emitter::EmitMachineNode() expects only the glued convergence token if it
-  // exists. Similarly, the selection of the call expects to match only the
-  // InGlue operand if it exists.
   if (SDValue Token = CLI.ConvergenceControlToken) {
-    Ops.push_back(SDValue(DAG.getMachineNode(TargetOpcode::CONVERGENCECTRL_GLUE,
-                                             DL, MVT::Glue, Token),
-                          0));
+    SmallVector<SDValue, 2> GlueOps;
+    GlueOps.push_back(Token);
+    if (InGlue.getNode())
+      GlueOps.push_back(InGlue);
+
+    InGlue = SDValue(DAG.getMachineNode(TargetOpcode::CONVERGENCECTRL_GLUE,
+                                       DL, MVT::Glue, GlueOps), 0);
   }
 
+  if (InGlue.getNode())
+    Ops.push_back(InGlue);
+
   SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
 
   // If we're doing a tall call, use a TC_RETURN here rather than an

Copy link

github-actions bot commented May 2, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@jayfoad
Copy link
Contributor

jayfoad commented May 2, 2024

I guess no nodes actually require this yet. Are you expecting any? Or is this just defensive programming?

0));
SmallVector<SDValue, 2> GlueOps;
GlueOps.push_back(Token);
if (InGlue.getNode())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need .getNode()

}

if (InGlue.getNode())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need .getNode()

@ssahasra
Copy link
Collaborator Author

ssahasra commented May 3, 2024

I guess no nodes actually require this yet. Are you expecting any? Or is this just defensive programming?

What is "this" in this context?? When lowering calls, we do glue stuff onto the actually call instruction. Now we also need to glue the convergence token to the same call. The existing attempt happily created a second glue operand, and this change fixes that to have a single glue operand which could itself have a chain of glued operands.

@ssahasra ssahasra force-pushed the ssahasra/convergence-glue branch from 3a5ee8a to 897cc6d Compare May 6, 2024 09:14
@ssahasra ssahasra merged commit 11e5d1c into llvm:main May 14, 2024
4 checks passed
@ssahasra ssahasra deleted the ssahasra/convergence-glue branch May 14, 2024 08:09
@jayfoad
Copy link
Contributor

jayfoad commented May 14, 2024

I guess no nodes actually require this yet. Are you expecting any? Or is this just defensive programming?

What is "this" in this context??

"This" meant "this patch". I was trying to work out what kind of patch this is. Does it fix a bug? Why is there no test case?

@ssahasra
Copy link
Collaborator Author

I guess no nodes actually require this yet. Are you expecting any? Or is this just defensive programming?

"This" meant "this patch". I was trying to work out what kind of patch this is. Does it fix a bug? Why is there no test case?

This patch merely cements my improved understanding of how glue is supposed to be set on an operation. Callsites already have a glue operand that holds on to the arg nodes. The lowering of control flow tokens at a callsite was adding a second glue operand, which is unexpected. This patch cleans that up by chaining the token with the existing glue operand. In this narrow window inside the AMDGPU backend, this "bug" would have been triggered if those arg operands were actually accessed as glue. But they are not, so nothing broke when I put a second glue operand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants