[PATCH] D49919: [InstCombine] Fold Select with OR condition

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 27 10:04:28 PDT 2018


lebedev.ri added inline comments.


================
Comment at: lib/Transforms/InstCombine/InstCombineSelect.cpp:65-87
+static Value *foldSelectInstBinaryOp(SelectInst &Sel) {
+  Value *A, *B;
+  Value *TrueVal = Sel.getTrueValue();
+  Value *FalseVal = Sel.getFalseValue();
+  if (match(Sel.getCondition(), m_c_Or(m_Value(A), m_Value(B)))) {
+    CmpInst::Predicate Pred1, Pred2;
+    Value *T1, *T2;
----------------
One more thing - this is slightly too verbose. I suspect it may miss some commutative cases, too.
Please make better use of pattern matchers.

How about:
```
Value *foldSelectInstBinaryOp(SelectInst &Sel) {
  Value *X, *V1, *V2;
  CmpInst::Predicate Pred1, Pred2;
  if (!match(&Sel, m_Select(m_c_Or(m_ICmp(Pred1, m_Value(X), m_Value(V1)),
                                   m_c_ICmp(Pred2, m_Deferred(X), m_Value(V2))),
                            m_Deferred(X), m_Deferred(V1))) ||
      !(Pred1 == Pred2 && Pred1 == ICmpInst::ICMP_NE))
    return nullptr;
  return X;
}

```


Repository:
  rL LLVM

https://reviews.llvm.org/D49919





More information about the llvm-commits mailing list