[llvm] [ValueTracking] Handle `icmp pred (trunc X), C` in `computeKnownBitsFromCmp` (PR #82803)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 5 09:20:36 PST 2024
================
@@ -724,10 +724,22 @@ static void computeKnownBitsFromCond(const Value *V, Value *Cond,
Known = Known.unionWith(Known2);
}
- if (auto *Cmp = dyn_cast<ICmpInst>(Cond))
- computeKnownBitsFromCmp(
- V, Invert ? Cmp->getInversePredicate() : Cmp->getPredicate(),
- Cmp->getOperand(0), Cmp->getOperand(1), Known, SQ);
+ if (auto *Cmp = dyn_cast<ICmpInst>(Cond)) {
+ ICmpInst::Predicate Pred =
+ Invert ? Cmp->getInversePredicate() : Cmp->getPredicate();
+ Value *LHS = Cmp->getOperand(0);
+ Value *RHS = Cmp->getOperand(1);
+
+ // Handle icmp pred (trunc V), C
+ if (match(LHS, m_Trunc(m_Specific(V)))) {
+ KnownBits DstKnown(LHS->getType()->getScalarSizeInBits());
+ computeKnownBitsFromCmp(LHS, Pred, LHS, RHS, DstKnown, SQ);
+ Known = Known.unionWith(DstKnown.anyext(Known.getBitWidth()));
+ return;
+ }
----------------
goldsteinn wrote:
Hmm? its an NFC refactor. My point is you could drop the `if(match(LHS, m_Trunc(...)))` and the code would have the same behavior.
https://github.com/llvm/llvm-project/pull/82803
More information about the llvm-commits
mailing list