[PATCH] D27714: [DAGCombiner] Use SelectionDAG::isKnownToBeAPowerOfTwo instead of just APInt::isPowerOf2
Andrea Di Biagio via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 14 04:38:05 PST 2016
andreadb accepted this revision.
andreadb added a comment.
This revision is now accepted and ready to land.
Hi Simon,
I only have two minor comments (see below). Otherwise the patch LGTM. Thanks!
About the udiv/urem/sdiv/srem tests. Would it be possible to add extra RUN lines for AVX (non AVX2)? You can probably do that in a separate commit.
Thanks,
Andrea
================
Comment at: lib/CodeGen/SelectionDAG/DAGCombiner.cpp:2492-2502
// fold (urem x, pow2) -> (and x, pow2-1)
- if (N1C && !N1C->isNullValue() && !N1C->isOpaque() &&
- N1C->getAPIntValue().isPowerOf2()) {
- return DAG.getNode(ISD::AND, DL, VT, N0,
- DAG.getConstant(N1C->getAPIntValue() - 1, DL, VT));
+ if (DAG.isKnownToBeAPowerOfTwo(N1)) {
+ APInt NegOne = APInt::getAllOnesValue(VT.getScalarSizeInBits());
+ SDValue Add =
+ DAG.getNode(ISD::ADD, DL, VT, N1, DAG.getConstant(NegOne, DL, VT));
+ AddToWorklist(Add.getNode());
+ return DAG.getNode(ISD::AND, DL, VT, N0, Add);
----------------
I noticed that you removed the check for opaque constants. Is that intentional?
Repository:
rL LLVM
https://reviews.llvm.org/D27714
More information about the llvm-commits
mailing list