[PATCH] D48223: DAG combine "and|or (select c, -1, 0), x" -> "select c, x, 0|-1"

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 16 07:10:54 PDT 2018


spatel requested changes to this revision.
spatel added inline comments.
This revision now requires changes to proceed.


================
Comment at: lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1883-1889
+  unsigned SelOpNo = 0;
   SDValue Sel = BO->getOperand(0);
+  if (Sel.getOpcode() != ISD::SELECT || !Sel.hasOneUse()) {
+    SelOpNo = 1;
+    Sel = BO->getOperand(1);
+  }
+
----------------
This change is independent of the and/or enhancement. We're now allowing folding when the binop has a constant operand 0. That seems like a good enhancement for non-commutative binops, but it should have its own tests using opcodes besides 'and'/'or' and be split into its own patch.

Example based on one of the original tests from rL296699:

```
define <2 x double> @sel_constants_fmul_constant_vec(i1 %cond) {
  %sel = select i1 %cond, <2 x double> <double -4.0, double 12.0>, <2 x double> <double 23.3, double 11.0>
  %bo = fsub <2 x double> <double 5.1, double 3.14>, %sel
  ret <2 x double> %bo
}

```


https://reviews.llvm.org/D48223





More information about the llvm-commits mailing list