[llvm] [llvm][AMDGPU] Fix signed/unsigned comparison warning in 32-bit builds (PR #172623)

David Spickett via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 18 02:36:22 PST 2025


https://github.com/DavidSpickett updated https://github.com/llvm/llvm-project/pull/172623

>From 7ad15b959f1678ba726e9c30ee141712e5cda694 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Wed, 17 Dec 2025 10:05:10 +0000
Subject: [PATCH 1/3] [llvm][AMDGPU] Fix signed/unsigned comparison warning in
 32-bit builds

llvm::count_if calls std::count_if which returns a difference_type.
difference_type is always signed but is never going to be a negative
value when used as the result of count_if.

This resulted in warnings in our 32-bit Arm builds like:
AMDGPUIGroupLP.cpp:1050:20: warning: comparison of integers of different signs: 'typename iterator_traits<const SDep *>::difference_type' (aka 'int') and 'unsigned int' [-Wsign-compare]
 1050 |       if (SuccSize >= Size)
      |           ~~~~~~~~ ^  ~~~~

I presume these warnings are not generated in 64-bit builds because
unsigned is 32-bit even for 64-bit platforms and there is no risk
in extending 32-bit unsigned into 64-bit signed.

To fix the warning I've added static_casts at the comparison points.
---
 llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp b/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
index 85addb13aef8d..e6ec3bbb52adb 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
@@ -1047,7 +1047,7 @@ class MFMAExpInterleaveOpt final : public IGLPStrategy {
       auto SuccSize = llvm::count_if(SU->Succs, [](const SDep &Succ) {
         return Succ.getKind() == SDep::Data;
       });
-      if (SuccSize >= Size)
+      if (static_cast<unsigned>(SuccSize) >= Size)
         return false;
 
       if (HasIntermediary) {
@@ -1056,7 +1056,7 @@ class MFMAExpInterleaveOpt final : public IGLPStrategy {
               llvm::count_if(Succ.getSUnit()->Succs, [](const SDep &SuccSucc) {
                 return SuccSucc.getKind() == SDep::Data;
               });
-          if (SuccSize >= Size)
+          if (static_cast<unsigned>(SuccSize) >= Size)
             return false;
         }
       }
@@ -1087,7 +1087,7 @@ class MFMAExpInterleaveOpt final : public IGLPStrategy {
       auto SuccSize = llvm::count_if(SU->Succs, [](const SDep &Succ) {
         return Succ.getKind() == SDep::Data;
       });
-      if (SuccSize >= Size)
+      if (static_cast<unsigned>(SuccSize) >= Size)
         return true;
 
       if (HasIntermediary) {
@@ -1096,7 +1096,7 @@ class MFMAExpInterleaveOpt final : public IGLPStrategy {
               llvm::count_if(Succ.getSUnit()->Succs, [](const SDep &SuccSucc) {
                 return SuccSucc.getKind() == SDep::Data;
               });
-          if (SuccSize >= Size)
+          if (static_cast<unsigned>(SuccSize) >= Size)
             return true;
         }
       }

>From e06996c99b13e0a2d3904e3b77ebfd37de75b4af Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Thu, 18 Dec 2025 10:34:56 +0000
Subject: [PATCH 2/3] change type instead

---
 llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp b/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
index e6ec3bbb52adb..74686d21f829e 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
@@ -1084,19 +1084,19 @@ class MFMAExpInterleaveOpt final : public IGLPStrategy {
       if (!SyncPipe.size())
         return false;
 
-      auto SuccSize = llvm::count_if(SU->Succs, [](const SDep &Succ) {
+      unsigned SuccSize = llvm::count_if(SU->Succs, [](const SDep &Succ) {
         return Succ.getKind() == SDep::Data;
       });
-      if (static_cast<unsigned>(SuccSize) >= Size)
+      if (SuccSize >= Size)
         return true;
 
       if (HasIntermediary) {
         for (auto Succ : SU->Succs) {
-          auto SuccSize =
+          unsigned SuccSize =
               llvm::count_if(Succ.getSUnit()->Succs, [](const SDep &SuccSucc) {
                 return SuccSucc.getKind() == SDep::Data;
               });
-          if (static_cast<unsigned>(SuccSize) >= Size)
+          if (SuccSize >= Size)
             return true;
         }
       }

>From 7fa434b491957e78eb5dc78d0653d13c3a3da635 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Thu, 18 Dec 2025 10:36:07 +0000
Subject: [PATCH 3/3] change type

---
 llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp b/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
index 74686d21f829e..8340405c7c9ed 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
@@ -1044,19 +1044,19 @@ class MFMAExpInterleaveOpt final : public IGLPStrategy {
       if (!SyncPipe.size())
         return false;
 
-      auto SuccSize = llvm::count_if(SU->Succs, [](const SDep &Succ) {
+      unsigned SuccSize = llvm::count_if(SU->Succs, [](const SDep &Succ) {
         return Succ.getKind() == SDep::Data;
       });
-      if (static_cast<unsigned>(SuccSize) >= Size)
+      if (SuccSize >= Size)
         return false;
 
       if (HasIntermediary) {
         for (auto Succ : SU->Succs) {
-          auto SuccSize =
+          unsigned SuccSize =
               llvm::count_if(Succ.getSUnit()->Succs, [](const SDep &SuccSucc) {
                 return SuccSucc.getKind() == SDep::Data;
               });
-          if (static_cast<unsigned>(SuccSize) >= Size)
+          if (SuccSize >= Size)
             return false;
         }
       }



More information about the llvm-commits mailing list