[llvm] [DirectX] Allow llvm lifetime intrinsics to pass on to the DirectX backend (PR #136622)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 21 14:58:33 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-directx
Author: Farzon Lotfi (farzonl)
<details>
<summary>Changes</summary>
fixes #<!-- -->136620
It was determined that the lifetime intrinsics generated by clang are likely more correct than the ones in DXC hence explaining the missing lifetimes between the IR diffs.
As such we are legalizing lllvm lifetime intrinsics by letting them all pass on through.
---
Full diff: https://github.com/llvm/llvm-project/pull/136622.diff
2 Files Affected:
- (modified) llvm/lib/Target/DirectX/DXILOpLowering.cpp (+2)
- (added) llvm/test/CodeGen/DirectX/legalize-lifetimes.ll (+20)
``````````diff
diff --git a/llvm/lib/Target/DirectX/DXILOpLowering.cpp b/llvm/lib/Target/DirectX/DXILOpLowering.cpp
index f28171b6d4908..fe6dff57e2625 100644
--- a/llvm/lib/Target/DirectX/DXILOpLowering.cpp
+++ b/llvm/lib/Target/DirectX/DXILOpLowering.cpp
@@ -753,6 +753,8 @@ class OpLowerer {
case Intrinsic::dx_resource_casthandle:
// NOTE: llvm.dbg.value is supported as is in DXIL.
case Intrinsic::dbg_value:
+ case Intrinsic::lifetime_start:
+ case Intrinsic::lifetime_end:
case Intrinsic::not_intrinsic:
continue;
default: {
diff --git a/llvm/test/CodeGen/DirectX/legalize-lifetimes.ll b/llvm/test/CodeGen/DirectX/legalize-lifetimes.ll
new file mode 100644
index 0000000000000..7997734a75c1d
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/legalize-lifetimes.ll
@@ -0,0 +1,20 @@
+; RUN: opt -S -passes='dxil-op-lower' -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
+
+; CHECK-NOT: error: Unsupported intrinsic llvm.lifetime.start.p0 for DXIL lowering
+; CHECK-NOT: error: Unsupported intrinsic llvm.lifetime.end.p0 for DXIL lowering
+; CHECK-LABEL: define void @test_legal_lifetime() {
+; CHECK-NEXT: [[ACCUM_I_FLAT:%.*]] = alloca [1 x i32], align 4
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, ptr [[ACCUM_I_FLAT]], i32 0
+; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr nonnull [[ACCUM_I_FLAT]])
+; CHECK-NEXT: store i32 0, ptr [[GEP]], align 4
+; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr nonnull [[ACCUM_I_FLAT]])
+; CHECK-NEXT: ret void
+;
+define void @test_legal_lifetime() {
+ %accum.i.flat = alloca [1 x i32], align 4
+ %gep = getelementptr i32, ptr %accum.i.flat, i32 0
+ call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %accum.i.flat)
+ store i32 0, ptr %gep, align 4
+ call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %accum.i.flat)
+ ret void
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/136622
More information about the llvm-commits
mailing list