[PATCH] D96945: [InstCombine] Add simplification of two logical and/ors

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 7 04:11:40 PST 2021


nikic added inline comments.


================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:4858
+      return directlyImpliesPoison(ValAssumedPoison, SI->getCondition(),
+                                   Depth + 1);
+
----------------
Feel free to already land this part separately.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:2640
+        match(FalseVal, m_c_LogicalOr(m_Specific(CondVal), m_Value(B))))
+      return replaceOperand(SI, 2, B);
+
----------------
aqjune wrote:
> aqjune wrote:
> > nikic wrote:
> > > What currently happens for something like `a ? (a | b) : false`? I assume it doesn't get folded?
> > No, it doesn't get folded.
> > That being said, I think it is better to simply propagate true/false to select operands, e.g.
> > `a ? (a | b) : false` -> `a ? (true | b) : false` -> `a ? b : false`. I'll update this patch to do so.
> Nevermind, since the replacement needs to take care of # uses but the current version doesn't need it, I think it does not completely cover the foldings in this patch.
What I had in mind here is that this is basically the `foldSelectValueEquivalence()` fold, just that instead of `x == C ? y : z` we have `x == true ? y : z`, with the `== true` comparison being implicit. If we generalize that fold to handle this special case, this should work automatically (either via SimplifyWithOpReplaced, or by direct operand replacement for single use).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96945



More information about the llvm-commits mailing list