Skip to content

AMDGPU: Add is.shared/is.private intrinsics to isBoolSGPR #141804

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

Merged

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented May 28, 2025

No change in the net output since these ultimately expand to setcc,
but saves a step in the DAG.

@arsenm arsenm marked this pull request as ready for review May 28, 2025 16:43
Copy link
Contributor Author

arsenm commented May 28, 2025

@llvmbot
Copy link
Member

llvmbot commented May 28, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)

Changes

No change in the net output since these ultimately expand to setcc,
but saves a step in the DAG.


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

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/SIISelLowering.cpp (+12)
  • (modified) llvm/test/CodeGen/AMDGPU/combine-cond-add-sub.ll (+48)
diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index 7ad10454e7931..b124f02d32a8a 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -11922,6 +11922,18 @@ bool llvm::isBoolSGPR(SDValue V) {
   case ISD::SMULO:
   case ISD::UMULO:
     return V.getResNo() == 1;
+  case ISD::INTRINSIC_WO_CHAIN: {
+    unsigned IntrinsicID = V.getConstantOperandVal(0);
+    switch (IntrinsicID) {
+    case Intrinsic::amdgcn_is_shared:
+    case Intrinsic::amdgcn_is_private:
+      return true;
+    default:
+      return false;
+    }
+
+    return false;
+  }
   }
   return false;
 }
diff --git a/llvm/test/CodeGen/AMDGPU/combine-cond-add-sub.ll b/llvm/test/CodeGen/AMDGPU/combine-cond-add-sub.ll
index 1778fa42fbf7e..ba8abdc17fb05 100644
--- a/llvm/test/CodeGen/AMDGPU/combine-cond-add-sub.ll
+++ b/llvm/test/CodeGen/AMDGPU/combine-cond-add-sub.ll
@@ -740,6 +740,54 @@ bb:
   ret void
 }
 
+define i32 @add_sext_bool_is_shared(ptr %ptr, i32 %y) {
+; GCN-LABEL: add_sext_bool_is_shared:
+; GCN:       ; %bb.0:
+; GCN-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GCN-NEXT:    s_mov_b64 s[4:5], 0xe8
+; GCN-NEXT:    s_load_dword s4, s[4:5], 0x0
+; GCN-NEXT:    s_waitcnt lgkmcnt(0)
+; GCN-NEXT:    v_cmp_eq_u32_e32 vcc, s4, v1
+; GCN-NEXT:    v_subbrev_u32_e32 v0, vcc, 0, v2, vcc
+; GCN-NEXT:    s_setpc_b64 s[30:31]
+;
+; GFX9-LABEL: add_sext_bool_is_shared:
+; GFX9:       ; %bb.0:
+; GFX9-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT:    s_mov_b64 s[4:5], src_shared_base
+; GFX9-NEXT:    v_cmp_eq_u32_e32 vcc, s5, v1
+; GFX9-NEXT:    v_subbrev_co_u32_e32 v0, vcc, 0, v2, vcc
+; GFX9-NEXT:    s_setpc_b64 s[30:31]
+  %is.shared = call i1 @llvm.amdgcn.is.shared(ptr %ptr)
+  %sext = sext i1 %is.shared to i32
+  %add = add i32 %sext, %y
+  ret i32 %add
+}
+
+define i32 @add_sext_bool_is_private(ptr %ptr, i32 %y) {
+; GCN-LABEL: add_sext_bool_is_private:
+; GCN:       ; %bb.0:
+; GCN-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GCN-NEXT:    s_mov_b64 s[4:5], 0xe4
+; GCN-NEXT:    s_load_dword s4, s[4:5], 0x0
+; GCN-NEXT:    s_waitcnt lgkmcnt(0)
+; GCN-NEXT:    v_cmp_eq_u32_e32 vcc, s4, v1
+; GCN-NEXT:    v_subbrev_u32_e32 v0, vcc, 0, v2, vcc
+; GCN-NEXT:    s_setpc_b64 s[30:31]
+;
+; GFX9-LABEL: add_sext_bool_is_private:
+; GFX9:       ; %bb.0:
+; GFX9-NEXT:    s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT:    s_mov_b64 s[4:5], src_private_base
+; GFX9-NEXT:    v_cmp_eq_u32_e32 vcc, s5, v1
+; GFX9-NEXT:    v_subbrev_co_u32_e32 v0, vcc, 0, v2, vcc
+; GFX9-NEXT:    s_setpc_b64 s[30:31]
+  %is.private = call i1 @llvm.amdgcn.is.private(ptr %ptr)
+  %sext = sext i1 %is.private to i32
+  %add = add i32 %sext, %y
+  ret i32 %add
+}
+
 declare i1 @llvm.amdgcn.class.f32(float, i32) #0
 
 declare i32 @llvm.amdgcn.workitem.id.x() #0

return false;
}

return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: llvm_unreachable?

Copy link
Contributor Author

arsenm commented May 28, 2025

Merge activity

  • May 28, 7:25 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 28, 7:35 PM UTC: Graphite rebased this pull request as part of a merge.
  • May 28, 7:38 PM UTC: @arsenm merged this pull request with Graphite.

@arsenm arsenm force-pushed the users/arsenm/amdgpu/add-overflow-operations-is-bool-sgpr branch from 2048248 to 7c026d8 Compare May 28, 2025 19:31
Base automatically changed from users/arsenm/amdgpu/add-overflow-operations-is-bool-sgpr to main May 28, 2025 19:35
No change in the net output since these ultimately expand to setcc,
but saves a step in the DAG.
@arsenm arsenm force-pushed the users/arsenm/amdgpu/add-is-shared-is-private-is-bool-sgpr branch from 6967e64 to 52d2ff5 Compare May 28, 2025 19:35
@arsenm arsenm merged commit d8235af into main May 28, 2025
6 of 9 checks passed
@arsenm arsenm deleted the users/arsenm/amdgpu/add-is-shared-is-private-is-bool-sgpr branch May 28, 2025 19:38
google-yfyang pushed a commit to google-yfyang/llvm-project that referenced this pull request May 29, 2025
No change in the net output since these ultimately expand to setcc,
but saves a step in the DAG.
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
No change in the net output since these ultimately expand to setcc,
but saves a step in the DAG.
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.

3 participants