Skip to content

Commit e3be8fe

Browse files
scottp101igcbot
authored andcommitted
Handle metadata users of old function after legalization
Just replace these users with poison instead of dropping them
1 parent 353f89e commit e3be8fe

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

IGC/AdaptorCommon/LegalizeFunctionSignatures.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,11 @@ void LegalizeFunctionSignatures::FixFunctionBody(Module &M) {
478478

479479
// Now that all instructions are transferred to the new func, delete the old func
480480
pFunc->removeDeadConstantUsers();
481-
pFunc->dropAllReferences();
482-
pFunc->removeFromParent();
481+
// There may be cases where the old function was referenced by just metadata.
482+
// If we've cleaned up all "real" uses, then we can just update the metadata
483+
// with poison so we can delete the function.
484+
pFunc->replaceAllUsesWith(PoisonValue::get(pFunc->getType()));
485+
pFunc->eraseFromParent();
483486
}
484487
}
485488

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2025 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
;
9+
; RUN: igc_opt --opaque-pointers --igc-legalize-function-signatures -S < %s 2>&1 | FileCheck %s
10+
; ------------------------------------------------
11+
; LegalizeFunctionSignatures
12+
; ------------------------------------------------
13+
14+
; Test that functions with illegal types referenced by metadata are handled correctly.
15+
16+
define spir_kernel void @test_kernel() {
17+
call void @foo(i1 true)
18+
ret void
19+
}
20+
21+
define internal void @foo(i1) {
22+
ret void
23+
}
24+
25+
!md = !{!0}
26+
!0 = !{ptr @foo}
27+
28+
; CHECK: !0 = !{ptr poison}

0 commit comments

Comments
 (0)