[llvm] [InstCombine] Match a new form of truncating saturation (PR #189703)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 2 07:55:16 PDT 2026
================
@@ -1171,6 +1171,33 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) {
}
}
+ // trunc (select(icmp_ult(A, DestTy_umax+1), A, sext(icmp_sgt(A, 0)))) -->
+ // trunc (smin(smax(0, A), DestTy_umax))
+ if (SrcTy->isIntegerTy() && isPowerOf2_64(SrcTy->getPrimitiveSizeInBits()) &&
+ DestTy->isIntegerTy() &&
----------------
david-arm wrote:
Perhaps better to check the types early on to avoid the cost of checking the sizes, i.e. `if (SrcTy->isIntegerTy() && DestTy->isIntegerTy() && ..)`
Having said that, I'm not surely that it's even legal to have one type an integer and the other a vector of integers. When I try to do that I get this error:
```
error: invalid cast opcode for cast from '<16 x i8>' to 'i8'
```
so I suspect you can drop the `DestTy->isIntegerTy()` entirely anyway.
https://github.com/llvm/llvm-project/pull/189703
More information about the llvm-commits
mailing list