[llvm] [AMDGPU] Omit umin on ctlz/cttz if operand is non-zero. (PR #79127)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 23 06:24:34 PST 2024
================
@@ -3116,9 +3116,14 @@ SDValue AMDGPUTargetLowering::LowerCTLZ_CTTZ(SDValue Op, SelectionDAG &DAG) cons
// (cttz_zero_undef src) -> (S_FF1_I32_B64 src)
SDValue NewOpr = DAG.getNode(NewOpc, SL, MVT::i32, Src);
if (!ZeroUndef) {
- const SDValue ConstVal = DAG.getConstant(
- Op.getValueType().getScalarSizeInBits(), SL, MVT::i32);
- NewOpr = DAG.getNode(ISD::UMIN, SL, MVT::i32, NewOpr, ConstVal);
+ // umin can be omitted if the operand is known to be non-zero.
+ auto KB = DAG.computeKnownBits(Src);
+ auto const IsNonZero = KB.countMinPopulation() > 0u;
+ if (!IsNonZero) {
----------------
jayfoad wrote:
```suggestion
if (!KB.isNonZero) {
```
https://github.com/llvm/llvm-project/pull/79127
More information about the llvm-commits
mailing list