[llvm] [SelectionDAG] Make the FoldingSet profile in getAtomic match AddNodeIDCustom. (PR #136651)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 21 21:15:17 PDT 2025


https://github.com/topperc created https://github.com/llvm/llvm-project/pull/136651

The code in AddNodeIDCustom:

const AtomicSDNode *AT = cast<AtomicSDNode>(N);
ID.AddInteger(AT->getMemoryVT().getRawBits());
ID.AddInteger(AT->getRawSubclassData());
ID.AddInteger(AT->getPointerInfo().getAddrSpace()); ID.AddInteger(AT->getMemOperand()->getFlags());

In theory, the mismatch would have made CSE of AtomicSDNodes not work, but I don't know how to test it.

>From 504d23a82edaeaa5609602294978b27ade92c446 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Mon, 21 Apr 2025 21:07:48 -0700
Subject: [PATCH] [SelectionDAG] Make the FoldingSet profile in getAtomic match
 AddNodeIDCustom.

The code in AddNodeIDCustom:

const AtomicSDNode *AT = cast<AtomicSDNode>(N);
ID.AddInteger(AT->getMemoryVT().getRawBits());
ID.AddInteger(AT->getRawSubclassData());
ID.AddInteger(AT->getPointerInfo().getAddrSpace());
ID.AddInteger(AT->getMemOperand()->getFlags());

In theory, the mismatch would have made CSE of AtomicSDNodes not
work, but I don't know how to test it.
---
 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index ba6c5d884d381..5269962ea2062 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -8994,8 +8994,10 @@ SDValue SelectionDAG::getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT,
                                 SDVTList VTList, ArrayRef<SDValue> Ops,
                                 MachineMemOperand *MMO) {
   FoldingSetNodeID ID;
-  ID.AddInteger(MemVT.getRawBits());
   AddNodeIDNode(ID, Opcode, VTList, Ops);
+  ID.AddInteger(MemVT.getRawBits());
+  ID.AddInteger(getSyntheticNodeSubclassData<AtomicSDNode>(
+      Opcode, dl.getIROrder(), VTList, MemVT, MMO));
   ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
   ID.AddInteger(MMO->getFlags());
   void* IP = nullptr;



More information about the llvm-commits mailing list