[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:03:33 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:
https://github.com/llvm/llvm-project/blob/d5093aac543dfd24f339f7d43aa02282f7c16fa5/llvm/lib/Analysis/ValueTracking.cpp#L3075-L3077
https://github.com/llvm/llvm-project/pull/89643
More information about the llvm-commits
mailing list