diff options
author | Torok Edwin <edwintorok@gmail.com> | 2008-04-06 21:23:02 +0000 |
---|---|---|
committer | Torok Edwin <edwintorok@gmail.com> | 2008-04-06 21:23:02 +0000 |
commit | 4fea2e982d79132715711dfcfdc46abf15239217 (patch) | |
tree | 6a99d39f0d871028fd0ba90ec92df26864c8f9d0 /lib/CodeGen/SelectionDAG/TargetLowering.cpp | |
parent | 051a950000e21935165db56695e35bade668193b (diff) |
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/CodeGen/SelectionDAG/TargetLowering.cpp')
-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 0fcb3c81d7..a0894ddebc 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; |