[llvm] [DeadArgElim] fix verifier failure when changing musttail's function signature (PR #127366)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 10 05:08:21 PDT 2025
u4f3 wrote:
Previously:
```
surveyFunction:
... a lot of other staff
if Fn musttail call anotherFn:
if we can't analyze anotherFn/somehow not internal:
freeze Fn, we can't change Fn's signature
end
end
if Fn is musttail called by others or has musttail calls:
mark all arguments to be live, so we can't change them
end
end surveyFunction
propagateVirtMustcallLiveness:
all frozen fns' musttail caller should be frozen too.
end propagateVirtMustcallLiveness
```
So we will be able to somehow change the return type in `removeDeadStuffFromFunction` . We use insert and extract to change the return type. It will only be legal if we change the caller’s and callee’s return type to the same return type at the same time, otherwise we will fail the verifier. So #107569 crashes.
As for #126817, the return type of `C` is changed to void since nobody use the return value of the internal function…So the verifier fails again.
```llvm
define i64 @A() {
entry:
%v2660 = musttail call i64 @B()
ret i64 %v2660
}
define internal i64 @B() {
entry:
ret i64 0
}
define internal i64 @C() {
entry:
%v30543 = musttail call i64 @B()
ret i64 %v30543
}
```
So according to llvm langref: [LLVM Language Reference Manual — LLVM 21.0.0git documentation](https://llvm.org/docs/LangRef.html#id334). If the cc is not tailcc of swiftcc, we need to ensure they have exactly the same signature. Otherwise we only need to ensure the share the same return type here in DeadArgElim. So I change the logic to:
```
surveyFunction:
... a lot of other staff
if Fn musttail call anotherFn:
freeze the whole Fn or just the return type according to cc, and if we freeze the whole Fn, return.
end
if Fn is musttail called by others:
freeze the whole Fn or just the return type according to cc, and if we freeze the whole Fn, return.
end
end surveyFunction
propagateVirtMustcallLiveness:
No need for this since if the cc is not tailcc of swifttailcc, we already mark both the caller and callee frozen.
end propagateVirtMustcallLiveness
```
https://github.com/llvm/llvm-project/pull/127366
More information about the llvm-commits
mailing list