[llvm] [ValueTracking] Handle trunc to i1 as condition in dominating condition. (PR #126414)

via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 9 08:50:00 PST 2025


================
@@ -801,6 +801,22 @@ static void computeKnownBitsFromCond(const Value *V, Value *Cond,
 
   if (auto *Cmp = dyn_cast<ICmpInst>(Cond))
     computeKnownBitsFromICmpCond(V, Cmp, Known, SQ, Invert);
+
+  if (match(Cond, m_Not(m_Value(Cond))))
+    Invert = !Invert;
+
+  if (match(Cond, m_Trunc(m_Specific(V)))) {
+    KnownBits DstKnown(1);
+    if (Invert) {
+      DstKnown.setAllZero();
+    } else {
+      DstKnown.setAllOnes();
+    }
+    if (cast<TruncInst>(Cond)->hasNoUnsignedWrap())
+      Known = Known.unionWith(DstKnown.zext(Known.getBitWidth()));
----------------
goldsteinn wrote:

you can `sext` if you have `trunc nsw`

https://github.com/llvm/llvm-project/pull/126414


More information about the llvm-commits mailing list