Skip to content

[AMDGPU] Avoid resource propagation for recursion through multiple functions #111004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 11, 2024

Conversation

JanekvO
Copy link
Contributor

@JanekvO JanekvO commented Oct 3, 2024

Avoid constructing recursive MCExpr definitions when multiple functions cause a recursion.

Fixes #110863

@llvmbot
Copy link
Member

llvmbot commented Oct 3, 2024

@llvm/pr-subscribers-backend-amdgpu

Author: Janek van Oirschot (JanekvO)

Changes

Avoid constructing recursive MCExpr definitions when multiple functions cause a recursion.

Fixes #110863


Full diff: https://github.com/llvm/llvm-project/pull/111004.diff

9 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp (+6-1)
  • (modified) llvm/test/CodeGen/AMDGPU/agpr-register-count.ll (+1-1)
  • (modified) llvm/test/CodeGen/AMDGPU/amdpal-metadata-agpr-register-count.ll (+1-1)
  • (modified) llvm/test/CodeGen/AMDGPU/function-resource-usage.ll (+73)
  • (modified) llvm/test/CodeGen/AMDGPU/hsa-metadata-agpr-register-count.ll (+1-1)
  • (modified) llvm/test/CodeGen/AMDGPU/ipra.ll (+2-2)
  • (modified) llvm/test/CodeGen/AMDGPU/recursion.ll (+9-9)
  • (added) llvm/test/CodeGen/AMDGPU/recursive-mcexpr.ll (+85)
  • (modified) llvm/test/CodeGen/AMDGPU/sibling-call.ll (+2-2)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
index da0397fa20bd1b..dd970c78e66e91 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
@@ -109,10 +109,13 @@ void MCResourceInfo::assignResourceInfoExpr(
     for (const Function *Callee : Callees) {
       if (!Seen.insert(Callee).second)
         continue;
+      if (!F.doesNotRecurse() && !Callee->doesNotRecurse())
+        continue;
       MCSymbol *CalleeValSym = getSymbol(Callee->getName(), RIK, OutContext);
       ArgExprs.push_back(MCSymbolRefExpr::create(CalleeValSym, OutContext));
     }
-    SymVal = AMDGPUMCExpr::create(Kind, ArgExprs, OutContext);
+    if (ArgExprs.size() > 1)
+      SymVal = AMDGPUMCExpr::create(Kind, ArgExprs, OutContext);
   }
   MCSymbol *Sym = getSymbol(MF.getName(), RIK, OutContext);
   Sym->setVariableValue(SymVal);
@@ -164,6 +167,8 @@ void MCResourceInfo::gatherResourceInfo(
     for (const Function *Callee : FRI.Callees) {
       if (!Seen.insert(Callee).second)
         continue;
+      if (!MF.getFunction().doesNotRecurse() && !Callee->doesNotRecurse())
+        continue;
       if (!Callee->isDeclaration()) {
         MCSymbol *calleeValSym =
             getSymbol(Callee->getName(), RIK_PrivateSegSize, OutContext);
diff --git a/llvm/test/CodeGen/AMDGPU/agpr-register-count.ll b/llvm/test/CodeGen/AMDGPU/agpr-register-count.ll
index 0e16ea10c019ac..189b2d80827896 100644
--- a/llvm/test/CodeGen/AMDGPU/agpr-register-count.ll
+++ b/llvm/test/CodeGen/AMDGPU/agpr-register-count.ll
@@ -178,4 +178,4 @@ bb:
 ; GCN-NEXT: .set amdgpu.max_num_agpr, 32
 ; GCN-NEXT: .set amdgpu.max_num_sgpr, 34
 
-attributes #0 = { nounwind noinline "amdgpu-flat-work-group-size"="1,512" "amdgpu-no-workitem-id-x" "amdgpu-no-workitem-id-y" "amdgpu-no-workitem-id-z" }
+attributes #0 = { nounwind noinline norecurse "amdgpu-flat-work-group-size"="1,512" "amdgpu-no-workitem-id-x" "amdgpu-no-workitem-id-y" "amdgpu-no-workitem-id-z" }
diff --git a/llvm/test/CodeGen/AMDGPU/amdpal-metadata-agpr-register-count.ll b/llvm/test/CodeGen/AMDGPU/amdpal-metadata-agpr-register-count.ll
index 8f4cb364751d88..a01bfc6c8730da 100644
--- a/llvm/test/CodeGen/AMDGPU/amdpal-metadata-agpr-register-count.ll
+++ b/llvm/test/CodeGen/AMDGPU/amdpal-metadata-agpr-register-count.ll
@@ -77,4 +77,4 @@ bb:
 ; GFX908: agpr_count:  0x20
 ; GFX908: vgpr_count:  0x20
 
-attributes #0 = { nounwind noinline "amdgpu-flat-work-group-size"="1,512" }
+attributes #0 = { nounwind noinline norecurse "amdgpu-flat-work-group-size"="1,512" }
diff --git a/llvm/test/CodeGen/AMDGPU/function-resource-usage.ll b/llvm/test/CodeGen/AMDGPU/function-resource-usage.ll
index d3a6b4e01ebfb8..3c57689781378f 100644
--- a/llvm/test/CodeGen/AMDGPU/function-resource-usage.ll
+++ b/llvm/test/CodeGen/AMDGPU/function-resource-usage.ll
@@ -481,6 +481,79 @@ define amdgpu_kernel void @usage_direct_recursion(i32 %n) #0 {
   ret void
 }
 
+; GCN-LABEL: {{^}}multi_stage_recurse2:
+; GCN: .set multi_stage_recurse2.num_vgpr, 41
+; GCN: .set multi_stage_recurse2.num_agpr, 0
+; GCN: .set multi_stage_recurse2.numbered_sgpr, 34
+; GCN: .set multi_stage_recurse2.private_seg_size, 16
+; GCN: .set multi_stage_recurse2.uses_vcc, 1
+; GCN: .set multi_stage_recurse2.uses_flat_scratch, 0
+; GCN: .set multi_stage_recurse2.has_dyn_sized_stack, 0
+; GCN: .set multi_stage_recurse2.has_recursion, 1
+; GCN: .set multi_stage_recurse2.has_indirect_call, 0
+; GCN: TotalNumSgprs: 38
+; GCN: NumVgprs: 41
+; GCN: ScratchSize: 16
+; GCN-LABEL: {{^}}multi_stage_recurse1:
+; GCN: .set multi_stage_recurse1.num_vgpr, 41
+; GCN: .set multi_stage_recurse1.num_agpr, 0
+; GCN: .set multi_stage_recurse1.numbered_sgpr, 34
+; GCN: .set multi_stage_recurse1.private_seg_size, 16
+; GCN: .set multi_stage_recurse1.uses_vcc, 1
+; GCN: .set multi_stage_recurse1.uses_flat_scratch, 0
+; GCN: .set multi_stage_recurse1.has_dyn_sized_stack, 0
+; GCN: .set multi_stage_recurse1.has_recursion, 1
+; GCN: .set multi_stage_recurse1.has_indirect_call, 0
+; GCN: TotalNumSgprs: 38
+; GCN: NumVgprs: 41
+; GCN: ScratchSize: 16
+define void @multi_stage_recurse1(i32 %val) #2 {
+  call void @multi_stage_recurse2(i32 %val)
+  ret void
+}
+define void @multi_stage_recurse2(i32 %val) #2 {
+  call void @multi_stage_recurse1(i32 %val)
+  ret void
+}
+
+; GCN-LABEL: {{^}}usage_multi_stage_recurse:
+; GCN: .set usage_multi_stage_recurse.num_vgpr, max(32, multi_stage_recurse1.num_vgpr)
+; GCN: .set usage_multi_stage_recurse.num_agpr, max(0, multi_stage_recurse1.num_agpr)
+; GCN: .set usage_multi_stage_recurse.numbered_sgpr, max(33, multi_stage_recurse1.numbered_sgpr)
+; GCN: .set usage_multi_stage_recurse.private_seg_size, 0+(max(multi_stage_recurse1.private_seg_size))
+; GCN: .set usage_multi_stage_recurse.uses_vcc, or(1, multi_stage_recurse1.uses_vcc)
+; GCN: .set usage_multi_stage_recurse.uses_flat_scratch, or(1, multi_stage_recurse1.uses_flat_scratch)
+; GCN: .set usage_multi_stage_recurse.has_dyn_sized_stack, or(0, multi_stage_recurse1.has_dyn_sized_stack)
+; GCN: .set usage_multi_stage_recurse.has_recursion, or(1, multi_stage_recurse1.has_recursion)
+; GCN: .set usage_multi_stage_recurse.has_indirect_call, or(0, multi_stage_recurse1.has_indirect_call)
+; GCN: TotalNumSgprs: 40
+; GCN: NumVgprs: 41
+; GCN: ScratchSize: 16
+define amdgpu_kernel void @usage_multi_stage_recurse(i32 %n) #0 {
+  call void @multi_stage_recurse1(i32 %n)
+  ret void
+}
+
+; GCN-LABEL: {{^}}multi_call_with_multi_stage_recurse:
+; GCN:  .set multi_call_with_multi_stage_recurse.num_vgpr, max(41, use_stack0.num_vgpr, use_stack1.num_vgpr, multi_stage_recurse1.num_vgpr)
+; GCN:  .set multi_call_with_multi_stage_recurse.num_agpr, max(0, use_stack0.num_agpr, use_stack1.num_agpr, multi_stage_recurse1.num_agpr)
+; GCN:  .set multi_call_with_multi_stage_recurse.numbered_sgpr, max(43, use_stack0.numbered_sgpr, use_stack1.numbered_sgpr, multi_stage_recurse1.numbered_sgpr)
+; GCN:  .set multi_call_with_multi_stage_recurse.private_seg_size, 0+(max(use_stack0.private_seg_size, use_stack1.private_seg_size, multi_stage_recurse1.private_seg_size))
+; GCN:  .set multi_call_with_multi_stage_recurse.uses_vcc, or(1, use_stack0.uses_vcc, use_stack1.uses_vcc, multi_stage_recurse1.uses_vcc)
+; GCN:  .set multi_call_with_multi_stage_recurse.uses_flat_scratch, or(1, use_stack0.uses_flat_scratch, use_stack1.uses_flat_scratch, multi_stage_recurse1.uses_flat_scratch)
+; GCN:  .set multi_call_with_multi_stage_recurse.has_dyn_sized_stack, or(0, use_stack0.has_dyn_sized_stack, use_stack1.has_dyn_sized_stack, multi_stage_recurse1.has_dyn_sized_stack)
+; GCN:  .set multi_call_with_multi_stage_recurse.has_recursion, or(1, use_stack0.has_recursion, use_stack1.has_recursion, multi_stage_recurse1.has_recursion)
+; GCN:  .set multi_call_with_multi_stage_recurse.has_indirect_call, or(0, use_stack0.has_indirect_call, use_stack1.has_indirect_call, multi_stage_recurse1.has_indirect_call)
+; GCN: TotalNumSgprs: 49
+; GCN: NumVgprs: 41
+; GCN: ScratchSize: 2052
+define amdgpu_kernel void @multi_call_with_multi_stage_recurse(i32 %n) #0 {
+  call void @use_stack0()
+  call void @use_stack1()
+  call void @multi_stage_recurse1(i32 %n)
+  ret void
+}
+
 ; Make sure there's no assert when a sgpr96 is used.
 ; GCN-LABEL: {{^}}count_use_sgpr96_external_call
 ; GCN:	.set count_use_sgpr96_external_call.num_vgpr, max(32, amdgpu.max_num_vgpr)
diff --git a/llvm/test/CodeGen/AMDGPU/hsa-metadata-agpr-register-count.ll b/llvm/test/CodeGen/AMDGPU/hsa-metadata-agpr-register-count.ll
index 380a8e911e4995..fdc3f3957b828b 100644
--- a/llvm/test/CodeGen/AMDGPU/hsa-metadata-agpr-register-count.ll
+++ b/llvm/test/CodeGen/AMDGPU/hsa-metadata-agpr-register-count.ll
@@ -98,4 +98,4 @@ bb:
   ret void
 }
 
-attributes #0 = { nounwind noinline "amdgpu-flat-work-group-size"="1,512" "amdgpu-no-workitem-id-x" "amdgpu-no-workitem-id-y" "amdgpu-no-workitem-id-z" }
+attributes #0 = { nounwind noinline norecurse "amdgpu-flat-work-group-size"="1,512" "amdgpu-no-workitem-id-x" "amdgpu-no-workitem-id-y" "amdgpu-no-workitem-id-z" }
diff --git a/llvm/test/CodeGen/AMDGPU/ipra.ll b/llvm/test/CodeGen/AMDGPU/ipra.ll
index 957f404c8cdbed..85d23323ec6dec 100644
--- a/llvm/test/CodeGen/AMDGPU/ipra.ll
+++ b/llvm/test/CodeGen/AMDGPU/ipra.ll
@@ -131,6 +131,6 @@ bb:
 declare dso_local void @eggs()
 
 
-attributes #0 = { nounwind }
-attributes #1 = { nounwind noinline "amdgpu-no-workitem-id-x" "amdgpu-no-workitem-id-y" "amdgpu-no-workitem-id-z" }
+attributes #0 = { nounwind norecurse }
+attributes #1 = { nounwind noinline norecurse "amdgpu-no-workitem-id-x" "amdgpu-no-workitem-id-y" "amdgpu-no-workitem-id-z" }
 attributes #2 = { norecurse }
diff --git a/llvm/test/CodeGen/AMDGPU/recursion.ll b/llvm/test/CodeGen/AMDGPU/recursion.ll
index c0d228e1254e64..479f46faf79d3e 100644
--- a/llvm/test/CodeGen/AMDGPU/recursion.ll
+++ b/llvm/test/CodeGen/AMDGPU/recursion.ll
@@ -41,11 +41,11 @@ define void @tail_recursive_with_stack() {
 ; For an arbitrary recursive call, report a large number for unknown stack
 ; usage for code object v4 and older
 ; CHECK-LABEL: {{^}}calls_recursive:
-; CHECK: .set calls_recursive.private_seg_size, 0+(max(16384, recursive.private_seg_size))
+; CHECK: .set calls_recursive.private_seg_size, 0+(max(16384))
 ;
 ; V5-LABEL: {{^}}calls_recursive:
-; V5: .set calls_recursive.private_seg_size, 0+(max(recursive.private_seg_size))
-; V5: .set calls_recursive.has_dyn_sized_stack, or(0, recursive.has_dyn_sized_stack)
+; V5: .set calls_recursive.private_seg_size, 0
+; V5: .set calls_recursive.has_dyn_sized_stack, 0
 define amdgpu_kernel void @calls_recursive() {
   call void @recursive()
   ret void
@@ -65,22 +65,22 @@ define amdgpu_kernel void @kernel_indirectly_calls_tail_recursive() {
 ; in the kernel.
 
 ; CHECK-LABEL: {{^}}kernel_calls_tail_recursive:
-; CHECK: .set kernel_calls_tail_recursive.private_seg_size, 0+(max(16384, tail_recursive.private_seg_size))
+; CHECK: .set kernel_calls_tail_recursive.private_seg_size, 0+(max(16384))
 ;
 ; V5-LABEL: {{^}}kernel_calls_tail_recursive:
-; V5: .set kernel_calls_tail_recursive.private_seg_size, 0+(max(tail_recursive.private_seg_size))
-; V5: .set kernel_calls_tail_recursive.has_recursion, or(1, tail_recursive.has_recursion)
+; V5: .set kernel_calls_tail_recursive.private_seg_size, 0
+; V5: .set kernel_calls_tail_recursive.has_recursion, 1
 define amdgpu_kernel void @kernel_calls_tail_recursive() {
   call void @tail_recursive()
   ret void
 }
 
 ; CHECK-LABEL: {{^}}kernel_calls_tail_recursive_with_stack:
-; CHECK: .set kernel_calls_tail_recursive_with_stack.private_seg_size, 0+(max(16384, tail_recursive_with_stack.private_seg_size))
+; CHECK: .set kernel_calls_tail_recursive_with_stack.private_seg_size, 0+(max(16384))
 ;
 ; V5-LABEL: {{^}}kernel_calls_tail_recursive_with_stack:
-; V5: .set kernel_calls_tail_recursive_with_stack.private_seg_size, 0+(max(tail_recursive_with_stack.private_seg_size))
-; V5: .set kernel_calls_tail_recursive_with_stack.has_dyn_sized_stack, or(0, tail_recursive_with_stack.has_dyn_sized_stack)
+; V5: .set kernel_calls_tail_recursive_with_stack.private_seg_size, 0
+; V5: .set kernel_calls_tail_recursive_with_stack.has_dyn_sized_stack, 0
 define amdgpu_kernel void @kernel_calls_tail_recursive_with_stack() {
   call void @tail_recursive_with_stack()
   ret void
diff --git a/llvm/test/CodeGen/AMDGPU/recursive-mcexpr.ll b/llvm/test/CodeGen/AMDGPU/recursive-mcexpr.ll
new file mode 100644
index 00000000000000..630a0923e31287
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/recursive-mcexpr.ll
@@ -0,0 +1,85 @@
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -verify-machineinstrs -mcpu=gfx90a < %s | FileCheck %s
+
+; CHECK-LABEL: {{^}}qux
+; CHECK: .set qux.num_vgpr, 41
+; CHECK: .set qux.num_agpr, 0
+; CHECK: .set qux.numbered_sgpr, 34
+; CHECK: .set qux.private_seg_size, 16
+; CHECK: .set qux.uses_vcc, 1
+; CHECK: .set qux.uses_flat_scratch, 0
+; CHECK: .set qux.has_dyn_sized_stack, 0
+; CHECK: .set qux.has_recursion, 1
+; CHECK: .set qux.has_indirect_call, 0
+
+; CHECK-LABEL: {{^}}baz
+; CHECK: .set baz.num_vgpr, 42
+; CHECK: .set baz.num_agpr, 0
+; CHECK: .set baz.numbered_sgpr, 34
+; CHECK: .set baz.private_seg_size, 16
+; CHECK: .set baz.uses_vcc, 1
+; CHECK: .set baz.uses_flat_scratch, 0
+; CHECK: .set baz.has_dyn_sized_stack, 0
+; CHECK: .set baz.has_recursion, 1
+; CHECK: .set baz.has_indirect_call, 0
+
+; CHECK-LABEL: {{^}}bar
+; CHECK: .set bar.num_vgpr, 42
+; CHECK: .set bar.num_agpr, 0
+; CHECK: .set bar.numbered_sgpr, 34
+; CHECK: .set bar.private_seg_size, 16
+; CHECK: .set bar.uses_vcc, 1
+; CHECK: .set bar.uses_flat_scratch, 0
+; CHECK: .set bar.has_dyn_sized_stack, 0
+; CHECK: .set bar.has_recursion, 1
+; CHECK: .set bar.has_indirect_call, 0
+
+; CHECK-LABEL: {{^}}foo
+; CHECK: .set foo.num_vgpr, 42
+; CHECK: .set foo.num_agpr, 0
+; CHECK: .set foo.numbered_sgpr, 34
+; CHECK: .set foo.private_seg_size, 16
+; CHECK: .set foo.uses_vcc, 1
+; CHECK: .set foo.uses_flat_scratch, 0
+; CHECK: .set foo.has_dyn_sized_stack, 0
+; CHECK: .set foo.has_recursion, 1
+; CHECK: .set foo.has_indirect_call, 0
+
+define void @foo() {
+entry:
+  call void @bar()
+  ret void
+}
+
+define void @bar() {
+entry:
+  call void @baz()
+  ret void
+}
+
+define void @baz() {
+entry:
+  call void @qux()
+  ret void
+}
+
+define void @qux() {
+entry:
+  call void @foo()
+  ret void
+}
+
+; CHECK-LABEL: {{^}}usefoo
+; CHECK: .set usefoo.num_vgpr, 32
+; CHECK: .set usefoo.num_agpr, 0
+; CHECK: .set usefoo.numbered_sgpr, 33
+; CHECK: .set usefoo.private_seg_size, 0
+; CHECK: .set usefoo.uses_vcc, 1
+; CHECK: .set usefoo.uses_flat_scratch, 1
+; CHECK: .set usefoo.has_dyn_sized_stack, 0
+; CHECK: .set usefoo.has_recursion, 1
+; CHECK: .set usefoo.has_indirect_call, 0
+define amdgpu_kernel void @usefoo() {
+  call void @foo()
+  ret void
+}
+
diff --git a/llvm/test/CodeGen/AMDGPU/sibling-call.ll b/llvm/test/CodeGen/AMDGPU/sibling-call.ll
index 5536a09538e6ee..4639bf4a678d49 100644
--- a/llvm/test/CodeGen/AMDGPU/sibling-call.ll
+++ b/llvm/test/CodeGen/AMDGPU/sibling-call.ll
@@ -468,5 +468,5 @@ entry:
   ret <2 x i64> %ret
 }
 
-attributes #0 = { nounwind }
-attributes #1 = { nounwind noinline "amdgpu-no-dispatch-id" "amdgpu-no-dispatch-ptr" "amdgpu-no-heap-ptr" "amdgpu-no-hostcall-ptr" "amdgpu-no-implicitarg-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-y" "amdgpu-no-workitem-id-z" }
+attributes #0 = { nounwind norecurse }
+attributes #1 = { nounwind noinline norecurse "amdgpu-no-dispatch-id" "amdgpu-no-dispatch-ptr" "amdgpu-no-heap-ptr" "amdgpu-no-hostcall-ptr" "amdgpu-no-implicitarg-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-y" "amdgpu-no-workitem-id-z" }

@agozillon agozillon requested a review from jhuber6 October 3, 2024 16:37
@JanekvO
Copy link
Contributor Author

JanekvO commented Oct 4, 2024

Took a different approach since the dependence on the norecurse attribute wasn't sitting too well with me (extra burden on new tests, still possibility of crashing on norecurse with recursing functions). Do let me know if I'm missing some low hanging fruit in terms of avoiding recursive def/use with MCSymbols.

Comment on lines 110 to 111
return findSymbolInExpr(Sym, BExpr->getLHS(), Exprs) ||
findSymbolInExpr(Sym, BExpr->getRHS(), Exprs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have the worklist, but aren't using it to avoid the recursive call? Couldn't this also add duplicate entries?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if my interpretation of the comment is wrong but AFAIK, it cannot recurse locally within findSymbolInExpr as Exprs is only populated with Symbols that are assigned an MCExpr (which is what we're in the middle of doing for MCSymbol Sym).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually if you have to deal with recursive expressions, you track a visited set while walking through the expression, and give up when you encounter already visited entries. You're looking at all the visited expressions each time you visit an expression.

As an example, here's a similar situation for ConstantExprs:

uint8_t getConstantAccess(const Constant *C,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the getConstantAccess example walks over an already completed expression. My approach here is more preventative in terms of recursion so no recursion should exist, at all. I've added a Visited set but more so to ensure the invariant of no recursion to be upheld + added more comments that hopefully explain that this walk is to avoid recursion rather than detect and remove recursion.

Comment on lines 167 to 170
if (!foundRecursiveSymbolDef(
Sym, CalleeValSym->getVariableValue(/*isUsed=*/false))) {
ArgExprs.push_back(MCSymbolRefExpr::create(CalleeValSym, OutContext));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you track a visited set instead of explicitly checking for recursion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may not understand what's suggested with a visited set but I've attempted a visit set using the Seen set above but that can't consider the case where there's multi function recursion since only single-level callees are being covered by Seen. If using a visit set with walking over the expression, it may return true with cases where a caller isn't on the recursive path where I'd like to find cases where the currently assigned Function's symbol is somewhere in the uses of its callees.

Comment on lines 94 to 95
// The (partially complete) expression should have no recursion in it. After
// all, we're trying to avoid recursion using this codepath.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document return value

ArgExprs.push_back(MCSymbolRefExpr::create(CalleeValSym, OutContext));
}
} else {
ArgExprs.push_back(MCSymbolRefExpr::create(CalleeValSym, OutContext));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 2 paths to this push_back, so merge the push_back into one condition

ArgExprs.push_back(
MCSymbolRefExpr::create(calleeValSym, OutContext));
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, can turn this into one conditional push_back?

SmallPtrSetImpl<const MCExpr *> &Visited) {
// Assert if any of the expressions is already visited (i.e., there is
// existing recursion).
if (!Visited.insert(Expr).second)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the advantage of this over assert? Is it because llvm_unreachable can be enabled separately?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't require the annoying variable only used in asserts builds problem

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the compiler will optimize out the unused variable if llvm_unreachable is a no-op. Guess it's

if (!Visited.insert(Expr).second)
  llvm_unreachable("already visited expression");

vs

[[maybe_unused]] bool AlreadyVisited = Visited.insert(Expr).second;
assert(!AlreadyVisited && "already visited expression");

Roughly equivalent so I guess it's up to taste.

Copy link

github-actions bot commented Oct 10, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@arsenm
Copy link
Contributor

arsenm commented Oct 11, 2024

Fix clang-format error

@JanekvO JanekvO merged commit 67160c5 into llvm:main Oct 11, 2024
8 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 11, 2024

LLVM Buildbot has detected a new failure on builder clang-hip-vega20 running on hip-vega20-0 while building llvm at step 3 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/123/builds/7371

Here is the relevant piece of the build log for the reference
Step 3 (annotate) failure: '../llvm-zorg/zorg/buildbot/builders/annotated/hip-build.sh --jobs=' (failure)
...
[26/40] : && /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang -O3 -DNDEBUG  tools/CMakeFiles/timeit-target.dir/timeit.c.o -o tools/timeit-target   && :
[27/40] /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang -DNDEBUG  -O3 -DNDEBUG   -w -Werror=date-time -MD -MT tools/CMakeFiles/fpcmp-target.dir/fpcmp.c.o -MF tools/CMakeFiles/fpcmp-target.dir/fpcmp.c.o.d -o tools/CMakeFiles/fpcmp-target.dir/fpcmp.c.o -c /buildbot/llvm-test-suite/tools/fpcmp.c
[28/40] : && /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang -O3 -DNDEBUG  tools/CMakeFiles/fpcmp-target.dir/fpcmp.c.o -o tools/fpcmp-target   && :
[29/40] /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -DNDEBUG  -O3 -DNDEBUG   -w -Werror=date-time --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --offload-arch=gfx908 --offload-arch=gfx90a --offload-arch=gfx1030 --offload-arch=gfx1100 -MD -MT External/HIP/CMakeFiles/empty-hip-6.0.2.dir/empty.hip.o -MF External/HIP/CMakeFiles/empty-hip-6.0.2.dir/empty.hip.o.d -o External/HIP/CMakeFiles/empty-hip-6.0.2.dir/empty.hip.o -c /buildbot/llvm-test-suite/External/HIP/empty.hip
[30/40] : && /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -O3 -DNDEBUG  External/HIP/CMakeFiles/empty-hip-6.0.2.dir/empty.hip.o -o External/HIP/empty-hip-6.0.2  --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --hip-link -rtlib=compiler-rt -unwindlib=libgcc -frtlib-add-rpath && cd /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP && /usr/local/bin/cmake -E create_symlink /buildbot/llvm-test-suite/External/HIP/empty.reference_output /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/empty.reference_output-hip-6.0.2
[31/40] /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -DNDEBUG  -O3 -DNDEBUG   -w -Werror=date-time --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --offload-arch=gfx908 --offload-arch=gfx90a --offload-arch=gfx1030 --offload-arch=gfx1100 -fopenmp -MD -MT External/HIP/CMakeFiles/with-fopenmp-hip-6.0.2.dir/with-fopenmp.hip.o -MF External/HIP/CMakeFiles/with-fopenmp-hip-6.0.2.dir/with-fopenmp.hip.o.d -o External/HIP/CMakeFiles/with-fopenmp-hip-6.0.2.dir/with-fopenmp.hip.o -c /buildbot/llvm-test-suite/External/HIP/with-fopenmp.hip
[32/40] : && /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -O3 -DNDEBUG  External/HIP/CMakeFiles/with-fopenmp-hip-6.0.2.dir/with-fopenmp.hip.o -o External/HIP/with-fopenmp-hip-6.0.2  --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --hip-link -rtlib=compiler-rt -unwindlib=libgcc -frtlib-add-rpath && cd /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP && /usr/local/bin/cmake -E create_symlink /buildbot/llvm-test-suite/External/HIP/with-fopenmp.reference_output /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/with-fopenmp.reference_output-hip-6.0.2
[33/40] /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -DNDEBUG  -O3 -DNDEBUG   -w -Werror=date-time --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --offload-arch=gfx908 --offload-arch=gfx90a --offload-arch=gfx1030 --offload-arch=gfx1100 -MD -MT External/HIP/CMakeFiles/saxpy-hip-6.0.2.dir/saxpy.hip.o -MF External/HIP/CMakeFiles/saxpy-hip-6.0.2.dir/saxpy.hip.o.d -o External/HIP/CMakeFiles/saxpy-hip-6.0.2.dir/saxpy.hip.o -c /buildbot/llvm-test-suite/External/HIP/saxpy.hip
[34/40] : && /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -O3 -DNDEBUG  External/HIP/CMakeFiles/saxpy-hip-6.0.2.dir/saxpy.hip.o -o External/HIP/saxpy-hip-6.0.2  --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --hip-link -rtlib=compiler-rt -unwindlib=libgcc -frtlib-add-rpath && cd /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP && /usr/local/bin/cmake -E create_symlink /buildbot/llvm-test-suite/External/HIP/saxpy.reference_output /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/saxpy.reference_output-hip-6.0.2
[35/40] /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -DNDEBUG  -O3 -DNDEBUG   -w -Werror=date-time --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --offload-arch=gfx908 --offload-arch=gfx90a --offload-arch=gfx1030 --offload-arch=gfx1100 -xhip -mfma -MD -MT External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o -MF External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o.d -o External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o -c /buildbot/llvm-test-suite/External/HIP/workload/ray-tracing/TheNextWeek/main.cc
FAILED: External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o 
/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -DNDEBUG  -O3 -DNDEBUG   -w -Werror=date-time --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --offload-arch=gfx908 --offload-arch=gfx90a --offload-arch=gfx1030 --offload-arch=gfx1100 -xhip -mfma -MD -MT External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o -MF External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o.d -o External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o -c /buildbot/llvm-test-suite/External/HIP/workload/ray-tracing/TheNextWeek/main.cc
already visited expression
UNREACHABLE executed at /buildbot/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp:103!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19 -cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -Werror=atomic-alignment -emit-obj -disable-free -clear-ast-before-backend -main-file-name main.cc -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fno-rounding-math -mconstructor-aliases -aux-target-cpu x86-64 -aux-target-feature +fma -fcuda-is-device -mllvm -amdgpu-internalize-symbols -fcuda-allow-variadic-functions -fvisibility=hidden -fapply-global-visibility-to-externs -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/hip.bc -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/ocml.bc -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/ockl.bc -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/oclc_daz_opt_off.bc -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/oclc_unsafe_math_off.bc -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/oclc_finite_only_off.bc -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/oclc_correctly_rounded_sqrt_on.bc -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/oclc_wavefrontsize64_off.bc -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/oclc_isa_version_1030.bc -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/oclc_abi_version_400.bc -target-cpu gfx1030 -debugger-tuning=gdb -fdebug-compilation-dir=/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build -resource-dir /buildbot/hip-vega20-0/clang-hip-vega20/llvm/lib/clang/20 -dependency-file External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o.d -MT External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o -sys-header-deps -internal-isystem /buildbot/hip-vega20-0/clang-hip-vega20/llvm/lib/clang/20/include/cuda_wrappers -idirafter /buildbot/Externals/hip/rocm-6.0.2/include -include __clang_hip_runtime_wrapper.h -D NDEBUG -D NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/backward -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/backward -internal-isystem /buildbot/hip-vega20-0/clang-hip-vega20/llvm/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -internal-isystem /buildbot/hip-vega20-0/clang-hip-vega20/llvm/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Werror=date-time -w -fdeprecated-macro -fno-autolink -ferror-limit 19 -fhip-new-launch-api -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -cuid=9c43066b7056eb66 -fcuda-allow-variadic-functions -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/main-gfx1030-eba29b.o -x hip /buildbot/llvm-test-suite/External/HIP/workload/ray-tracing/TheNextWeek/main.cc
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'CallGraph Pass Manager' on module '/buildbot/llvm-test-suite/External/HIP/workload/ray-tracing/TheNextWeek/main.cc'.
4.	Running pass 'AMDGPU Assembly Printer' on function '@_ZN4TestI14random_spheresE18devSceneInitKernelEv'
 #0 0x00005621368147e0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x2b117e0)
 #1 0x0000562136811bef llvm::sys::RunSignalHandlers() (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x2b0ebef)
 #2 0x0000562136811d45 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f99e1871520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f99e18c59fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007f99e18c59fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007f99e18c59fc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007f99e1871476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007f99e18577f3 abort ./stdlib/abort.c:81:7
 #9 0x000056213676703e (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x2a6403e)
#10 0x0000562134babecf foundRecursiveSymbolDef(llvm::MCSymbol*, llvm::MCExpr const*) AMDGPUMCResourceInfo.cpp:0:0
#11 0x0000562134bad0a7 llvm::MCResourceInfo::gatherResourceInfo(llvm::MachineFunction const&, llvm::AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo const&, llvm::MCContext&) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0xeaa0a7)
#12 0x0000562134b9d25c llvm::AMDGPUAsmPrinter::runOnMachineFunction(llvm::MachineFunction&) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0xe9a25c)
#13 0x0000562135ae06b7 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#14 0x000056213614cf07 llvm::FPPassManager::runOnFunction(llvm::Function&) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x2449f07)
#15 0x00005621356cfaf2 (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) CallGraphSCCPass.cpp:0:0
#16 0x000056213614dd11 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x244ad11)
#17 0x0000562136aabfb8 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x2da8fb8)
#18 0x0000562137151775 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x344e775)
#19 0x0000562138eaf87c clang::ParseAST(clang::Sema&, bool, bool) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x51ac87c)
#20 0x000056213742fd69 clang::FrontendAction::Execute() (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x372cd69)
#21 0x00005621373a9595 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x36a6595)
#22 0x000056213750e423 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x380b423)
#23 0x0000562134b839d7 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0xe809d7)
#24 0x0000562134b7b02a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#25 0x0000562134b7f2ee clang_main(int, char**, llvm::ToolContext const&) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0xe7c2ee)
#26 0x0000562134aaaa5b main (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0xda7a5b)
#27 0x00007f99e1858d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
Step 11 (Building HIP test-suite) failure: Building HIP test-suite (failure)
...
[26/40] : && /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang -O3 -DNDEBUG  tools/CMakeFiles/timeit-target.dir/timeit.c.o -o tools/timeit-target   && :
[27/40] /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang -DNDEBUG  -O3 -DNDEBUG   -w -Werror=date-time -MD -MT tools/CMakeFiles/fpcmp-target.dir/fpcmp.c.o -MF tools/CMakeFiles/fpcmp-target.dir/fpcmp.c.o.d -o tools/CMakeFiles/fpcmp-target.dir/fpcmp.c.o -c /buildbot/llvm-test-suite/tools/fpcmp.c
[28/40] : && /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang -O3 -DNDEBUG  tools/CMakeFiles/fpcmp-target.dir/fpcmp.c.o -o tools/fpcmp-target   && :
[29/40] /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -DNDEBUG  -O3 -DNDEBUG   -w -Werror=date-time --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --offload-arch=gfx908 --offload-arch=gfx90a --offload-arch=gfx1030 --offload-arch=gfx1100 -MD -MT External/HIP/CMakeFiles/empty-hip-6.0.2.dir/empty.hip.o -MF External/HIP/CMakeFiles/empty-hip-6.0.2.dir/empty.hip.o.d -o External/HIP/CMakeFiles/empty-hip-6.0.2.dir/empty.hip.o -c /buildbot/llvm-test-suite/External/HIP/empty.hip
[30/40] : && /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -O3 -DNDEBUG  External/HIP/CMakeFiles/empty-hip-6.0.2.dir/empty.hip.o -o External/HIP/empty-hip-6.0.2  --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --hip-link -rtlib=compiler-rt -unwindlib=libgcc -frtlib-add-rpath && cd /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP && /usr/local/bin/cmake -E create_symlink /buildbot/llvm-test-suite/External/HIP/empty.reference_output /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/empty.reference_output-hip-6.0.2
[31/40] /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -DNDEBUG  -O3 -DNDEBUG   -w -Werror=date-time --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --offload-arch=gfx908 --offload-arch=gfx90a --offload-arch=gfx1030 --offload-arch=gfx1100 -fopenmp -MD -MT External/HIP/CMakeFiles/with-fopenmp-hip-6.0.2.dir/with-fopenmp.hip.o -MF External/HIP/CMakeFiles/with-fopenmp-hip-6.0.2.dir/with-fopenmp.hip.o.d -o External/HIP/CMakeFiles/with-fopenmp-hip-6.0.2.dir/with-fopenmp.hip.o -c /buildbot/llvm-test-suite/External/HIP/with-fopenmp.hip
[32/40] : && /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -O3 -DNDEBUG  External/HIP/CMakeFiles/with-fopenmp-hip-6.0.2.dir/with-fopenmp.hip.o -o External/HIP/with-fopenmp-hip-6.0.2  --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --hip-link -rtlib=compiler-rt -unwindlib=libgcc -frtlib-add-rpath && cd /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP && /usr/local/bin/cmake -E create_symlink /buildbot/llvm-test-suite/External/HIP/with-fopenmp.reference_output /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/with-fopenmp.reference_output-hip-6.0.2
[33/40] /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -DNDEBUG  -O3 -DNDEBUG   -w -Werror=date-time --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --offload-arch=gfx908 --offload-arch=gfx90a --offload-arch=gfx1030 --offload-arch=gfx1100 -MD -MT External/HIP/CMakeFiles/saxpy-hip-6.0.2.dir/saxpy.hip.o -MF External/HIP/CMakeFiles/saxpy-hip-6.0.2.dir/saxpy.hip.o.d -o External/HIP/CMakeFiles/saxpy-hip-6.0.2.dir/saxpy.hip.o -c /buildbot/llvm-test-suite/External/HIP/saxpy.hip
[34/40] : && /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -O3 -DNDEBUG  External/HIP/CMakeFiles/saxpy-hip-6.0.2.dir/saxpy.hip.o -o External/HIP/saxpy-hip-6.0.2  --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --hip-link -rtlib=compiler-rt -unwindlib=libgcc -frtlib-add-rpath && cd /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP && /usr/local/bin/cmake -E create_symlink /buildbot/llvm-test-suite/External/HIP/saxpy.reference_output /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/saxpy.reference_output-hip-6.0.2
[35/40] /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -DNDEBUG  -O3 -DNDEBUG   -w -Werror=date-time --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --offload-arch=gfx908 --offload-arch=gfx90a --offload-arch=gfx1030 --offload-arch=gfx1100 -xhip -mfma -MD -MT External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o -MF External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o.d -o External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o -c /buildbot/llvm-test-suite/External/HIP/workload/ray-tracing/TheNextWeek/main.cc
FAILED: External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o 
/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -DNDEBUG  -O3 -DNDEBUG   -w -Werror=date-time --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --offload-arch=gfx908 --offload-arch=gfx90a --offload-arch=gfx1030 --offload-arch=gfx1100 -xhip -mfma -MD -MT External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o -MF External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o.d -o External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o -c /buildbot/llvm-test-suite/External/HIP/workload/ray-tracing/TheNextWeek/main.cc
already visited expression
UNREACHABLE executed at /buildbot/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp:103!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19 -cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -Werror=atomic-alignment -emit-obj -disable-free -clear-ast-before-backend -main-file-name main.cc -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fno-rounding-math -mconstructor-aliases -aux-target-cpu x86-64 -aux-target-feature +fma -fcuda-is-device -mllvm -amdgpu-internalize-symbols -fcuda-allow-variadic-functions -fvisibility=hidden -fapply-global-visibility-to-externs -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/hip.bc -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/ocml.bc -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/ockl.bc -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/oclc_daz_opt_off.bc -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/oclc_unsafe_math_off.bc -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/oclc_finite_only_off.bc -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/oclc_correctly_rounded_sqrt_on.bc -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/oclc_wavefrontsize64_off.bc -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/oclc_isa_version_1030.bc -mlink-builtin-bitcode /buildbot/Externals/hip/rocm-6.0.2/amdgcn/bitcode/oclc_abi_version_400.bc -target-cpu gfx1030 -debugger-tuning=gdb -fdebug-compilation-dir=/buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build -resource-dir /buildbot/hip-vega20-0/clang-hip-vega20/llvm/lib/clang/20 -dependency-file External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o.d -MT External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o -sys-header-deps -internal-isystem /buildbot/hip-vega20-0/clang-hip-vega20/llvm/lib/clang/20/include/cuda_wrappers -idirafter /buildbot/Externals/hip/rocm-6.0.2/include -include __clang_hip_runtime_wrapper.h -D NDEBUG -D NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/backward -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/backward -internal-isystem /buildbot/hip-vega20-0/clang-hip-vega20/llvm/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -internal-isystem /buildbot/hip-vega20-0/clang-hip-vega20/llvm/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Werror=date-time -w -fdeprecated-macro -fno-autolink -ferror-limit 19 -fhip-new-launch-api -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -cuid=9c43066b7056eb66 -fcuda-allow-variadic-functions -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/main-gfx1030-eba29b.o -x hip /buildbot/llvm-test-suite/External/HIP/workload/ray-tracing/TheNextWeek/main.cc
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'CallGraph Pass Manager' on module '/buildbot/llvm-test-suite/External/HIP/workload/ray-tracing/TheNextWeek/main.cc'.
4.	Running pass 'AMDGPU Assembly Printer' on function '@_ZN4TestI14random_spheresE18devSceneInitKernelEv'
 #0 0x00005621368147e0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x2b117e0)
 #1 0x0000562136811bef llvm::sys::RunSignalHandlers() (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x2b0ebef)
 #2 0x0000562136811d45 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f99e1871520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f99e18c59fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007f99e18c59fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007f99e18c59fc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007f99e1871476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007f99e18577f3 abort ./stdlib/abort.c:81:7
 #9 0x000056213676703e (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x2a6403e)
#10 0x0000562134babecf foundRecursiveSymbolDef(llvm::MCSymbol*, llvm::MCExpr const*) AMDGPUMCResourceInfo.cpp:0:0
#11 0x0000562134bad0a7 llvm::MCResourceInfo::gatherResourceInfo(llvm::MachineFunction const&, llvm::AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo const&, llvm::MCContext&) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0xeaa0a7)
#12 0x0000562134b9d25c llvm::AMDGPUAsmPrinter::runOnMachineFunction(llvm::MachineFunction&) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0xe9a25c)
#13 0x0000562135ae06b7 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#14 0x000056213614cf07 llvm::FPPassManager::runOnFunction(llvm::Function&) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x2449f07)
#15 0x00005621356cfaf2 (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) CallGraphSCCPass.cpp:0:0
#16 0x000056213614dd11 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x244ad11)
#17 0x0000562136aabfb8 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x2da8fb8)
#18 0x0000562137151775 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x344e775)
#19 0x0000562138eaf87c clang::ParseAST(clang::Sema&, bool, bool) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x51ac87c)
#20 0x000056213742fd69 clang::FrontendAction::Execute() (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x372cd69)
#21 0x00005621373a9595 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x36a6595)
#22 0x000056213750e423 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0x380b423)
#23 0x0000562134b839d7 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0xe809d7)
#24 0x0000562134b7b02a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#25 0x0000562134b7f2ee clang_main(int, char**, llvm::ToolContext const&) (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0xe7c2ee)
#26 0x0000562134aaaa5b main (/buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang-19+0xda7a5b)
#27 0x00007f99e1858d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16

@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 11, 2024

LLVM Buildbot has detected a new failure on builder openmp-offload-amdgpu-runtime running on omp-vega20-0 while building llvm at step 7 "Add check check-offload".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/30/builds/8082

Here is the relevant piece of the build log for the reference
Step 7 (Add check check-offload) failure: test (failure)
******************** TEST 'libomptarget :: amdgcn-amd-amdhsa :: api/ompx_sync.cpp' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang++ -fopenmp    -I /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src  -nogpulib -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib  -fopenmp-targets=amdgcn-amd-amdhsa /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/api/ompx_sync.cpp -o /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/api/Output/ompx_sync.cpp.tmp /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a && /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/api/Output/ompx_sync.cpp.tmp | /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/api/ompx_sync.cpp
# executed command: /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang++ -fopenmp -I /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -nogpulib -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -fopenmp-targets=amdgcn-amd-amdhsa /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/api/ompx_sync.cpp -o /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/api/Output/ompx_sync.cpp.tmp /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# .---command stderr------------
# | already visited expression
# | UNREACHABLE executed at /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp:103!
# | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
# | Stack dump:
# | 0.	Program arguments: /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld --no-undefined -shared --no-undefined /tmp/lit-tmp-u0hn8a4i/ompx_sync-cbe791-amdgcn-amd-amdhsa-gfx908-65c343.o /tmp/lit-tmp-u0hn8a4i/devicertl-amdgpu-gfx908-amdgcn-amd-amdhsa-gfx908-5259dc.o -plugin-opt=mcpu=gfx908 -plugin-opt=O2 --lto-CGO2 -o /tmp/lit-tmp-u0hn8a4i/ompx_sync.cpp.tmp.amdgcn.gfx908-c90456.img
# | 1.	Running pass 'CallGraph Pass Manager' on module 'ld-temp.o'.
# | 2.	Running pass 'AMDGPU Assembly Printer' on function '@__omp_offloading_802_b38825f__Z3fooi_l10_omp_outlined'
# |  #0 0x000055cc0efdb35f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld+0x83835f)
# |  #1 0x000055cc0efd8894 SignalHandler(int) Signals.cpp:0:0
# |  #2 0x00007fa258469420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
# |  #3 0x00007fa257f3600b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
# |  #4 0x00007fa257f15859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
# |  #5 0x000055cc0ef6e50e (/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld+0x7cb50e)
# |  #6 0x000055cc0f94f512 foundRecursiveSymbolDef(llvm::MCSymbol*, llvm::MCExpr const*) AMDGPUMCResourceInfo.cpp:0:0
# |  #7 0x000055cc0f94fe0b llvm::MCResourceInfo::assignResourceInfoExpr(long, llvm::MCResourceInfo::ResourceInfoKind, llvm::AMDGPUMCExpr::VariantKind, llvm::MachineFunction const&, llvm::SmallVectorImpl<llvm::Function const*> const&, llvm::MCContext&) (/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld+0x11ace0b)
# |  #8 0x000055cc0f950308 llvm::MCResourceInfo::gatherResourceInfo(llvm::MachineFunction const&, llvm::AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo const&, llvm::MCContext&) (/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld+0x11ad308)
# |  #9 0x000055cc0f941401 llvm::AMDGPUAsmPrinter::runOnMachineFunction(llvm::MachineFunction&) (/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld+0x119e401)
# | #10 0x000055cc1087cfe5 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
# | #11 0x000055cc125a0d28 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld+0x3dfdd28)
# | #12 0x000055cc11bcb1e2 (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) CallGraphSCCPass.cpp:0:0
# | #13 0x000055cc125a1a17 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld+0x3dfea17)
# | #14 0x000055cc1056846d codegen(llvm::lto::Config const&, llvm::TargetMachine*, std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, unsigned int, llvm::Module&, llvm::ModuleSummaryIndex const&) LTOBackend.cpp:0:0
# | #15 0x000055cc10569cfd llvm::lto::backend(llvm::lto::Config const&, std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, unsigned int, llvm::Module&, llvm::ModuleSummaryIndex&) (/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld+0x1dc6cfd)
# | #16 0x000055cc1055a607 llvm::lto::LTO::runRegularLTO(std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>) (/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld+0x1db7607)
# | #17 0x000055cc1055e8b9 llvm::lto::LTO::run(std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, llvm::FileCache) (/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld+0x1dbb8b9)
# | #18 0x000055cc0f1bdb5f lld::elf::BitcodeCompiler::compile() (/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld+0xa1ab5f)
# | #19 0x000055cc0f117f47 void lld::elf::LinkerDriver::compileBitcodeFiles<llvm::object::ELFType<(llvm::endianness)1, true>>(bool) (/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld+0x974f47)
# | #20 0x000055cc0f136917 void lld::elf::LinkerDriver::link<llvm::object::ELFType<(llvm::endianness)1, true>>(llvm::opt::InputArgList&) (/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld+0x993917)
# | #21 0x000055cc0f13c763 lld::elf::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) (/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld+0x999763)
# | #22 0x000055cc0f13cdba lld::elf::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) (/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld+0x999dba)
# | #23 0x000055cc0f015120 lld::unsafeLldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayRef<lld::DriverDef>, bool) (/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld+0x872120)
# | #24 0x000055cc0ef47f56 lld_main(int, char**, llvm::ToolContext const&) (/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld+0x7a4f56)
# | #25 0x000055cc0ee859eb main (/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld+0x6e29eb)
# | #26 0x00007fa257f17083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
# | #27 0x000055cc0ef4788e _start (/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/ld.lld+0x7a488e)
# | clang: error: unable to execute command: Aborted (core dumped)
# | clang: error: ld.lld command failed due to signal (use -v to see invocation)
# | /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/bin/clang-linker-wrapper: error: 'clang' failed
# | clang++: error: linker command failed with exit code 1 (use -v to see invocation)
# `-----------------------------
# error: command failed with exit status: 1
...

@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 11, 2024

LLVM Buildbot has detected a new failure on builder openmp-offload-libc-amdgpu-runtime running on omp-vega20-1 while building llvm at step 10 "Add check check-offload".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/6942

Here is the relevant piece of the build log for the reference
Step 10 (Add check check-offload) failure: test (failure)
******************** TEST 'libomptarget :: amdgcn-amd-amdhsa :: api/ompx_sync.cpp' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang++ -fopenmp    -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src  -nogpulib -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib  -fopenmp-targets=amdgcn-amd-amdhsa /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/api/ompx_sync.cpp -o /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/api/Output/ompx_sync.cpp.tmp -Xoffload-linker -lc -Xoffload-linker -lm /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a && /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/api/Output/ompx_sync.cpp.tmp | /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/api/ompx_sync.cpp
# executed command: /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang++ -fopenmp -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -nogpulib -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -fopenmp-targets=amdgcn-amd-amdhsa /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/api/ompx_sync.cpp -o /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/api/Output/ompx_sync.cpp.tmp -Xoffload-linker -lc -Xoffload-linker -lm /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# .---command stderr------------
# | already visited expression
# | UNREACHABLE executed at /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp:103!
# | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
# | Stack dump:
# | 0.	Program arguments: /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld --no-undefined -shared -L/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/../lib/amdgcn-amd-amdhsa --no-undefined /tmp/lit-tmp-mibgyqy2/ompx_sync-ff272d-amdgcn-amd-amdhsa-gfx906-dce7f1.o /tmp/lit-tmp-mibgyqy2/devicertl-amdgpu-gfx906-amdgcn-amd-amdhsa-gfx906-1fca15.o -lc -lm -plugin-opt=mcpu=gfx906 -plugin-opt=O2 --lto-CGO2 -o /tmp/lit-tmp-mibgyqy2/ompx_sync.cpp.tmp.amdgcn.gfx906-654961.img
# | 1.	Running pass 'CallGraph Pass Manager' on module 'ld-temp.o'.
# | 2.	Running pass 'AMDGPU Assembly Printer' on function '@__omp_offloading_802_d8282a8__Z3fooi_l10_omp_outlined'
# |  #0 0x00005614bad2f57f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld+0x83857f)
# |  #1 0x00005614bad2cab4 SignalHandler(int) Signals.cpp:0:0
# |  #2 0x00007f2f57e36420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
# |  #3 0x00007f2f5774900b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
# |  #4 0x00007f2f57728859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
# |  #5 0x00005614bacc272e (/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld+0x7cb72e)
# |  #6 0x00005614bb6a6082 foundRecursiveSymbolDef(llvm::MCSymbol*, llvm::MCExpr const*) AMDGPUMCResourceInfo.cpp:0:0
# |  #7 0x00005614bb6a697b llvm::MCResourceInfo::assignResourceInfoExpr(long, llvm::MCResourceInfo::ResourceInfoKind, llvm::AMDGPUMCExpr::VariantKind, llvm::MachineFunction const&, llvm::SmallVectorImpl<llvm::Function const*> const&, llvm::MCContext&) (/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld+0x11af97b)
# |  #8 0x00005614bb6a6e78 llvm::MCResourceInfo::gatherResourceInfo(llvm::MachineFunction const&, llvm::AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo const&, llvm::MCContext&) (/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld+0x11afe78)
# |  #9 0x00005614bb697f71 llvm::AMDGPUAsmPrinter::runOnMachineFunction(llvm::MachineFunction&) (/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld+0x11a0f71)
# | #10 0x00005614bc5d3b55 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
# | #11 0x00005614be2f7898 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld+0x3e00898)
# | #12 0x00005614bd921d52 (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) CallGraphSCCPass.cpp:0:0
# | #13 0x00005614be2f8587 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld+0x3e01587)
# | #14 0x00005614bc2befdd codegen(llvm::lto::Config const&, llvm::TargetMachine*, std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, unsigned int, llvm::Module&, llvm::ModuleSummaryIndex const&) LTOBackend.cpp:0:0
# | #15 0x00005614bc2c086d llvm::lto::backend(llvm::lto::Config const&, std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, unsigned int, llvm::Module&, llvm::ModuleSummaryIndex&) (/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld+0x1dc986d)
# | #16 0x00005614bc2b1177 llvm::lto::LTO::runRegularLTO(std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>) (/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld+0x1dba177)
# | #17 0x00005614bc2b5429 llvm::lto::LTO::run(std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, llvm::FileCache) (/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld+0x1dbe429)
# | #18 0x00005614baf11d7f lld::elf::BitcodeCompiler::compile() (/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld+0xa1ad7f)
# | #19 0x00005614bae6c167 void lld::elf::LinkerDriver::compileBitcodeFiles<llvm::object::ELFType<(llvm::endianness)1, true>>(bool) (/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld+0x975167)
# | #20 0x00005614bae8ab37 void lld::elf::LinkerDriver::link<llvm::object::ELFType<(llvm::endianness)1, true>>(llvm::opt::InputArgList&) (/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld+0x993b37)
# | #21 0x00005614bae90983 lld::elf::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) (/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld+0x999983)
# | #22 0x00005614bae90fda lld::elf::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) (/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld+0x999fda)
# | #23 0x00005614bad69340 lld::unsafeLldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayRef<lld::DriverDef>, bool) (/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld+0x872340)
# | #24 0x00005614bac9c176 lld_main(int, char**, llvm::ToolContext const&) (/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld+0x7a5176)
# | #25 0x00005614babd9c0b main (/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld+0x6e2c0b)
# | #26 0x00007f2f5772a083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
# | #27 0x00005614bac9baae _start (/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/ld.lld+0x7a4aae)
# | clang: error: unable to execute command: Aborted (core dumped)
# | clang: error: ld.lld command failed due to signal (use -v to see invocation)
# | /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/bin/clang-linker-wrapper: error: 'clang' failed
# | clang++: error: linker command failed with exit code 1 (use -v to see invocation)
# `-----------------------------
# error: command failed with exit status: 1
...

JanekvO added a commit that referenced this pull request Oct 11, 2024
JanekvO added a commit to JanekvO/llvm-project that referenced this pull request Oct 14, 2024
…tiple functions

I was wrong last patch. I viewed the visited set purely as a possible
recursion deterrent where functions calling a callee multiple times are
handled elsewhere. This wouldn't consider cases where a function is
called multiple times by different callers still part of the same call
graph. New test shows the aforementioned case.

Reapplies llvm#111004
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
…nctions (llvm#111004)

Avoid constructing recursive MCExpr definitions when multiple functions
cause a recursion.

Fixes llvm#110863
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
JanekvO added a commit that referenced this pull request Nov 15, 2024
…tiple functions (#112251)

I was wrong last patch. I viewed the `Visited` set purely as a possible
recursion deterrent where functions calling a callee multiple times are
handled elsewhere. This doesn't consider cases where a function is
called multiple times by different callers still part of the same call
graph. New test shows the aforementioned case.

Reapplies #111004, fixes #115562.
abidh pushed a commit to abidh/llvm-project that referenced this pull request Feb 4, 2025
…ass (llvm#102913)

Converts AMDGPUResourceUsageAnalysis pass from Module to MachineFunction
pass. Moves function resource info propagation to to MC layer (through
helpers in AMDGPUMCResourceInfo) by generating MCExprs for every
function resource which the emitters have been prepped for.

Fixes llvm#64863

[AMDGPU] Fix stack size metadata for functions with direct and indirect calls (llvm#110828)

When a function has an external call, it should still use the stack
sizes of direct, known, calls to calculate its own stack size

[AMDGPU] Fix resource usage information for unnamed functions (llvm#115320)

Resource usage information would try to overwrite unnamed functions if
there are multiple within the same compilation unit. This aims to either
use the `MCSymbol` assigned to the unnamed function (i.e.,
`CurrentFnSym`), or, rematerialize the `MCSymbol` for the unnamed
function.

Reapply [AMDGPU] Avoid resource propagation for recursion through multiple functions (llvm#112251)

I was wrong last patch. I viewed the `Visited` set purely as a possible
recursion deterrent where functions calling a callee multiple times are
handled elsewhere. This doesn't consider cases where a function is
called multiple times by different callers still part of the same call
graph. New test shows the aforementioned case.

Reapplies llvm#111004, fixes llvm#115562.

[AMDGPU] Newly added test modified for recent SGPR use change (llvm#116427)

Mistimed rebase for llvm#112251 which added new tests which did not consider
the changes introduced in llvm#112403 yet

Change-Id: I4dfe6a1b679137e080a6d2b44016347ea704b014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[AMDGPU] Infinite recursion in evaluateAsRelocatableImpl when evaluating a cyclical SCC
5 participants