[llvm] [Analysis] Only fold `trunc X` to `(X & Mask)` if `Mask == getLowBitsSet(bit width of original operands)` (PR #176589)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 19 11:08:57 PST 2026
dtcxzyw wrote:
I mean changing the code here: https://github.com/llvm/llvm-project/blob/d7cbc7f9e465344dd326eaf6e5a6cfa90285ce8e/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp#L6291-L6298
This should allow patterns like `(trunc i32 %x to i16) u> 15 -> (and %x, 65520) == 0` but not `(trunc i32 %x to i16) == 15 -> (and i32 %x, 65535) == 15`.
However, I double checked and found that it didn't happen, since it was already guarded by the following check (`DecomposeAnd` is false by default):
https://github.com/llvm/llvm-project/blob/010f6c8658da62e031fc02a1e3db6785884c2ddc/llvm/lib/Analysis/CmpInstAnalysis.cpp#L83-L85
We need more time to investigate the root cause of regressions, as demonstrated in https://github.com/dtcxzyw/llvm-opt-benchmark/pull/3316/files (See bench/llvm/optimized/SemaType.ll, bench/libigl/optimized/bijective_composite_harmonic_mapping.ll, and bench/cpython/optimized/_ssl.ll). With https://github.com/llvm/llvm-project/pull/171195, new masking instructions are introduced in multiple IR files. So I guess there are some optimizations converting truncs into ands unconditionally.
https://github.com/llvm/llvm-project/pull/176589
More information about the llvm-commits
mailing list