[llvm] [ValueTracking] Add support for `trunc nuw/nsw` in isKnowNonZero (PR #89643)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 23 02:01:18 PDT 2024
================
@@ -2632,6 +2632,13 @@ static bool isKnownNonZeroFromOperator(const Operator *I,
Q.DL.getTypeSizeInBits(I->getType()).getFixedValue())
return isKnownNonZero(I->getOperand(0), Q, Depth);
break;
+ case Instruction::Trunc: {
+ auto *TI = cast<TruncInst>(I);
+ // nuw/nsw trunc preserves zero/non-zero status of input.
+ if (TI->hasNoSignedWrap() || TI->hasNoUnsignedWrap())
+ return isKnownNonZero(TI->getOperand(0), Q, Depth + 1);
----------------
dtcxzyw wrote:
```suggestion
return isKnownNonZero(TI->getOperand(0), Q, Depth);
```
https://github.com/llvm/llvm-project/pull/89643
More information about the llvm-commits
mailing list