[llvm] [InstCombine] Simplify zext(sub(0, trunc(x))) -> and(sub(0, x), mask) (Fixes #165306) (PR #167101)
V S Susi Krishna via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 8 03:35:37 PST 2025
Susikrishna wrote:
> I'd expect this pattern to be handled in `CanEvaluateZExtd`.
Hi @dtcxzyw, I'm still learning my way around InstCombine. I tried to trace the logic, and it looks like canEvaluateZExtd is called from inside an if statement that first checks shouldChangeType(SrcTy, DestTy)
[shouldChangeType](https://github.com/llvm/llvm-project/blob/8f2b167de4a1268160c06512d08863a9e8f43290/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp#L1239C3-L1240C66).
In my test case, the types are i6 (Source) and i64 (Destination). It seems shouldChangeType returns false for this, so the canEvaluateZExtd function is never actually called.
I'm guessing this is because the cost model doesn't recommend promoting from a small type like i6 all the way to i64?
Is that the correct approach for this kind of special pattern, or is there a better way to do this that I'm not seeing?
https://github.com/llvm/llvm-project/pull/167101
More information about the llvm-commits
mailing list