[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 06:41:11 PST 2016
andreadb added inline comments.
================
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);
----------------
RKSimon wrote:
> andreadb wrote:
> > I noticed that you removed the check for opaque constants. Is that intentional?
> It made sense to replace the constant-only combine with a generic isPowerOfTwo call (which can detect many runtime cases as well) - no need for opaque constant detection.
Thanks Simon. LGTM.
Repository:
rL LLVM
https://reviews.llvm.org/D27714
More information about the llvm-commits
mailing list