From: Andrew Lenharth Date: Sun, 2 Apr 2006 21:42:45 +0000 (+0000) Subject: This should be a win of every arch X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=50a0d426e85b4e27766a99279d2e61f622525f94;p=oota-llvm.git This should be a win of every arch git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27364 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index f0003f0d6cd..6bb4ea23a52 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -818,7 +818,32 @@ SDOperand DAGCombiner::visitMUL(SDNode *N) { DAG.getConstant(Log2_64(-N1C->getSignExtended()), TLI.getShiftAmountTy()))); } - + + //These two might be better as: + // mul x, ((1 << c) + cn) -> (x << c) + (x * cn) + // where TargetInfo tells us cn is a cheap constant to multiply by + + // fold (mul x, (1 << c) + 1) -> (x << c) + x + //FIXME: there should be a target hint to allow other constants based on + // expense of mul + if (N1C && isPowerOf2_64(N1C->getSignExtended() - 1)) { + return DAG.getNode(ISD::ADD, VT, + DAG.getNode(ISD::SHL, VT, N0, + DAG.getConstant(Log2_64(N1C->getSignExtended() - 1), + TLI.getShiftAmountTy())), + N0); + } + // fold (mul x, (1 << c) - 1) -> (x << c) - x + //FIXME: there should be a target hint to allow other constants based on + // the expense of mul + if (N1C && isPowerOf2_64(N1C->getSignExtended() + 1)) { + return DAG.getNode(ISD::SUB, VT, + DAG.getNode(ISD::SHL, VT, N0, + DAG.getConstant(Log2_64(N1C->getSignExtended() + 1), + TLI.getShiftAmountTy())), + N0); + } + // (mul (shl X, c1), c2) -> (mul X, c2 << c1) if (N1C && N0.getOpcode() == ISD::SHL && isa(N0.getOperand(1))) {