[PATCH] D140933: [LVI] Look through negations when evaluating conditions

Keno Fischer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 4 06:12:44 PST 2023


loladiro added inline comments.


================
Comment at: llvm/lib/Analysis/LazyValueInfo.cpp:1207
+    return inverse(NV->second);
+  }
+
----------------
nikic wrote:
> Hm, I don't think this is correct if N is and and/or, or generally in any case where the returned lattice value does not represent the condition exactly, but is a superset. Inversion would exclude that difference between the exact set and superset. I'd suggest adding a test case for some case where getValueFromCondition() performs an approximation.
> 
> Could we instead flip isTrueDest, i.e. do something like this at the top?
> ```
> Value *N;
> if (match(Cond, m_Not(m_Value(N)))) {
>   isTrueDest = !isTrueDest;
>   Cond = N;
> }
> ```
Good catch, though I don't think that would be correct either, because then the caching logic is incorrect. However, I think we could just add `isTrueDest` to the cache key and then this should work fine. Let me do that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140933



More information about the llvm-commits mailing list