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

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 27 04:13:42 PST 2021


aqjune added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:2642-2649
+    // select (select a, true, b), true, b -> select a, true, b
+    if (match(CondVal, m_Select(m_Value(A), m_One(), m_Value(B))) &&
+        match(TrueVal, m_One()) && match(FalseVal, m_Specific(B)))
+      return replaceOperand(SI, 0, A);
+    // select (select a, b, false), b, false -> select a, b, false
+    if (match(CondVal, m_Select(m_Value(A), m_Value(B), m_Zero())) &&
+        match(TrueVal, m_Specific(B)) && match(FalseVal, m_Zero()))
----------------
lebedev.ri wrote:
> Why does this only deal with `select` form in the cond operand, unlike the two folds above?
It's because the non-select cond cases are dealt with the existing transformations (line 2593, 2598).
They fold `select (or a, b), true, b` into `or (or a, b), b` which becomes  `or a, b` by visitOr.
This is sound: https://alive2.llvm.org/ce/z/UgMbNq 
Similarly,  `select (and a, b), b, false` is folded into `and (and a, b), b` which becomes `and a, b`.
This is also okay (https://alive2.llvm.org/ce/z/AWoJK6).


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