[InstCombine] Constant-folding a musttail libcall (sin/cos) replaces its returned value and produces invalid IR
InstCombine constant-folds a musttail call to a math libcall with a constant argument and replaces the
returned value with the constant, but keeps the musttail call. The verifier then rejects the module because
the result of a musttail call must be returned.
Reproducer (opt -passes=instcombine, no target flags needed):
declare double @sin(double)
define double @f(double %x) {
%r = musttail call double @sin(double 0.0)
ret double %r
}
$ opt -passes=instcombine -disable-output test.ll
musttail call result must be returned
ret double 0.000000e+00
LLVM ERROR: Broken module found, compilation aborted!
Output with -disable-verify:
define double @f(double %x) {
%r = musttail call double @sin(double 0.000000e+00)
ret double 0.000000e+00
}
Expected: valid IR — either leave a musttail call (and its ret) alone, or drop the call together with the
musttail marker.
Notes: same with @cos and with sin(1.0); @llvm.sin.f64, -passes=instsimplify, early-cse, sccp and gvn
are fine, so it looks specific to InstCombine's libcall folding path. Also reproduces on a 2026-11-05 trunk.
Found with a mutation-based IR fuzzer. Triage, test-case minimization and parts of this write-up were assisted by an LLM; verified the reproducer on b23814056.
Assisted-by: Claude (Anthropic)
Hi @arie2026 please can I pick this up?