summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2016-10-07 21:55:42 +0000
committerSanjay Patel <spatel@rotateright.com>2016-10-07 21:55:42 +0000
commit14c02052d6552bfa6109929001b1e39761e18996 (patch)
tree1e49338bc157102051a6a7507025f444aabe0667 /llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
parentf6988d2980c505519abff2b1464f20f26478eceb (diff)
downloadbcm5719-llvm-14c02052d6552bfa6109929001b1e39761e18996.tar.gz
bcm5719-llvm-14c02052d6552bfa6109929001b1e39761e18996.zip
[DAG] clean up foldSelectOfConstants(); NFCI
Rename variables, simplify logic. Not clear yet why we don't handle a target with ZeroOrNegativeOneBooleanContent too. llvm-svn: 283613
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp33
1 files changed, 14 insertions, 19 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 3f62f0af9e1..1f298427499 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -5108,13 +5108,14 @@ static SDValue combineMinNumMaxNum(const SDLoc &DL, EVT VT, SDValue LHS,
// TODO: We should handle other cases of selecting between {-1,0,1} here.
SDValue DAGCombiner::foldSelectOfConstants(SDNode *N) {
- SDValue N0 = N->getOperand(0);
+ SDValue Cond = N->getOperand(0);
SDValue N1 = N->getOperand(1);
SDValue N2 = N->getOperand(2);
EVT VT = N->getValueType(0);
- EVT VT0 = N0.getValueType();
+ EVT CondVT = Cond.getValueType();
+ SDLoc DL(N);
- // fold (select C, 0, 1) -> (xor C, 1)
+ // fold (select Cond, 0, 1) -> (xor Cond, 1)
// We can't do this reliably if integer based booleans have different contents
// to floating point based booleans. This is because we can't tell whether we
// have an integer-based boolean or a floating-point-based boolean unless we
@@ -5124,23 +5125,17 @@ SDValue DAGCombiner::foldSelectOfConstants(SDNode *N) {
// in another basic block or it could require searching a complicated
// expression.
if (VT.isInteger() &&
- (VT0 == MVT::i1 || (VT0.isInteger() &&
- TLI.getBooleanContents(false, false) ==
- TLI.getBooleanContents(false, true) &&
- TLI.getBooleanContents(false, false) ==
- TargetLowering::ZeroOrOneBooleanContent)) &&
+ (CondVT == MVT::i1 || (CondVT.isInteger() &&
+ TLI.getBooleanContents(false, true) ==
+ TargetLowering::ZeroOrOneBooleanContent &&
+ TLI.getBooleanContents(false, false) ==
+ TargetLowering::ZeroOrOneBooleanContent)) &&
isNullConstant(N1) && isOneConstant(N2)) {
- SDValue XORNode;
- if (VT == VT0) {
- SDLoc DL(N);
- return DAG.getNode(ISD::XOR, DL, VT0, N0, DAG.getConstant(1, DL, VT0));
- }
- SDLoc DL0(N0);
- XORNode = DAG.getNode(ISD::XOR, DL0, VT0, N0, DAG.getConstant(1, DL0, VT0));
- AddToWorklist(XORNode.getNode());
- if (VT.bitsGT(VT0))
- return DAG.getNode(ISD::ZERO_EXTEND, SDLoc(N), VT, XORNode);
- return DAG.getNode(ISD::TRUNCATE, SDLoc(N), VT, XORNode);
+ SDValue NotCond = DAG.getNode(ISD::XOR, DL, CondVT, Cond,
+ DAG.getConstant(1, DL, CondVT));
+ if (VT.bitsEq(CondVT))
+ return NotCond;
+ return DAG.getZExtOrTrunc(NotCond, DL, VT);
}
return SDValue();
OpenPOWER on IntegriCloud