[llvm] [SelectionDAG][NVPTX] Allow targets to configure CSE strategy (PR #192812)

via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 18 15:39:07 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- llvm/include/llvm/CodeGen/SelectionDAG.h llvm/include/llvm/CodeGen/SelectionDAGTargetInfo.h llvm/include/llvm/IR/DebugLoc.h llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp llvm/lib/IR/DebugLoc.cpp llvm/lib/Target/NVPTX/NVPTXSelectionDAGInfo.cpp llvm/lib/Target/NVPTX/NVPTXSelectionDAGInfo.h --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 6ef51b513..12e0c9214 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -98,9 +98,7 @@ public:
     FS.InsertNode(N, InsertPos);
   }
   bool RemoveNode(SDNode *N) override { return FS.RemoveNode(N); }
-  SDNode *GetOrInsertNode(SDNode *N) override {
-    return FS.GetOrInsertNode(N);
-  }
+  SDNode *GetOrInsertNode(SDNode *N) override { return FS.GetOrInsertNode(N); }
   void clear() override { FS.clear(); }
 };
 } // namespace
@@ -1990,7 +1988,7 @@ SDValue SelectionDAG::getGlobalAddress(const GlobalValue *GV, const SDLoc &DL,
   auto *N = newSDNode<GlobalAddressSDNode>(
       Opc, DL.getIROrder(), DL.getDebugLoc(), GV, VTs, Offset, TargetFlags);
   CSEMap->InsertNode(N, IP);
-    InsertNode(N);
+  InsertNode(N);
   return SDValue(N, 0);
 }
 
@@ -2000,7 +1998,8 @@ SDValue SelectionDAG::getDeactivationSymbol(const GlobalValue *GV) {
   AddNodeIDNode(ID, ISD::DEACTIVATION_SYMBOL, VTs, {});
   ID.AddPointer(GV);
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, SDLoc(), IP, ISD::DEACTIVATION_SYMBOL))
+  if (SDNode *E =
+          FindNodeOrInsertPos(ID, SDLoc(), IP, ISD::DEACTIVATION_SYMBOL))
     return SDValue(E, 0);
 
   auto *N = newSDNode<DeactivationSymbolSDNode>(GV, VTs);
@@ -10127,7 +10126,8 @@ SDValue SelectionDAG::getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT,
   ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
   ID.AddInteger(MMO->getFlags());
   void* IP = nullptr;
-  if (auto *E = cast_or_null<AtomicSDNode>(FindNodeOrInsertPos(ID, dl, IP, Opcode))) {
+  if (auto *E =
+          cast_or_null<AtomicSDNode>(FindNodeOrInsertPos(ID, dl, IP, Opcode))) {
     E->refineAlignment(MMO);
     E->refineRanges(MMO);
     return SDValue(E, 0);
@@ -10442,7 +10442,8 @@ SDValue SelectionDAG::getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType,
   ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
   ID.AddInteger(MMO->getFlags());
   void *IP = nullptr;
-  if (auto *E = cast_or_null<LoadSDNode>(FindNodeOrInsertPos(ID, dl, IP, ISD::LOAD))) {
+  if (auto *E = cast_or_null<LoadSDNode>(
+          FindNodeOrInsertPos(ID, dl, IP, ISD::LOAD))) {
     E->refineAlignment(MMO);
     E->refineRanges(MMO);
     return SDValue(E, 0);
@@ -10667,7 +10668,8 @@ SDValue SelectionDAG::getLoadVP(ISD::MemIndexedMode AM,
   ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
   ID.AddInteger(MMO->getFlags());
   void *IP = nullptr;
-  if (auto *E = cast_or_null<VPLoadSDNode>(FindNodeOrInsertPos(ID, dl, IP, ISD::VP_LOAD))) {
+  if (auto *E = cast_or_null<VPLoadSDNode>(
+          FindNodeOrInsertPos(ID, dl, IP, ISD::VP_LOAD))) {
     E->refineAlignment(MMO);
     E->refineRanges(MMO);
     return SDValue(E, 0);
@@ -10899,7 +10901,8 @@ SDValue SelectionDAG::getStridedLoadVP(
   ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
 
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP, ISD::EXPERIMENTAL_VP_STRIDED_LOAD)) {
+  if (SDNode *E =
+          FindNodeOrInsertPos(ID, DL, IP, ISD::EXPERIMENTAL_VP_STRIDED_LOAD)) {
     cast<VPStridedLoadSDNode>(E)->refineAlignment(MMO);
     return SDValue(E, 0);
   }
@@ -10954,7 +10957,8 @@ SDValue SelectionDAG::getStridedStoreVP(SDValue Chain, const SDLoc &DL,
       DL.getIROrder(), VTs, AM, IsTruncating, IsCompressing, MemVT, MMO));
   ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP, ISD::EXPERIMENTAL_VP_STRIDED_STORE)) {
+  if (SDNode *E =
+          FindNodeOrInsertPos(ID, DL, IP, ISD::EXPERIMENTAL_VP_STRIDED_STORE)) {
     cast<VPStridedStoreSDNode>(E)->refineAlignment(MMO);
     return SDValue(E, 0);
   }
@@ -11003,7 +11007,8 @@ SDValue SelectionDAG::getTruncStridedStoreVP(SDValue Chain, const SDLoc &DL,
       DL.getIROrder(), VTs, ISD::UNINDEXED, true, IsCompressing, SVT, MMO));
   ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP, ISD::EXPERIMENTAL_VP_STRIDED_STORE)) {
+  if (SDNode *E =
+          FindNodeOrInsertPos(ID, DL, IP, ISD::EXPERIMENTAL_VP_STRIDED_STORE)) {
     cast<VPStridedStoreSDNode>(E)->refineAlignment(MMO);
     return SDValue(E, 0);
   }
@@ -11308,7 +11313,8 @@ SDValue SelectionDAG::getMaskedHistogram(SDVTList VTs, EVT MemVT,
   ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
   ID.AddInteger(MMO->getFlags());
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP, ISD::EXPERIMENTAL_VECTOR_HISTOGRAM)) {
+  if (SDNode *E =
+          FindNodeOrInsertPos(ID, dl, IP, ISD::EXPERIMENTAL_VECTOR_HISTOGRAM)) {
     cast<MaskedGatherSDNode>(E)->refineAlignment(MMO);
     return SDValue(E, 0);
   }
@@ -11999,7 +12005,8 @@ SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, SDValue Op) {
 
   updateDivergence(N);
   // If this gets put into a CSE map, add it.
-  if (InsertPos) CSEMap->InsertNode(N, InsertPos);
+  if (InsertPos)
+    CSEMap->InsertNode(N, InsertPos);
   return N;
 }
 
@@ -12028,7 +12035,8 @@ SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2) {
 
   updateDivergence(N);
   // If this gets put into a CSE map, add it.
-  if (InsertPos) CSEMap->InsertNode(N, InsertPos);
+  if (InsertPos)
+    CSEMap->InsertNode(N, InsertPos);
   return N;
 }
 
@@ -12079,7 +12087,8 @@ UpdateNodeOperands(SDNode *N, ArrayRef<SDValue> Ops) {
 
   updateDivergence(N);
   // If this gets put into a CSE map, add it.
-  if (InsertPos) CSEMap->InsertNode(N, InsertPos);
+  if (InsertPos)
+    CSEMap->InsertNode(N, InsertPos);
   return N;
 }
 
@@ -12274,7 +12283,7 @@ SDNode *SelectionDAG::MorphNodeTo(SDNode *N, unsigned Opc,
   }
 
   if (IP)
-    CSEMap->InsertNode(N, IP);   // Memoize the new node.
+    CSEMap->InsertNode(N, IP); // Memoize the new node.
   return N;
 }
 
diff --git a/llvm/lib/Target/NVPTX/NVPTXSelectionDAGInfo.cpp b/llvm/lib/Target/NVPTX/NVPTXSelectionDAGInfo.cpp
index 97b1dd3c5..8f737e2e6 100644
--- a/llvm/lib/Target/NVPTX/NVPTXSelectionDAGInfo.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXSelectionDAGInfo.cpp
@@ -27,7 +27,7 @@ using namespace llvm;
 /// Appends DebugLoc data to ID at -O0, so nodes at different source locations
 /// are not merged.  Constants are always CSE'd regardless of location.
 static void profileDebugLoc(FoldingSetNodeID &ID, unsigned Opcode,
-                             const DebugLoc &DL, const SelectionDAG &DAG) {
+                            const DebugLoc &DL, const SelectionDAG &DAG) {
   if (DAG.getOptLevel() != CodeGenOptLevel::None)
     return;
   if (!DL)
@@ -79,9 +79,7 @@ public:
 
   bool RemoveNode(SDNode *N) override { return FS.RemoveNode(N); }
 
-  SDNode *GetOrInsertNode(SDNode *N) override {
-    return FS.GetOrInsertNode(N);
-  }
+  SDNode *GetOrInsertNode(SDNode *N) override { return FS.GetOrInsertNode(N); }
 
   void clear() override { FS.clear(); }
 };
diff --git a/llvm/lib/Target/NVPTX/NVPTXSelectionDAGInfo.h b/llvm/lib/Target/NVPTX/NVPTXSelectionDAGInfo.h
index 08741ff46..993dda10c 100644
--- a/llvm/lib/Target/NVPTX/NVPTXSelectionDAGInfo.h
+++ b/llvm/lib/Target/NVPTX/NVPTXSelectionDAGInfo.h
@@ -60,8 +60,7 @@ public:
   void verifyTargetNode(const SelectionDAG &DAG,
                         const SDNode *N) const override;
 
-  std::unique_ptr<SDNodeCSEMap>
-  createCSEMap(SelectionDAG &DAG) const override;
+  std::unique_ptr<SDNodeCSEMap> createCSEMap(SelectionDAG &DAG) const override;
 };
 
 } // namespace llvm

``````````

</details>


https://github.com/llvm/llvm-project/pull/192812


More information about the llvm-commits mailing list