[llvm] [InstCombine] Simplify zext(sub(0, trunc(x))) -> and(sub(0, x), mask) (Fixes #165306) (PR #167101)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 10 05:36:29 PST 2025
dtcxzyw wrote:
> @dtcxzyw You were right about the scalar case, it worked when I kept the datalayout. Like RKSimon mentioned, when I run the test (even with the datalayout), my output shows that:
>
> ```
> @foo (which uses <2 x i64>)
>
> @bar (which uses <4 x i64>)
>
> @baz (which uses <8 x i64>) ...are all still not being simplified.
> ```
>
> I think I found the reason for the difference. I was looking at the shouldChangeType function, and the Type* version has this check at the very top: C++
>
> ```
> bool InstCombinerImpl::shouldChangeType(Type *From, Type *To) const {
> if (!From->isIntegerTy() || !To->isIntegerTy())
> return false;
> ...
> }
> ```
>
> This check returns false for all vector types, so the canEvaluateZExtd path is never reached for them (but it is reached for the scalar i6 type).
InstCombine is conservative about changing vector types due to the lack of cost modeling. Perhaps we can do some simple fold in VectorCombine instead.
https://github.com/llvm/llvm-project/pull/167101
More information about the llvm-commits
mailing list