[PATCH] D147900: [ValueTracking] Use `select` condition to help determine if `select` is non-zero

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 21 14:02:29 PDT 2023


nikic added inline comments.


================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:586
+// example Pred=EQ, RHS=isKnownNonZero. cmpExcludesZero is called in loops
+// so the extra compile time may not be worth it, but possible a second API
+// should be created for use outside of loops.
----------------
possible -> possibly


================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:2913
+    if (Op1NonZero && Op2NonZero)
+      return true;
+
----------------
I'd factor this differently, so that you keep the general structure of the previous code (i.e. short circuit if one operand is not known non-zero). Basically move the isKnownNonZero() check into the lambda as well.


================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:2926-2933
+      if (match(I->getOperand(0), m_ICmp(Pred, m_Specific(Op), m_Value(X)))) {
+        // pass
+      } else if (match(I->getOperand(0),
+                       m_ICmp(Pred, m_Value(X), m_Specific(Op)))) {
+        Pred = ICmpInst::getSwappedPredicate(Pred);
+      } else {
+        return false;
----------------



================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:2940
+      // we still have enough information about `X` to conclude `Op` is nonzero.
+      // If a better API ever comes about, update this use.
+      return cmpExcludesZero(Pred, X);
----------------
Redundant with the TODO on cmpExcludesZero.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147900/new/

https://reviews.llvm.org/D147900



More information about the llvm-commits mailing list