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

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 22 11:25:36 PDT 2025


Author: Farzon Lotfi
Date: 2025-04-22T14:25:33-04:00
New Revision: 5ebf08cd9a1d4b2697a0d3ad588ddbdc553362dc

URL: https://github.com/llvm/llvm-project/commit/5ebf08cd9a1d4b2697a0d3ad588ddbdc553362dc
DIFF: https://github.com/llvm/llvm-project/commit/5ebf08cd9a1d4b2697a0d3ad588ddbdc553362dc.diff

LOG: [DirectX] Allow llvm lifetime intrinsics to pass on to the DirectX backend (#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.

Added: 
    llvm/test/CodeGen/DirectX/legalize-lifetimes.ll

Modified: 
    llvm/lib/Target/DirectX/DXILOpLowering.cpp

Removed: 
    


################################################################################
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..44b2419a05d64
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/legalize-lifetimes.ll
@@ -0,0 +1,18 @@
+; RUN: opt -S -passes='dxil-op-lower' -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
+
+; 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