RKSimon wrote: Can we keep the existing cost estimate code, but instead of returning Cost just stash it as a optional<ExpansionCost> value and fallback to it if the ISD legality fails? https://github.com/llvm/llvm-project/pull/97463