[llvm-branch-commits] [clang] [llvm] [llvm] Introduce callee_type metadata (PR #87573)
Prabhu Rajasekaran via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Jul 18 08:55:50 PDT 2025
================
@@ -3423,6 +3424,17 @@ static void combineMetadata(Instruction *K, const Instruction *J,
MDNode::getMergedCallsiteMetadata(KCallSite, JCallSite));
}
+ // Merge callee_type metadata.
+ // Handle separately to support cases where only one instruction has the
+ // metadata.
----------------
Prabhuk wrote:
I tried the following but could not get the simplifyCFG to produce that case:
```
define ptr @_Z10test_diff_fnptrsb(i1 zeroext %b) {
entry:
%fn = alloca ptr
%fn2 = alloca ptr
store ptr @_Znwm, ptr %fn
store ptr @_Znwm, ptr %fn2
br i1 %b, label %if.then, label %if.else
if.then: ; preds = %entry
%call = call ptr %fn(i64 4), !callee_type !4
br label %if.end
if.else: ; preds = %entry
%call1 = call ptr %fn2(i64 4), !callee_type !3
br label %if.end
if.end: ; preds = %if.else, %if.then
%x.0 = phi ptr [ %call, %if.then ], [ %call1, %if.else ]
ret ptr %x.0
}
declare ptr @_Znwm(i64)
```
`bin/opt -passes=simplifycfg -S < merge-callee-type-metadata.ll` was the command used.
This was the output:
```
define ptr @_Z10test_diff_fnptrsb(i1 zeroext %b) {
entry:
%fn = alloca ptr, align 8
%fn2 = alloca ptr, align 8
store ptr @_Znwm, ptr %fn, align 8
store ptr @_Znwm, ptr %fn2, align 8
br i1 %b, label %if.then, label %if.else
if.then: ; preds = %entry
%call = call ptr %fn(i64 4), !callee_type !0
br label %if.end
if.else: ; preds = %entry
%call1 = call ptr %fn2(i64 4), !callee_type !2
br label %if.end
if.end: ; preds = %if.else, %if.then
%x.0 = phi ptr [ %call, %if.then ], [ %call1, %if.else ]
ret ptr %x.0
}
```
I tried combinations where either %call and %call1 does not have callee_type. Tried both without callee_type as well. Only case where the call instructions get merged is when both instructions carried the same function ptr %fn.
https://github.com/llvm/llvm-project/pull/87573
More information about the llvm-branch-commits
mailing list