[llvm] [AMDGPU] Add dereferenceable retAttr to a call to llvm.amdgcn.implicitarg.ptr in amdgpu-codegenprepare (PR #182206)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 19 09:08:49 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Yoonseo Choi (yoonseoch)
<details>
<summary>Changes</summary>
This PR adds a return value attribute, dereferenceable(byte) to a call to llvm.amdgcn.implicitarg.ptr in amdgpu-codegenprepare. "amdgpu-codegenprepare" runs as one of the last LLVM IR Passes in amdgpu llc pipeline. After that pass, one final LICM pass runs before isel.
By adding dereferenceable(byte) to a call to llvm.amdgcn.implicitarg.ptr, a load reading from its pointer can be hoisted even if the load resided in the inner loop's preheader and the call resided in the outer loop's preheader. Without dereferenceable return attr, the dependent load cannot be hoisted as above because the load is conditionally executed with regard to an outer loop.
This can help example hip programs:
blockDim.{y, z} - which underlying have calls and loads - can be hosted out of the outer most loop.
```
__global__ void fooKernel(const double* d_a, const double* d_b, double* d_c) {
const int team_idx = hipBlockIdx_x;
for (int thread_z = threadIdx.z; thread_z < block_factor; thread_z += blockDim.z) {
for (int thread_y = threadIdx.y; thread_y < block_factor; thread_y += blockDim.y) {
for (int thread_x = threadIdx.x; thread_x < block_factor; thread_x += blockDim.x) {
auto index = team_idx * block_size +
block_factor * block_factor * block_factor * c +
block_factor * block_factor * thread_z +
block_factor * thread_y +
thread_x;
assert(index < count);
d_c[index] = d_a[index] + d_b[index];
}
}
}
}
```
LICM passes in the middle end (target-independent LLVM IR optimization pipeline) hoist calls to llvm.amdgcn.implicitarg.ptr to the outer loops' preheader as they are speculatable. However, once they are hoisted dereferenceable return attr will be dropped to avoid any UB.
A target-specific changes that are done in IR passes for instruction selection was introduced for the final LICM to further hoist remaining invariant loads by making it safe to execute unconditionally.
There can be tradeoffs in performance from longer live ranges and more unconditional execution of loads from implicitarg_ptr. However, I suspect hip kernels with multi-level loop nests often benefit from it.
---
Patch is 20.71 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/182206.diff
3 Files Affected:
- (modified) llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp (+39)
- (added) llvm/test/CodeGen/AMDGPU/amdgpu-mark-dereferenceable-call.ll (+141)
- (added) llvm/test/CodeGen/AMDGPU/licm-after-marking-dereferenceable.ll (+172)
``````````diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
index 2cd1bf4a813c4..6f9ba9703df1c 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
@@ -94,6 +94,12 @@ static cl::opt<bool> DisableFDivExpand(
cl::ReallyHidden,
cl::init(false));
+static cl::opt<bool> MarkDereferenceableCalls(
+ "amdgpu-codegenprepare-mark-dereferenceable-calls",
+ cl::desc("Mark implicitarg.ptr calls as dereferenceable to enable LICM "
+ "optimization"),
+ cl::ReallyHidden, cl::init(true));
+
class AMDGPUCodeGenPrepareImpl
: public InstVisitor<AMDGPUCodeGenPrepareImpl, bool> {
public:
@@ -283,6 +289,36 @@ class AMDGPUCodeGenPrepare : public FunctionPass {
StringRef getPassName() const override { return "AMDGPU IR optimizations"; }
};
+static bool markDereferenceableCalls(Function &F) {
+ if (F.hasFnAttribute("amdgpu-no-implicitarg-ptr"))
+ return false;
+
+ bool Changed = false;
+ unsigned CodeObjectVersion =
+ AMDGPU::getAMDHSACodeObjectVersion(*(F.getParent()));
+ uint64_t Bytes = (CodeObjectVersion >= AMDGPU::AMDHSA_COV5) ? 256 : 64;
+
+ for (BasicBlock &BB : F)
+ for (Instruction &I : BB)
+ if (auto *CI = dyn_cast<CallInst>(&I)) {
+ Function *Callee = CI->getCalledFunction();
+ if (!Callee)
+ continue;
+
+ // Check if this is a call to amdgcn_implicitarg_ptr intrinsic
+ Intrinsic::ID IID = Callee->getIntrinsicID();
+ if (IID != Intrinsic::amdgcn_implicitarg_ptr)
+ continue;
+
+ if (!CI->hasRetAttr(Attribute::Dereferenceable)) {
+ CI->addRetAttr(
+ Attribute::getWithDereferenceableBytes(CI->getContext(), Bytes));
+ Changed = true;
+ }
+ }
+
+ return Changed;
+}
} // end anonymous namespace
bool AMDGPUCodeGenPrepareImpl::run() {
@@ -304,6 +340,9 @@ bool AMDGPUCodeGenPrepareImpl::run() {
RecursivelyDeleteTriviallyDeadInstructions(I, TLI);
}
+ if (MarkDereferenceableCalls)
+ MadeChange |= markDereferenceableCalls(F);
+
return MadeChange;
}
diff --git a/llvm/test/CodeGen/AMDGPU/amdgpu-mark-dereferenceable-call.ll b/llvm/test/CodeGen/AMDGPU/amdgpu-mark-dereferenceable-call.ll
new file mode 100644
index 0000000000000..ae73551c0230d
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/amdgpu-mark-dereferenceable-call.ll
@@ -0,0 +1,141 @@
+; RUN: opt -S -passes='amdgpu-codegenprepare' -mtriple=amdgcn-amd-amdhsa -disable-verify < %s | FileCheck %s --check-prefix=DEREF
+; RUN: opt -S -passes='loop-mssa(licm)' -mtriple=amdgcn-amd-amdhsa -disable-verify < %s | FileCheck %s --check-prefix=WITHOUT
+; RUN: opt -S -passes='amdgpu-codegenprepare,loop-mssa(licm)' -mtriple=amdgcn-amd-amdhsa -amdgpu-codegenprepare-mark-dereferenceable-calls=false < %s \
+; RUN: | FileCheck %s --check-prefix=WITHOUT
+; RUN: opt -S -passes='amdgpu-codegenprepare,loop-mssa(licm)' -mtriple=amdgcn-amd-amdhsa < %s | FileCheck %s --check-prefix=WITH
+
+target datalayout = "e-m:e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128:128:48-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9"
+
+define protected amdgpu_kernel void @foo(ptr addrspace(1) noundef readonly captures(none) %d_a.coerce, ptr addrspace(1) noundef readonly captures(none) %d_b.coerce, ptr addrspace(1) noundef writeonly captures(none) %d_c.coerce, i32 noundef %count) local_unnamed_addr #0 {
+; DEREF-LABEL: define protected amdgpu_kernel void @foo(
+; DEREF: tail call dereferenceable(256) ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()
+;
+; WITHOUT-LABEL: define protected amdgpu_kernel void @foo(
+; WITHOUT-SAME: ptr addrspace(1) noundef readonly captures(none) [[D_A_COERCE:%.*]], ptr addrspace(1) noundef readonly captures(none) [[D_B_COERCE:%.*]], ptr addrspace(1) noundef writeonly captures(none) [[D_C_COERCE:%.*]], i32 noundef [[COUNT:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+; WITHOUT-NEXT: [[ENTRY:.*:]]
+; WITHOUT-NEXT: [[TMP0:%.*]] = tail call noundef range(i32 0, 1024) i32 @llvm.amdgcn.workitem.id.y()
+; WITHOUT-NEXT: [[CMP11:%.*]] = icmp samesign ult i32 [[TMP0]], 4
+; WITHOUT-NEXT: br i1 [[CMP11]], label %[[FOR_BODY_LR_PH:.*]], label %[[FOR_COND_CLEANUP:.*]]
+; WITHOUT: [[FOR_BODY_LR_PH]]:
+; WITHOUT-NEXT: [[TMP1:%.*]] = tail call i32 @llvm.amdgcn.workgroup.id.x()
+; WITHOUT-NEXT: [[TMP2:%.*]] = tail call noundef range(i32 0, 1024) i32 @llvm.amdgcn.workitem.id.x()
+; WITHOUT-NEXT: [[CMP79:%.*]] = icmp samesign ult i32 [[TMP2]], 4
+; WITHOUT-NEXT: [[CONV:%.*]] = sext i32 [[TMP1]] to i64
+; WITHOUT-NEXT: [[MUL:%.*]] = mul nsw i64 [[CONV]], 192
+; WITHOUT-NEXT: [[TMP3:%.*]] = tail call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()
+; WITHOUT-NEXT: [[TMP4:%.*]] = getelementptr inbounds nuw i8, ptr addrspace(4) [[TMP3]], i64 12
+; WITHOUT-NEXT: [[TMP5:%.*]] = getelementptr inbounds nuw i8, ptr addrspace(4) [[TMP3]], i64 14
+; WITHOUT-NEXT: [[DOTIN_I_I_I:%.*]] = load i16, ptr addrspace(4) [[TMP5]], align 2, !tbaa [[SHORT_TBAA6:![0-9]+]]
+; WITHOUT-NEXT: [[CONV_I_I:%.*]] = zext i16 [[DOTIN_I_I_I]] to i32
+; WITHOUT-NEXT: br label %[[FOR_BODY:.*]]
+;
+; WITH-LABEL: define protected amdgpu_kernel void @foo(
+; WITH-SAME: ptr addrspace(1) noundef readonly captures(none) [[D_A_COERCE:%.*]], ptr addrspace(1) noundef readonly captures(none) [[D_B_COERCE:%.*]], ptr addrspace(1) noundef writeonly captures(none) [[D_C_COERCE:%.*]], i32 noundef [[COUNT:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+; WITH-NEXT: [[ENTRY:.*:]]
+; WITH-NEXT: [[TMP0:%.*]] = tail call noundef range(i32 0, 1024) i32 @llvm.amdgcn.workitem.id.y()
+; WITH-NEXT: [[CMP11:%.*]] = icmp samesign ult i32 [[TMP0]], 4
+; WITH-NEXT: br i1 [[CMP11]], label %[[FOR_BODY_LR_PH:.*]], label %[[FOR_COND_CLEANUP:.*]]
+; WITH: [[FOR_BODY_LR_PH]]:
+; WITH-NEXT: [[TMP1:%.*]] = tail call i32 @llvm.amdgcn.workgroup.id.x()
+; WITH-NEXT: [[TMP2:%.*]] = tail call noundef range(i32 0, 1024) i32 @llvm.amdgcn.workitem.id.x()
+; WITH-NEXT: [[CMP79:%.*]] = icmp samesign ult i32 [[TMP2]], 4
+; WITH-NEXT: [[CONV:%.*]] = sext i32 [[TMP1]] to i64
+; WITH-NEXT: [[MUL:%.*]] = mul nsw i64 [[CONV]], 192
+; WITH-NEXT: [[TMP3:%.*]] = tail call dereferenceable(256) ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()
+; WITH-NEXT: [[TMP4:%.*]] = getelementptr inbounds nuw i8, ptr addrspace(4) [[TMP3]], i64 12
+; WITH-NEXT: [[TMP5:%.*]] = getelementptr inbounds nuw i8, ptr addrspace(4) [[TMP3]], i64 14
+; WITH-NEXT: [[DOTIN_I_I_I:%.*]] = load i16, ptr addrspace(4) [[TMP5]], align 2, !tbaa [[SHORT_TBAA6:![0-9]+]]
+; WITH-NEXT: [[CONV_I_I:%.*]] = zext i16 [[DOTIN_I_I_I]] to i32
+; WITH-NEXT: [[DOTIN_I_I_I7:%.*]] = load i16, ptr addrspace(4) [[TMP4]], align 4
+; WITH-NEXT: [[CONV_I_I8:%.*]] = zext i16 [[DOTIN_I_I_I7]] to i32
+; WITH-NEXT: br label %[[FOR_BODY:.*]]
+;
+entry:
+ %0 = tail call noundef range(i32 0, 1024) i32 @llvm.amdgcn.workitem.id.y()
+ %cmp11 = icmp samesign ult i32 %0, 4
+ br i1 %cmp11, label %for.body.lr.ph, label %for.cond.cleanup
+
+for.body.lr.ph: ; preds = %entry
+ %1 = tail call i32 @llvm.amdgcn.workgroup.id.x()
+ %2 = tail call noundef range(i32 0, 1024) i32 @llvm.amdgcn.workitem.id.x()
+ %cmp79 = icmp samesign ult i32 %2, 4
+ %conv = sext i32 %1 to i64
+ %mul = mul nsw i64 %conv, 192
+ %3 = tail call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()
+ %4 = getelementptr inbounds nuw i8, ptr addrspace(4) %3, i64 12
+ %5 = getelementptr inbounds nuw i8, ptr addrspace(4) %3, i64 14
+ %.in.i.i.i = load i16, ptr addrspace(4) %5, align 2, !tbaa !12
+ %conv.i.i = zext i16 %.in.i.i.i to i32
+ br label %for.body
+
+for.cond.cleanup: ; preds = %for.cond.cleanup8, %entry
+ ret void
+
+for.body: ; preds = %for.cond.cleanup8, %for.body.lr.ph
+ %thread_y.012 = phi i32 [ %0, %for.body.lr.ph ], [ %add21, %for.cond.cleanup8 ]
+ br i1 %cmp79, label %for.body9.lr.ph, label %for.cond.cleanup8
+
+for.body9.lr.ph: ; preds = %for.body
+ %mul10 = shl nuw nsw i32 %thread_y.012, 2
+ %conv11 = zext nneg i32 %mul10 to i64
+ %add = add nuw nsw i64 %mul, %conv11
+ %.in.i.i.i7 = load i16, ptr addrspace(4) %4, align 4, !tbaa !12
+ %conv.i.i8 = zext i16 %.in.i.i.i7 to i32
+ br label %for.body9
+
+for.cond.cleanup8: ; preds = %for.body9, %for.body
+ %add21 = add nuw nsw i32 %thread_y.012, %conv.i.i
+ %cmp = icmp samesign ult i32 %add21, 4
+ br i1 %cmp, label %for.body, label %for.cond.cleanup, !llvm.loop !16
+
+for.body9: ; preds = %for.body9, %for.body9.lr.ph
+ %thread_x.010 = phi i32 [ %2, %for.body9.lr.ph ], [ %add18, %for.body9 ]
+ %conv12 = zext nneg i32 %thread_x.010 to i64
+ %add13 = add nuw nsw i64 %add, %conv12
+ %arrayidx = getelementptr inbounds double, ptr addrspace(1) %d_a.coerce, i64 %add13
+ %6 = load double, ptr addrspace(1) %arrayidx, align 8, !tbaa !18
+ %arrayidx14 = getelementptr inbounds double, ptr addrspace(1) %d_b.coerce, i64 %add13
+ %7 = load double, ptr addrspace(1) %arrayidx14, align 8, !tbaa !18
+ %add15 = fadd contract double %6, %7
+ %arrayidx16 = getelementptr inbounds double, ptr addrspace(1) %d_c.coerce, i64 %add13
+ store double %add15, ptr addrspace(1) %arrayidx16, align 8, !tbaa !18
+ %add18 = add nuw nsw i32 %thread_x.010, %conv.i.i8
+ %cmp7 = icmp samesign ult i32 %add18, 4
+ br i1 %cmp7, label %for.body9, label %for.cond.cleanup8, !llvm.loop !20
+}
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare noundef range(i32 0, 1024) i32 @llvm.amdgcn.workitem.id.x() #1
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare noundef range(i32 0, 1024) i32 @llvm.amdgcn.workitem.id.y() #1
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare noundef align 4 ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr() #1
+
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare noundef i32 @llvm.amdgcn.workgroup.id.x() #1
+
+attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) "amdgpu-agpr-alloc"="0" "amdgpu-flat-work-group-size"="1,192" "amdgpu-no-cluster-id-x" "amdgpu-no-cluster-id-y" "amdgpu-no-cluster-id-z" "amdgpu-no-completion-action" "amdgpu-no-default-queue" "amdgpu-no-dispatch-id" "amdgpu-no-dispatch-ptr" "amdgpu-no-flat-scratch-init" "amdgpu-no-heap-ptr" "amdgpu-no-hostcall-ptr" "amdgpu-no-lds-kernel-id" "amdgpu-no-multigrid-sync-arg" "amdgpu-no-queue-ptr" "amdgpu-no-workgroup-id-x" "amdgpu-no-workgroup-id-y" "amdgpu-no-workgroup-id-z" "amdgpu-no-workitem-id-x" "amdgpu-no-workitem-id-z" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx942" "uniform-work-group-size"="true" }
+attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
+
+!llvm.module.flags = !{!0}
+!llvm.errno.tbaa = !{!7}
+!opencl.ocl.version = !{!11}
+
+!0 = !{i32 1, !"amdhsa_code_object_version", i32 600}
+!7 = !{!8, !8, i64 0}
+!8 = !{!"int", !9, i64 0}
+!9 = !{!"omnipotent char", !10, i64 0}
+!10 = !{!"Simple C++ TBAA"}
+!11 = !{i32 2, i32 0}
+!12 = !{!13, !13, i64 0}
+!13 = !{!"short", !14, i64 0}
+!14 = !{!"omnipotent char", !15, i64 0}
+!15 = !{!"Simple C/C++ TBAA"}
+!16 = distinct !{!16, !17}
+!17 = !{!"llvm.loop.mustprogress"}
+!18 = !{!19, !19, i64 0}
+!19 = !{!"double", !9, i64 0}
+!20 = distinct !{!20, !17}
diff --git a/llvm/test/CodeGen/AMDGPU/licm-after-marking-dereferenceable.ll b/llvm/test/CodeGen/AMDGPU/licm-after-marking-dereferenceable.ll
new file mode 100644
index 0000000000000..fb684fc84f81b
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/licm-after-marking-dereferenceable.ll
@@ -0,0 +1,172 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -O2 -mtriple=amdgcn--amdhsa -disable-verify < %s | FileCheck %s
+
+; There is a depth-2 loopnest.
+; Make sure there is no s_load instruction in inner loop's preheader as the load is hoisted to the outer loop's preheader.
+;
+
+; ModuleID = 'mark-dereferenceable-licm.ll'
+target datalayout = "e-m:e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128:128:48-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9"
+
+; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite)
+define protected amdgpu_kernel void @foo(ptr addrspace(1) noundef readonly captures(none) %d_a.coerce, ptr addrspace(1) noundef readonly captures(none) %d_b.coerce, ptr addrspace(1) noundef writeonly captures(none) %d_c.coerce, i32 noundef %count) local_unnamed_addr #0 {
+; CHECK-LABEL: foo:
+; CHECK: ; %bb.0: ; %entry
+; CHECK-NEXT: v_bfe_u32 v8, v0, 10, 10
+; CHECK-NEXT: v_cmp_gt_u32_e32 vcc, 4, v8
+; CHECK-NEXT: s_and_saveexec_b64 s[4:5], vcc
+; CHECK-NEXT: s_cbranch_execz .LBB0_6
+; CHECK-NEXT: ; %bb.1: ; %for.body.lr.ph
+; CHECK-NEXT: s_load_dword s3, s[0:1], 0x2c
+; CHECK-NEXT: s_load_dwordx4 s[4:7], s[0:1], 0x0
+; CHECK-NEXT: s_load_dwordx2 s[8:9], s[0:1], 0x10
+; CHECK-NEXT: v_lshlrev_b32_e32 v2, 2, v8
+; CHECK-NEXT: v_mov_b32_e32 v3, 0
+; CHECK-NEXT: v_mov_b32_e32 v1, 0xc0
+; CHECK-NEXT: v_and_b32_e32 v0, 0x3ff, v0
+; CHECK-NEXT: v_mad_i64_i32 v[4:5], s[0:1], s2, v1, v[2:3]
+; CHECK-NEXT: v_mov_b32_e32 v1, v3
+; CHECK-NEXT: v_lshl_add_u64 v[2:3], v[4:5], 0, v[0:1]
+; CHECK-NEXT: s_waitcnt lgkmcnt(0)
+; CHECK-NEXT: s_lshr_b32 s12, s3, 16
+; CHECK-NEXT: s_and_b32 s13, s3, 0xffff
+; CHECK-NEXT: v_lshlrev_b64 v[6:7], 3, v[2:3]
+; CHECK-NEXT: v_cmp_gt_u32_e32 vcc, 4, v0
+; CHECK-NEXT: v_lshl_add_u64 v[2:3], s[8:9], 0, v[6:7]
+; CHECK-NEXT: s_lshl_b32 s2, s12, 5
+; CHECK-NEXT: s_mov_b32 s3, 0
+; CHECK-NEXT: s_lshl_b32 s14, s13, 3
+; CHECK-NEXT: v_lshl_add_u64 v[4:5], s[6:7], 0, v[6:7]
+; CHECK-NEXT: v_lshl_add_u64 v[6:7], s[4:5], 0, v[6:7]
+; CHECK-NEXT: s_mov_b64 s[4:5], 0
+; CHECK-NEXT: s_branch .LBB0_3
+; CHECK-NEXT: .LBB0_2: ; %Flow18
+; CHECK-NEXT: ; in Loop: Header=BB0_3 Depth=1
+; CHECK-NEXT: s_or_b64 exec, exec, s[6:7]
+; CHECK-NEXT: v_add_u32_e32 v8, s12, v8
+; CHECK-NEXT: v_cmp_lt_u32_e64 s[0:1], 3, v8
+; CHECK-NEXT: v_lshl_add_u64 v[2:3], v[2:3], 0, s[2:3]
+; CHECK-NEXT: v_lshl_add_u64 v[4:5], v[4:5], 0, s[2:3]
+; CHECK-NEXT: s_or_b64 s[4:5], s[0:1], s[4:5]
+; CHECK-NEXT: v_lshl_add_u64 v[6:7], v[6:7], 0, s[2:3]
+; CHECK-NEXT: s_andn2_b64 exec, exec, s[4:5]
+; CHECK-NEXT: s_cbranch_execz .LBB0_6
+; CHECK-NEXT: .LBB0_3: ; %for.body
+; CHECK-NEXT: ; =>This Loop Header: Depth=1
+; CHECK-NEXT: ; Child Loop BB0_5 Depth 2
+; CHECK-NEXT: s_and_saveexec_b64 s[6:7], vcc
+; CHECK-NEXT: s_cbranch_execz .LBB0_2
+; CHECK-NEXT: ; %bb.4: ; %for.body9.lr.ph
+; CHECK-NEXT: ; in Loop: Header=BB0_3 Depth=1
+; CHECK-NEXT: s_mov_b64 s[8:9], 0
+; CHECK-NEXT: s_mov_b64 s[10:11], 0
+; CHECK-NEXT: v_mov_b32_e32 v1, v0
+; CHECK-NEXT: .LBB0_5: ; %for.body9
+; CHECK-NEXT: ; Parent Loop BB0_3 Depth=1
+; CHECK-NEXT: ; => This Inner Loop Header: Depth=2
+; CHECK-NEXT: v_lshl_add_u64 v[10:11], v[6:7], 0, s[10:11]
+; CHECK-NEXT: v_lshl_add_u64 v[12:13], v[4:5], 0, s[10:11]
+; CHECK-NEXT: global_load_dwordx2 v[14:15], v[10:11], off
+; CHECK-NEXT: global_load_dwordx2 v[16:17], v[12:13], off
+; CHECK-NEXT: v_lshl_add_u64 v[10:11], v[2:3], 0, s[10:11]
+; CHECK-NEXT: v_add_u32_e32 v1, s13, v1
+; CHECK-NEXT: s_add_u32 s10, s10, s14
+; CHECK-NEXT: s_addc_u32 s11, s11, 0
+; CHECK-NEXT: v_cmp_lt_u32_e64 s[0:1], 3, v1
+; CHECK-NEXT: s_or_b64 s[8:9], s[0:1], s[8:9]
+; CHECK-NEXT: s_waitcnt vmcnt(0)
+; CHECK-NEXT: v_add_f64 v[12:13], v[14:15], v[16:17]
+; CHECK-NEXT: global_store_dwordx2 v[10:11], v[12:13], off
+; CHECK-NEXT: s_andn2_b64 exec, exec, s[8:9]
+; CHECK-NEXT: s_cbranch_execnz .LBB0_5
+; CHECK-NEXT: s_branch .LBB0_2
+; CHECK-NEXT: .LBB0_6: ; %Flow20
+; CHECK-NEXT: s_endpgm
+entry:
+ %0 = tail call noundef range(i32 0, 1024) i32 @llvm.amdgcn.workitem.id.y()
+ %cmp11 = icmp samesign ult i32 %0, 4
+ br i1 %cmp11, label %for.body.lr.ph, label %for.cond.cleanup
+
+for.body.lr.ph: ; preds = %entry
+ %1 = tail call i32 @llvm.amdgcn.workgroup.id.x()
+ %2 = tail call noundef range(i32 0, 1024) i32 @llvm.amdgcn.workitem.id.x()
+ %cmp79 = icmp samesign ult i32 %2, 4
+ %conv = sext i32 %1 to i64
+ %mul = mul nsw i64 %conv, 192
+ %3 = tail call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()
+ %4 = getelementptr inbounds nuw i8, ptr addrspace(4) %3, i64 12
+ %5 = getelementptr inbounds nuw i8, ptr addrspace(4) %3, i64 14
+ %.in.i.i.i = load i16, ptr addrspace(4) %5, align 2, !tbaa !12
+ %conv.i.i = zext i16 %.in.i.i.i to i32
+ br label %for.body
+
+for.cond.cleanup: ; preds = %for.cond.cleanup8, %entry
+ ret void
+
+for.body: ; preds = %for.cond.cleanup8, %for.body.lr.ph
+ %thread_y.012 = phi i32 [ %0, %for.body.lr.ph ], [ %add21, %for.cond.cleanup8 ]
+ br i1 %cmp79, label %for.body9.lr.ph, label %for.cond.cleanup8
+
+for.body9.lr.ph: ; preds = %for.body
+ %mul10 = shl nuw nsw i32 %thread_y.012, 2
+ %conv11 = zext nneg i32 %mul10 to i64
+ %add = add nuw nsw i64 %mul, %conv11
+ %.in.i.i.i7 = load i16, ptr addrspace(4) %4, align 4, !tbaa !12
+ %conv.i.i8 = zext i16 %.in.i.i.i7 to i32
+ br label %for.body9
+
+for.cond.cleanup8: ; preds = %for.body9, %for.body
+ %add21 = add nuw nsw i32 %thread_y.012, %conv.i.i
+ %cmp = icmp samesign ult i32 %add21, 4
+ br i1 %cmp, label %for.body, label %for.cond.cleanup, !llvm.loop !16
+
+for.body9: ; preds = %for.body9, %for.body9.lr.ph
+ %thread_x.010 = phi i32 [ %2, %for.body9.lr.ph ], [ %add18, %for.body9 ]
+ %conv12 = zext nneg i32 %thread_x.010 to i64
+ %add13 = add nuw nsw i64 %add, %conv12
+ %arrayidx = getelementptr inbounds double, ptr addrspace(1) %d_a.coerce, i64 %add13
+ %6 = load double, ptr addrspace(1) %arrayidx, align 8, !tbaa !18
+ %arrayidx14 = getelementptr inbounds double, ptr addrspace(1) %d_b.coerce, i64 %add13
+ %7 = load double, ptr addrspace(1) %arrayidx14, align 8, !tbaa !18
+ %add15 = fadd contract double %6, %7
+ %arrayidx16 = getelementptr inbounds double, ptr addrspace(1) %d_c.coerce, i64 %add13
+ store double %add15, ptr addrspace(1) %arrayidx16, align 8, !tbaa !18
+ %add18 = add nuw nsw i32 %thread_x.010, %conv.i.i8
+ %cmp7 = icmp samesign ult i32 %add18, 4
+ br i1 %cmp7, label %for.body9, label %for.cond.cleanup8, !llvm.loop !20
+}
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare noundef range(i32 0, 1024) i32 @llvm.amdgcn.workitem.id.x() #1
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare noundef range(i32 0, 1024) i32 @llvm.amdgcn.workitem.id.y() #1
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare noundef align 4 ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr() #1
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare noundef i32 @llvm.amdgcn.workgroup.id.x() #1
+
+attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) "amdgpu-agpr-alloc"="0" "amdgpu-flat-work-group-size"="1,192" "amdgpu-no-cluster-id-x" "amdgpu-no-cluster-id-y" "amdgpu-no-cluster-id-z" "amdgpu-no-completion-action" "amdgpu-no-default-queue" "amdgpu-no-dispatch-id" "amdgpu-no-dispatch-ptr" "amdgpu-no-flat-scratch-init" "amdgpu-no-heap-ptr" "amdgpu-no-hostcall-ptr" "amdgpu-no-lds-kernel-id" "amdgpu-no-multigrid-sync-arg" "amdgpu-no-queue-ptr" "amdgpu-no-workgroup-id-x" "amdgpu-no-workgroup-id-y" "amdgpu-no-workgroup-id-z" "amdgpu-no-workitem-id-x" "amdgpu-no-workitem-id-z" "no-trapping-math"="true" "stack-protector-...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/182206
More information about the llvm-commits
mailing list