diff options
author | Edwin Török <edwintorok@gmail.com> | 2008-04-06 21:23:02 +0000 |
---|---|---|
committer | Edwin Török <edwintorok@gmail.com> | 2008-04-06 21:23:02 +0000 |
commit | 405b243971627c037b7f48a009dfcf5c159ef1a5 (patch) | |
tree | 6a99d39f0d871028fd0ba90ec92df26864c8f9d0 /lib | |
parent | d6da1d0d17e2605363504f044664696f4d85b30f (diff) | |
download | external_llvm-405b243971627c037b7f48a009dfcf5c159ef1a5.zip external_llvm-405b243971627c037b7f48a009dfcf5c159ef1a5.tar.gz external_llvm-405b243971627c037b7f48a009dfcf5c159ef1a5.tar.bz2 |
Prefer to expand mask for xor to -1, so we have a chance to turn it into a not.
If it cannot be expanded, it will keep the old behaviour and try to shrink the constant.
Part of enhancement for PR2191.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49280 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/SelectionDAG/TargetLowering.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 0fcb3c8..a0894dd 100644 --- a/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -657,10 +657,25 @@ bool TargetLowering::SimplifyDemandedBits(SDOperand Op, } // If the RHS is a constant, see if we can simplify it. - // FIXME: for XOR, we prefer to force bits to 1 if they will make a -1. - if (TLO.ShrinkDemandedConstant(Op, NewMask)) - return true; - + // for XOR, we prefer to force bits to 1 if they will make a -1. + // if we can't force bits, try to shrink constant + if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { + APInt Expanded = C->getAPIntValue() | (~NewMask); + // if we can expand it to have all bits set, do it + if (Expanded.isAllOnesValue()) { + if (Expanded != C->getAPIntValue()) { + MVT::ValueType VT = Op.getValueType(); + SDOperand New = TLO.DAG.getNode(Op.getOpcode(), VT, Op.getOperand(0), + TLO.DAG.getConstant(Expanded, VT)); + return TLO.CombineTo(Op, New); + } + // if it already has all the bits set, nothing to change + // but don't shrink either! + } else if (TLO.ShrinkDemandedConstant(Op, NewMask)) { + return true; + } + } + KnownZero = KnownZeroOut; KnownOne = KnownOneOut; break; |