[llvm] [ValueTracking] Handle assume(!(trunc X)) in computeKnownBitsFromContext (PR #219854)
Andreas Jonson via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 12 14:12:15 PDT 2026
================
@@ -1145,6 +1145,21 @@ void llvm::computeKnownBitsFromContext(const Value *V, KnownBits &Known,
Known.One.setBit(0);
return;
}
+ // assume(!(trunc V)) -> last bit of V is 0
+ Value *NotOp;
+ if (match(Arg, m_Not(m_Value(NotOp))) && Arg->hasOneUse() &&
+ NotOp->hasOneUse()) {
+ auto *NotTrunc = dyn_cast<TruncInst>(NotOp);
+ if (NotTrunc && NotTrunc->getOperand(0) == V &&
+ isValidAssumeForContext(I, Q)) {
----------------
andjo403 wrote:
maybe instead of doing the oneUse checks that is a bit of a hack we can do the ephemeral checks here as we know all possible ephemeral values something like
```suggestion
if (match(Arg, m_Not(m_Value(NotOp, m_Trunc(m_Specific(V))))) &&
(Q.AllowEphemerals ||
(Q.CxtI != Arg && Q.CxtI != NotOp && Q.CxtI != V)) &&
isValidAssumeForContext(I, Q.allowEphemerals(true))) {
auto *NotTrunc = cast<TruncInst>(NotOp);
```
https://github.com/llvm/llvm-project/pull/219854
More information about the llvm-commits
mailing list