[PATCH] D49954: [InstCombine] Fold Select with binary op

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 30 09:47:48 PDT 2018


spatel added inline comments.


================
Comment at: lib/Transforms/InstCombine/InstCombineSelect.cpp:78-82
+  bool IsEq = Pred == ICmpInst::ICMP_EQ;
+  if (IsEq) {
+    if (match(TrueVal, m_c_BinOp(m_Specific(X), m_Value(Z))) &&
+        ConstantExpr::getBinOpIdentity(cast<Instruction>(TrueVal)->getOpcode(),
+                                       X->getType()) == C) {
----------------
Can we eliminate this duplication now? So something like:

  auto *BO = dyn_cast<BinaryOperator>(
      IsEq ? Sel.getTrueValue() : Sel.getFalseValue());
  if (BO && match(BO, ...) && 
      ConstantExpr::getBinOpIdentity(BO, Ty) == C) {
    Sel.setOperand(IsEq ? 1 : 2, Z);
    return &Sel;
  }


https://reviews.llvm.org/D49954





More information about the llvm-commits mailing list