[llvm] [DirectX] Allow llvm lifetime intrinsics to pass on to the DirectX backend (PR #136622)

Farzon Lotfi via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 21 14:57:59 PDT 2025


https://github.com/farzonl created https://github.com/llvm/llvm-project/pull/136622

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.

>From fabb1f2507f06480236ec7bc4a0ef28cd458b678 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi <farzonlotfi at microsoft.com>
Date: Mon, 21 Apr 2025 17:54:57 -0400
Subject: [PATCH] [DirectX] Allow llvm lifetime intrinsics to pass on to the
 DirectX backend

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.
---
 llvm/lib/Target/DirectX/DXILOpLowering.cpp    |  2 ++
 .../CodeGen/DirectX/legalize-lifetimes.ll     | 20 +++++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 llvm/test/CodeGen/DirectX/legalize-lifetimes.ll

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
+}



More information about the llvm-commits mailing list