[PATCH] D37896: [DAGCombine] Resolving PR34474 by transforming mul(x, 2^c +/- 1) -> sub/add(shl(x, c) x) for any type including vector types

Simon Pilgrim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 15 04:25:16 PDT 2017


RKSimon added a comment.

I've added a range of test cases at https://reviews.llvm.org/rL313353 - please can you update?

It might be we need suitable combines for (add (mul X, C), X) -> (mul (X, C+1)) and  (sub (mul X, C), X) -> (mul (X, C-1)) as well



================
Comment at: lib/CodeGen/SelectionDAG/DAGCombiner.cpp:2683
+    int isPow2 = Plus1.isPowerOf2() ? 1 : Minus1.isPowerOf2() ? -1 : 0;
+    if (isPow2) {
+      APInt &Pow2 = isPow2 > 0 ? Plus1 : Minus1;
----------------
You should be able to match non-uniform constant vectors with matchUnaryPredicate


================
Comment at: lib/CodeGen/SelectionDAG/DAGCombiner.cpp:2695
+    }
+  }
+
----------------
The other pow2 combines are before the mul (shl X, c1), c2 case - put this there with them?


https://reviews.llvm.org/D37896





More information about the llvm-commits mailing list