[llvm] ab75180 - [DirectX] Remove trivially dead functions at linkage finalize (#106146)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 17 11:54:55 PDT 2024


Author: Greg Roth
Date: 2024-10-17T12:54:52-06:00
New Revision: ab7518050183162f09724ef8682a580cc68709bc

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

LOG: [DirectX] Remove trivially dead functions at linkage finalize (#106146)

Functions are not removed even when made internal by
DXILFinalizeLinkage. The removal code is called from alwaysinliner and
globalopt, which are invoked too early to remove functions made internal
by this pass.

This adds a check similar to that in alwaysinliner that removes
trivially dead functions after being marked internal. It refactors that
code a bit to make it simpler including reversing what is stored int he
work queue.

Tests both the pass in isolation and the full i0nlining, linkage
finalization and function removal steps.

Fixes #106139

Added: 
    llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead-lib.ll
    llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll

Modified: 
    llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp
    llvm/test/CodeGen/DirectX/ShaderFlags/double-extensions.ll
    llvm/test/CodeGen/DirectX/ShaderFlags/doubles.ll
    llvm/test/CodeGen/DirectX/conflicting-bitcast-insert.ll
    llvm/test/CodeGen/DirectX/finalize_linkage.ll
    llvm/test/CodeGen/DirectX/fneg-conversion.ll
    llvm/test/CodeGen/DirectX/omit-bitcast-insert.ll
    llvm/test/CodeGen/DirectX/scalar-load.ll
    llvm/test/CodeGen/DirectX/scalar-store.ll
    llvm/test/CodeGen/DirectX/scalarize-two-calls.ll
    llvm/test/CodeGen/DirectX/strip-fn-attrs.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp
index d32dda2a67c951..aa1f55c572df29 100644
--- a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp
+++ b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp
@@ -19,20 +19,20 @@
 using namespace llvm;
 
 static bool finalizeLinkage(Module &M) {
-  SmallPtrSet<Function *, 8> EntriesAndExports;
+  SmallPtrSet<Function *, 8> Funcs;
 
-  // Find all entry points and export functions
+  // Collect non-entry and non-exported functions to set to internal linkage.
   for (Function &EF : M.functions()) {
-    if (!EF.hasFnAttribute("hlsl.shader") && !EF.hasFnAttribute("hlsl.export"))
+    if (EF.hasFnAttribute("hlsl.shader") || EF.hasFnAttribute("hlsl.export"))
       continue;
-    EntriesAndExports.insert(&EF);
+    Funcs.insert(&EF);
   }
 
-  for (Function &F : M.functions()) {
-    if (F.getLinkage() == GlobalValue::ExternalLinkage &&
-        !EntriesAndExports.contains(&F)) {
-      F.setLinkage(GlobalValue::InternalLinkage);
-    }
+  for (Function *F : Funcs) {
+    if (F->getLinkage() == GlobalValue::ExternalLinkage)
+      F->setLinkage(GlobalValue::InternalLinkage);
+    if (F->isDefTriviallyDead())
+      M.getFunctionList().erase(F);
   }
 
   return false;

diff  --git a/llvm/test/CodeGen/DirectX/ShaderFlags/double-extensions.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/double-extensions.ll
index d027216e4213d5..a8d5f9c78f0b43 100644
--- a/llvm/test/CodeGen/DirectX/ShaderFlags/double-extensions.ll
+++ b/llvm/test/CodeGen/DirectX/ShaderFlags/double-extensions.ll
@@ -9,11 +9,12 @@ target triple = "dxil-pc-shadermodel6.7-library"
 ; CHECK-NEXT: ;       Double-precision extensions for 11.1
 ; CHECK-NEXT: ; Note: extra DXIL module flags:
 ; CHECK-NEXT: {{^;$}}
-define double @div(double %a, double %b) {
+define double @div(double %a, double %b) #0 {
   %res = fdiv double %a, %b
   ret double %res
 }
 
+attributes #0 = { convergent norecurse nounwind "hlsl.export"}
 
 ; DXC: - Name:            SFI0
 ; DXC-NEXT:     Size:            8

diff  --git a/llvm/test/CodeGen/DirectX/ShaderFlags/doubles.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/doubles.ll
index c1a4c219a16951..e9b44240e10b9b 100644
--- a/llvm/test/CodeGen/DirectX/ShaderFlags/doubles.ll
+++ b/llvm/test/CodeGen/DirectX/ShaderFlags/doubles.ll
@@ -9,11 +9,13 @@ target triple = "dxil-pc-shadermodel6.7-library"
 ; CHECK-NEXT: ; Note: extra DXIL module flags:
 ; CHECK-NEXT: {{^;$}}
 
-define double @add(double %a, double %b) {
+define double @add(double %a, double %b) #0 {
   %sum = fadd double %a, %b
   ret double %sum
 }
 
+attributes #0 = { convergent norecurse nounwind "hlsl.export"}
+
 ; DXC: - Name:            SFI0
 ; DXC-NEXT:     Size:            8
 ; DXC-NEXT:     Flags:

diff  --git a/llvm/test/CodeGen/DirectX/conflicting-bitcast-insert.ll b/llvm/test/CodeGen/DirectX/conflicting-bitcast-insert.ll
index 8f5d3ae8641717..39e21daceea81a 100644
--- a/llvm/test/CodeGen/DirectX/conflicting-bitcast-insert.ll
+++ b/llvm/test/CodeGen/DirectX/conflicting-bitcast-insert.ll
@@ -1,25 +1,27 @@
 ; RUN: llc --filetype=asm %s -o - | FileCheck %s
 target triple = "dxil-unknown-shadermodel6.7-library"
 
-define i64 @test(ptr %p) {
+define i64 @test(ptr %p) #0 {
   store i32 0, ptr %p
   %v = load i64, ptr %p
   ret i64 %v
 }
 
-; CHECK: define internal i64 @test(ptr %p) {
+; CHECK: define i64 @test(ptr %p) #0 {
 ; CHECK-NEXT: %1 = bitcast ptr %p to ptr
 ; CHECK-NEXT: store i32 0, ptr %1, align 4
 ; CHECK-NEXT: %2 = bitcast ptr %p to ptr
 ; CHECK-NEXT: %3 = load i64, ptr %2, align 8
 
-define i64 @testGEP(ptr %p) {
+define i64 @testGEP(ptr %p) #0 {
   %ptr = getelementptr i32, ptr %p, i32 4
   %val = load i64, ptr %p
   ret i64 %val
 }
 
-; CHECK: define internal i64 @testGEP(ptr %p) {
+attributes #0 = { convergent norecurse nounwind "hlsl.export"}
+
+; CHECK: define i64 @testGEP(ptr %p) #0 {
 ; CHECK-NEXT:   %1 = bitcast ptr %p to ptr
 ; CHECK-NEXT:   %ptr = getelementptr i32, ptr %1, i32 4
 ; CHECK-NEXT:   %2 = bitcast ptr %p to ptr

diff  --git a/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead-lib.ll b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead-lib.ll
new file mode 100644
index 00000000000000..202609c8156a72
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead-lib.ll
@@ -0,0 +1,222 @@
+; RUN: opt -S -dxil-finalize-linkage -mtriple=dxil-unknown-shadermodel6.5-library %s | FileCheck %s
+; RUN: llc %s --filetype=asm -o - | FileCheck %s
+
+target triple = "dxilv1.5-pc-shadermodel6.5-compute"
+
+; Confirm that DXILFinalizeLinkage will remove functions that have compatible
+; linkage and are not called from anywhere. This should be any function that
+; is not explicitly marked export and is not an entry point.
+
+; Has no specified inlining/linking behavior and is uncalled, this should be removed.
+; CHECK-NOT: define {{.*}}doNothingUncalled
+define void @"?doNothingUncalled@@YAXXZ"() #2 {
+entry:
+  ret void
+}
+
+; Alwaysinline and uncalled, this should be removed.
+; CHECK-NOT: define {{.*}}doAlwaysInlineUncalled
+define void @"?doAlwaysInlineUncalled@@YAXXZ"() #0 {
+entry:
+  ret void
+}
+
+; Noinline and uncalled, this should be removed.
+; CHECK-NOT: define {{.*}}doNoinlineUncalled
+define void @"?doNoinlineUncalled@@YAXXZ"() #4 {
+entry:
+  ret void
+}
+
+; No inlining attribute, internal, and uncalled; this should be removed.
+; CHECK-NOT: define {{.*}}doInternalUncalled
+define internal void @"?doInternalUncalled@@YAXXZ"() #2 {
+entry:
+  ret void
+}
+
+; Alwaysinline, internal, and uncalled; this should be removed.
+; CHECK-NOT: define {{.*}}doAlwaysInlineInternalUncalled
+define internal void @"?doAlwaysInlineInternalUncalled@@YAXXZ"() #0 {
+entry:
+  ret void
+}
+
+; Noinline, internal, and uncalled; this should be removed.
+; CHECK-NOT: define {{.*}}doNoinlineInternalUncalled
+define internal void @"?doNoinlineInternalUncalled@@YAXXZ"() #4 {
+entry:
+  ret void
+}
+
+; Marked external and uncalled, this should become internal and be removed.
+; CHECK-NOT: define {{.*}}doExternalUncalled
+define external void @"?doExternalUncalled@@YAXXZ"() #2 {
+entry:
+  ret void
+}
+
+; Alwaysinline, external and uncalled, this should become internal and be removed.
+; CHECK-NOT: define {{.*}}doAlwaysInlineExternalUncalled
+define external void @"?doAlwaysInlineExternalUncalled@@YAXXZ"() #0 {
+entry:
+  ret void
+}
+
+; Noinline, external and uncalled, this should become internal and be removed.
+; CHECK-NOT: define {{.*}}doNoinlineExternalUncalled
+define external void @"?doNoinlineExternalUncalled@@YAXXZ"() #4 {
+entry:
+  ret void
+}
+
+; No inlining attribute and called, this should stay.
+; CHECK: define {{.*}}doNothingCalled
+define void @"?doNothingCalled@@YAXXZ"() #2 {
+entry:
+  ret void
+}
+
+; Alwaysinline and called, this should stay.
+; CHECK: define {{.*}}doAlwaysInlineCalled
+define void @"?doAlwaysInlineCalled@@YAXXZ"() #0 {
+entry:
+  ret void
+}
+
+; Noinline and called, this should stay.
+; CHECK: define {{.*}}doNoinlineCalled
+define void @"?doNoinlineCalled@@YAXXZ"() #4 {
+entry:
+  ret void
+}
+
+; No inlining attribute, internal, and called; this should stay.
+; CHECK: define {{.*}}doInternalCalled
+define internal void @"?doInternalCalled@@YAXXZ"() #2 {
+entry:
+  ret void
+}
+
+; Alwaysinline, internal, and called; this should stay.
+; CHECK: define {{.*}}doAlwaysInlineInternalCalled
+define internal void @"?doAlwaysInlineInternalCalled@@YAXXZ"() #0 {
+entry:
+  ret void
+}
+
+; Noinline, internal, and called; this should stay.
+; CHECK: define {{.*}}doNoinlineInternalCalled
+define internal void @"?doNoinlineInternalCalled@@YAXXZ"() #4 {
+entry:
+  ret void
+}
+
+; Marked external and called, this should become internal and stay.
+; CHECK: define {{.*}}doExternalCalled
+define external void @"?doExternalCalled@@YAXXZ"() #2 {
+entry:
+  ret void
+}
+
+; Always inlined, external and called, this should become internal and stay.
+; CHECK: define {{.*}}doAlwaysInlineExternalCalled
+define external void @"?doAlwaysInlineExternalCalled@@YAXXZ"() #0 {
+entry:
+  ret void
+}
+
+; Noinline, external and called, this should become internal and stay.
+; CHECK: define {{.*}}doNoinlineExternalCalled
+define external void @"?doNoinlineExternalCalled@@YAXXZ"() #4 {
+entry:
+  ret void
+}
+
+; No inlining attribute and exported, this should stay.
+; CHECK: define {{.*}}doNothingExported
+define void @"?doNothingExported@@YAXXZ"() #3 {
+entry:
+  ret void
+}
+
+; Alwaysinline and exported, this should stay.
+; CHECK: define {{.*}}doAlwaysInlineExported
+define void @"?doAlwaysInlineExported@@YAXXZ"() #1 {
+entry:
+  ret void
+}
+
+; Noinline attribute and exported, this should stay.
+; CHECK: define {{.*}}doNoinlineExported
+define void @"?doNoinlineExported@@YAXXZ"() #5 {
+entry:
+  ret void
+}
+
+; No inlining attribute, internal, and exported; this should stay.
+; CHECK: define {{.*}}doInternalExported
+define internal void @"?doInternalExported@@YAXXZ"() #3 {
+entry:
+  ret void
+}
+
+; Alwaysinline, internal, and exported; this should stay.
+; CHECK: define {{.*}}doAlwaysInlineInternalExported
+define internal void @"?doAlwaysInlineInternalExported@@YAXXZ"() #1 {
+entry:
+  ret void
+}
+
+; Noinline, internal, and exported; this should stay.
+; CHECK: define {{.*}}doNoinlineInternalExported
+define internal void @"?doNoinlineInternalExported@@YAXXZ"() #5 {
+entry:
+  ret void
+}
+
+; Marked external and exported, this should stay.
+; CHECK: define {{.*}}doExternalExported
+define external void @"?doExternalExported@@YAXXZ"() #3 {
+entry:
+  ret void
+}
+
+; Alwaysinline, external and exported, this should stay.
+; CHECK: define {{.*}}doAlwaysInlineExternalExported
+define external void @"?doAlwaysInlineExternalExported@@YAXXZ"() #1 {
+entry:
+  ret void
+}
+
+; Noinline, external and exported, this should stay.
+; CHECK: define {{.*}}doNoinlineExternalExported
+define external void @"?doNoinlineExternalExported@@YAXXZ"() #5 {
+entry:
+  ret void
+}
+
+; Entry point function, this should stay.
+; CHECK: define void @main()
+define void @main() #6 {
+entry:
+  call void @"?doNothingCalled@@YAXXZ"() #7
+  call void @"?doAlwaysInlineCalled@@YAXXZ"() #7
+  call void @"?doNoinlineCalled@@YAXXZ"() #7
+  call void @"?doInternalCalled@@YAXXZ"() #7
+  call void @"?doAlwaysInlineInternalCalled@@YAXXZ"() #7
+  call void @"?doNoinlineInternalCalled@@YAXXZ"() #7
+  call void @"?doExternalCalled@@YAXXZ"() #7
+  call void @"?doAlwaysInlineExternalCalled@@YAXXZ"() #7
+  call void @"?doNoinlineExternalCalled@@YAXXZ"() #7
+  ret void
+}
+
+attributes #0 = { alwaysinline convergent norecurse nounwind }
+attributes #1 = { alwaysinline convergent norecurse nounwind "hlsl.export"}
+attributes #2 = { convergent norecurse nounwind }
+attributes #3 = { convergent norecurse nounwind "hlsl.export"}
+attributes #4 = { convergent noinline norecurse nounwind }
+attributes #5 = { convergent noinline norecurse nounwind "hlsl.export"}
+attributes #6 = { convergent noinline norecurse "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
+attributes #7 = { convergent }

diff  --git a/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll
new file mode 100644
index 00000000000000..49c3bda621d74e
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll
@@ -0,0 +1,156 @@
+; RUN: opt -S -dxil-finalize-linkage -mtriple=dxil-unknown-shadermodel6.5-compute %s | FileCheck %s
+; RUN: llc %s --filetype=asm -o - | FileCheck %s
+
+target triple = "dxilv1.5-pc-shadermodel6.5-compute"
+
+; Confirm that DXILFinalizeLinkage will remove functions that have compatible
+; linkage and are not called from anywhere. This should be any function that
+; is not an entry point.
+
+; Has no specified inlining/linking behavior and is uncalled, this should be removed.
+; CHECK-NOT: define {{.*}}doNothingUncalled
+define void @"?doNothingUncalled@@YAXXZ"() #1 {
+entry:
+  ret void
+}
+
+; Alwaysinline and uncalled, this should be removed.
+; CHECK-NOT: define {{.*}}doAlwaysInlineUncalled
+define void @"?doAlwaysInlineUncalled@@YAXXZ"() #0 {
+entry:
+  ret void
+}
+
+; Noinline and uncalled, this should be removed.
+; CHECK-NOT: define {{.*}}doNoinlineUncalled
+define void @"?doNoinlineUncalled@@YAXXZ"() #3 {
+entry:
+  ret void
+}
+
+; No inlining attribute, internal, and uncalled; this should be removed.
+; CHECK-NOT: define {{.*}}doInternalUncalled
+define internal void @"?doInternalUncalled@@YAXXZ"() #1 {
+entry:
+  ret void
+}
+
+; Alwaysinline, internal, and uncalled; this should be removed.
+; CHECK-NOT: define {{.*}}doAlwaysInlineInternalUncalled
+define internal void @"?doAlwaysInlineInternalUncalled@@YAXXZ"() #0 {
+entry:
+  ret void
+}
+
+; Noinline, internal, and uncalled; this should be removed.
+; CHECK-NOT: define {{.*}}doNoinlineInternalUncalled
+define internal void @"?doNoinlineInternalUncalled@@YAXXZ"() #3 {
+entry:
+  ret void
+}
+
+; Marked external and uncalled, this should become internal and be removed.
+; CHECK-NOT: define {{.*}}doExternalUncalled
+define external void @"?doExternalUncalled@@YAXXZ"() #1 {
+entry:
+  ret void
+}
+
+; Alwaysinline, external and uncalled, this should become internal and be removed.
+; CHECK-NOT: define {{.*}}doAlwaysInlineExternalUncalled
+define external void @"?doAlwaysInlineExternalUncalled@@YAXXZ"() #0 {
+entry:
+  ret void
+}
+
+; Noinline, external and uncalled, this should become internal and be removed.
+; CHECK-NOT: define {{.*}}doNoinlineExternalUncalled
+define external void @"?doNoinlineExternalUncalled@@YAXXZ"() #3 {
+entry:
+  ret void
+}
+
+; No inlining attribute and called, this should stay.
+; CHECK: define {{.*}}doNothingCalled
+define void @"?doNothingCalled@@YAXXZ"() #1 {
+entry:
+  ret void
+}
+
+; Alwaysinline and called, this should stay.
+; CHECK: define {{.*}}doAlwaysInlineCalled
+define void @"?doAlwaysInlineCalled@@YAXXZ"() #0 {
+entry:
+  ret void
+}
+
+; Noinline and called, this should stay.
+; CHECK: define {{.*}}doNoinlineCalled
+define void @"?doNoinlineCalled@@YAXXZ"() #3 {
+entry:
+  ret void
+}
+
+; No inlining attribute, internal, and called; this should stay.
+; CHECK: define {{.*}}doInternalCalled
+define internal void @"?doInternalCalled@@YAXXZ"() #1 {
+entry:
+  ret void
+}
+
+; Alwaysinline, internal, and called; this should stay.
+; CHECK: define {{.*}}doAlwaysInlineInternalCalled
+define internal void @"?doAlwaysInlineInternalCalled@@YAXXZ"() #0 {
+entry:
+  ret void
+}
+
+; Noinline, internal, and called; this should stay.
+; CHECK: define {{.*}}doNoinlineInternalCalled
+define internal void @"?doNoinlineInternalCalled@@YAXXZ"() #3 {
+entry:
+  ret void
+}
+
+; Marked external and called, this should become internal and stay.
+; CHECK: define {{.*}}doExternalCalled
+define external void @"?doExternalCalled@@YAXXZ"() #1 {
+entry:
+  ret void
+}
+
+; Always inlined, external and called, this should become internal and stay.
+; CHECK: define {{.*}}doAlwaysInlineExternalCalled
+define external void @"?doAlwaysInlineExternalCalled@@YAXXZ"() #0 {
+entry:
+  ret void
+}
+
+; Noinline, external and called, this should become internal and stay.
+; CHECK: define {{.*}}doNoinlineExternalCalled
+define external void @"?doNoinlineExternalCalled@@YAXXZ"() #3 {
+entry:
+  ret void
+}
+
+; Entry point function, this should stay.
+; CHECK: define void @main()
+define void @main() #4 {
+entry:
+  call void @"?doNothingCalled@@YAXXZ"() #5
+  call void @"?doAlwaysInlineCalled@@YAXXZ"() #5
+  call void @"?doNoinlineCalled@@YAXXZ"() #5
+  call void @"?doInternalCalled@@YAXXZ"() #5
+  call void @"?doAlwaysInlineInternalCalled@@YAXXZ"() #5
+  call void @"?doNoinlineInternalCalled@@YAXXZ"() #5
+  call void @"?doExternalCalled@@YAXXZ"() #5
+  call void @"?doAlwaysInlineExternalCalled@@YAXXZ"() #5
+  call void @"?doNoinlineExternalCalled@@YAXXZ"() #5
+  ret void
+}
+
+attributes #0 = { alwaysinline convergent norecurse nounwind }
+attributes #1 = { convergent norecurse nounwind }
+attributes #3 = { convergent noinline norecurse nounwind }
+attributes #4 = { convergent noinline norecurse "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
+attributes #5 = { convergent }

diff  --git a/llvm/test/CodeGen/DirectX/finalize_linkage.ll b/llvm/test/CodeGen/DirectX/finalize_linkage.ll
index b6da9f6cb3926a..c761a79a5c28a5 100644
--- a/llvm/test/CodeGen/DirectX/finalize_linkage.ll
+++ b/llvm/test/CodeGen/DirectX/finalize_linkage.ll
@@ -6,7 +6,7 @@ target triple = "dxilv1.5-pc-shadermodel6.5-compute"
 ; DXILFinalizeLinkage changes linkage of all functions that are not
 ; entry points or exported function to internal.
 
-; CHECK: define internal void @"?f1@@YAXXZ"()
+; CHECK-NOT: define internal void @"?f1@@YAXXZ"()
 define void @"?f1@@YAXXZ"() #0 {
 entry:
   ret void

diff  --git a/llvm/test/CodeGen/DirectX/fneg-conversion.ll b/llvm/test/CodeGen/DirectX/fneg-conversion.ll
index a397c18398c5f7..3acf4790de4b10 100644
--- a/llvm/test/CodeGen/DirectX/fneg-conversion.ll
+++ b/llvm/test/CodeGen/DirectX/fneg-conversion.ll
@@ -1,14 +1,16 @@
 ; RUN: llc %s --filetype=asm -o - | FileCheck %s
 target triple = "dxil-unknown-shadermodel6.7-library"
 
-define float @negateF(float %0) {
+define float @negateF(float %0) #0 {
 ; CHECK:  %2 = fsub float -0.000000e+00, %0
   %2 = fneg float %0
   ret float %2
 }
 
-define double @negateD(double %0) {
+define double @negateD(double %0) #0 {
 ; CHECK: %2 = fsub double -0.000000e+00, %0
   %2 = fneg double %0
   ret double %2
 }
+
+attributes #0 = { convergent norecurse nounwind "hlsl.export"}
\ No newline at end of file

diff  --git a/llvm/test/CodeGen/DirectX/omit-bitcast-insert.ll b/llvm/test/CodeGen/DirectX/omit-bitcast-insert.ll
index 6066a0033e45de..734ff1b4dd2d57 100644
--- a/llvm/test/CodeGen/DirectX/omit-bitcast-insert.ll
+++ b/llvm/test/CodeGen/DirectX/omit-bitcast-insert.ll
@@ -1,32 +1,34 @@
 ; RUN: llc --filetype=asm %s -o - | FileCheck %s
 target triple = "dxil-unknown-shadermodel6.7-library"
 
-define i64 @test(ptr %p) {
+define i64 @test(ptr %p) #0 {
   %v = load i64, ptr %p
   ret i64 %v
 }
 
-; CHECK: define internal i64 @test(ptr %p) {
+; CHECK: define i64 @test(ptr %p) #0 {
 ; CHECK-NEXT: %v = load i64, ptr %p, align 8
 ; CHECK-NEXT: ret i64 %v
 
-define i64 @test2(ptr %p) {
+define i64 @test2(ptr %p) #0 {
   store i64 0, ptr %p
   %v = load i64, ptr %p
   ret i64 %v
 }
 
-; CHECK: define internal i64 @test2(ptr %p) {
+; CHECK: define i64 @test2(ptr %p) #0 {
 ; CHECK-NEXT: store i64 0, ptr %p
 ; CHECK-NEXT: %v = load i64, ptr %p, align 8
 ; CHECK-NEXT: ret i64 %v
 
-define i32 @test3(ptr %0)  {
+define i32 @test3(ptr %0) #0 {
   %2 = getelementptr i32, ptr %0, i32 4
   %3 = load i32, ptr %2
   ret i32 %3
 }
 
-; CHECK: define internal i32 @test3(ptr %0)  {
+attributes #0 = { convergent norecurse nounwind "hlsl.export"}
+
+; CHECK: define i32 @test3(ptr %0) #0 {
 ; CHECK-NEXT: %2 = getelementptr i32, ptr %0, i32 4
 ; CHECK-NEXT: %3 = load i32, ptr %2

diff  --git a/llvm/test/CodeGen/DirectX/scalar-load.ll b/llvm/test/CodeGen/DirectX/scalar-load.ll
index 612e5646f5a081..b911a8f7855bb8 100644
--- a/llvm/test/CodeGen/DirectX/scalar-load.ll
+++ b/llvm/test/CodeGen/DirectX/scalar-load.ll
@@ -20,7 +20,7 @@
 
 
 ; CHECK-LABEL: load_array_vec_test
-define <4 x i32> @load_array_vec_test() {
+define <4 x i32> @load_array_vec_test() #0 {
   ; CHECK-COUNT-8: load i32, ptr addrspace(3) {{(.*@arrayofVecData.scalarized.*|%.*)}}, align 4
   ; CHECK-NOT: load i32, ptr addrspace(3) {{.*}}, align 4
   %1 = load <4 x i32>, <4 x i32> addrspace(3)* getelementptr inbounds ([2 x <4 x i32>], [2 x <4 x i32>] addrspace(3)* @"arrayofVecData", i32 0, i32 0), align 4
@@ -30,7 +30,7 @@ define <4 x i32> @load_array_vec_test() {
 }
 
 ; CHECK-LABEL: load_vec_test
-define <4 x i32> @load_vec_test() {
+define <4 x i32> @load_vec_test() #0 {
   ; CHECK-COUNT-4: load i32, ptr addrspace(3) {{(@vecData.scalarized|getelementptr \(i32, ptr addrspace\(3\) @vecData.scalarized, i32 .*\)|%.*)}}, align {{.*}}
   ; CHECK-NOT: load i32, ptr addrspace(3) {{.*}}, align 4 
   %1 = load <4 x i32>, <4 x i32> addrspace(3)* @"vecData", align 4
@@ -38,7 +38,7 @@ define <4 x i32> @load_vec_test() {
 }
 
 ; CHECK-LABEL: load_static_array_of_vec_test
-define <4 x i32> @load_static_array_of_vec_test(i32 %index) {
+define <4 x i32> @load_static_array_of_vec_test(i32 %index) #0 {
   ; CHECK: getelementptr [3 x [4 x i32]], ptr @staticArrayOfVecData.scalarized, i32 0, i32 %index
   ; CHECK-COUNT-4: load i32, ptr {{.*}}, align 4
   ; CHECK-NOT: load i32, ptr {{.*}}, align 4
@@ -48,7 +48,7 @@ define <4 x i32> @load_static_array_of_vec_test(i32 %index) {
 }
 
 ; CHECK-LABEL: multid_load_test
-define <4 x i32> @multid_load_test()  {
+define <4 x i32> @multid_load_test() #0 {
   ; CHECK-COUNT-8: load i32, ptr addrspace(3) {{(.*@groushared2dArrayofVectors.scalarized.*|%.*)}}, align 4
   ; CHECK-NOT: load i32, ptr addrspace(3) {{.*}}, align 4
   %1 = load <4 x i32>, <4 x i32> addrspace(3)* getelementptr inbounds ([3 x [3 x <4 x i32>]], [3 x [3 x <4 x i32>]] addrspace(3)* @"groushared2dArrayofVectors", i32 0, i32 0, i32 0), align 4
@@ -56,3 +56,5 @@ define <4 x i32> @multid_load_test()  {
   %3 = add <4 x i32> %1, %2
   ret <4 x i32> %3
 }
+
+attributes #0 = { convergent norecurse nounwind "hlsl.export"}

diff  --git a/llvm/test/CodeGen/DirectX/scalar-store.ll b/llvm/test/CodeGen/DirectX/scalar-store.ll
index 7734d32bca58cd..c45481e8cae14f 100644
--- a/llvm/test/CodeGen/DirectX/scalar-store.ll
+++ b/llvm/test/CodeGen/DirectX/scalar-store.ll
@@ -12,7 +12,7 @@
 ; CHECK-NOT: @vecData
 
 ; CHECK-LABEL: store_array_vec_test
-define void @store_array_vec_test () local_unnamed_addr {
+define void @store_array_vec_test () local_unnamed_addr #0 {
     ; CHECK-COUNT-6: store float {{1|2|3|4|6}}.000000e+00, ptr addrspace(3) {{(.*@arrayofVecData.scalarized.*|%.*)}}, align {{4|8|16}}
     ; CHECK-NOT: store float {{1|2|3|4|6}}.000000e+00, ptr addrspace(3) {{(.*@arrayofVecData.scalarized.*|%.*)}}, align {{4|8|16}}
     store <3 x float> <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00>, ptr addrspace(3) @"arrayofVecData", align 16 
@@ -21,9 +21,11 @@ define void @store_array_vec_test () local_unnamed_addr {
  } 
 
 ; CHECK-LABEL: store_vec_test
-define void @store_vec_test(<4 x i32> %inputVec) {
+define void @store_vec_test(<4 x i32> %inputVec) #0 {
   ; CHECK-COUNT-4: store i32 %inputVec.{{.*}}, ptr addrspace(3) {{(@vecData.scalarized|getelementptr \(i32, ptr addrspace\(3\) @vecData.scalarized, i32 .*\)|%.*)}}, align 4 
   ; CHECK-NOT: store i32 %inputVec.{{.*}}, ptr addrspace(3)
   store <4 x i32> %inputVec, <4 x i32> addrspace(3)* @"vecData", align 4
   ret void
 }
+
+attributes #0 = { convergent norecurse nounwind "hlsl.export"}

diff  --git a/llvm/test/CodeGen/DirectX/scalarize-two-calls.ll b/llvm/test/CodeGen/DirectX/scalarize-two-calls.ll
index a14c1de5cc4205..0546a5505416f1 100644
--- a/llvm/test/CodeGen/DirectX/scalarize-two-calls.ll
+++ b/llvm/test/CodeGen/DirectX/scalarize-two-calls.ll
@@ -2,7 +2,7 @@
 
 ; CHECK: target triple = "dxilv1.3-pc-shadermodel6.3-library"
 ; CHECK-LABEL: cos_sin_float_test
-define noundef <4 x float> @cos_sin_float_test(<4 x float> noundef %a) {
+define noundef <4 x float> @cos_sin_float_test(<4 x float> noundef %a) #0 {
     ; CHECK: [[ee0:%.*]] = extractelement <4 x float> %a, i64 0
     ; CHECK: [[ie0:%.*]] = call float @dx.op.unary.f32(i32 13, float [[ee0]])
     ; CHECK: [[ee1:%.*]] = extractelement <4 x float> %a, i64 1
@@ -23,3 +23,5 @@ define noundef <4 x float> @cos_sin_float_test(<4 x float> noundef %a) {
     %3 = tail call <4 x float> @llvm.cos.v4f32(<4 x float> %2) 
     ret <4 x float> %3 
 } 
+
+attributes #0 = { convergent norecurse nounwind "hlsl.export"}

diff  --git a/llvm/test/CodeGen/DirectX/strip-fn-attrs.ll b/llvm/test/CodeGen/DirectX/strip-fn-attrs.ll
index b0dd89cf90f2b2..4223c909431945 100644
--- a/llvm/test/CodeGen/DirectX/strip-fn-attrs.ll
+++ b/llvm/test/CodeGen/DirectX/strip-fn-attrs.ll
@@ -12,4 +12,4 @@ define dso_local float @fma(float %0, float %1, float %2) local_unnamed_addr #0
 ; CHECK: attributes #0 = { nounwind memory(none) }
 ; CHECK-NOT: attributes #
 
-attributes #0 = { norecurse nounwind readnone willreturn }
+attributes #0 = { norecurse nounwind readnone willreturn "hlsl.export"}


        


More information about the llvm-commits mailing list