[llvm] AMDGPU: Add range attribute to mbcnt intrinsic callsites (PR #189191)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 6 06:50:44 PDT 2026


================
@@ -1422,11 +1422,31 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
 
     break;
   }
-  case Intrinsic::amdgcn_mbcnt_hi: {
+  case Intrinsic::amdgcn_mbcnt_hi:
     // exec_hi is all 0, so this is just a copy.
     if (ST->isWave32())
       return IC.replaceInstUsesWith(II, II.getArgOperand(1));
-    break;
+    [[fallthrough]];
+  case Intrinsic::amdgcn_mbcnt_lo: {
+    ConstantRange AccRange = computeConstantRange(II.getArgOperand(1),
+                                                  /*ForSigned=*/false);
+    if (AccRange.isFullSet())
+      return nullptr;
+
+    // TODO: Can raise upper bound by inspecting first argument.
----------------
arsenm wrote:

This is not a typo, this is intentional. We can prove there are non-0 bits in the input mask to prove the lower bound is not 0

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


More information about the llvm-commits mailing list