[clang] [llvm] [InstCombine] Infer nsw/nuw for trunc (PR #87910)
Nikita Popov via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 7 23:22:13 PDT 2024
================
@@ -897,7 +897,20 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) {
}
}
- return nullptr;
+ bool Changed = false;
+ if (!Trunc.hasNoSignedWrap() &&
+ ComputeMaxSignificantBits(Src, /*Depth=*/0, &Trunc) <= DestWidth) {
+ Trunc.setHasNoSignedWrap(true);
+ Changed = true;
+ }
+ if (!Trunc.hasNoUnsignedWrap() &&
+ MaskedValueIsZero(Src, APInt::getBitsSetFrom(SrcWidth, DestWidth),
+ /*Depth=*/0, &Trunc)) {
+ Trunc.setHasNoUnsignedWrap(true);
+ Changed = true;
----------------
nikic wrote:
Can we infer this in SimplifyDemanded instead, where we already have the KnownBits of the trunc arg?
https://github.com/llvm/llvm-project/pull/87910
More information about the cfe-commits
mailing list