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

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 30 10:08:11 PDT 2018


xbolva00 marked an inline comment as done.
xbolva00 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) {
----------------
spatel wrote:
> 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;
>   }
Yes, good idea


https://reviews.llvm.org/D49954





More information about the llvm-commits mailing list