mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +01:00
[DAGCombiner] use local variable to shorten code; NFCI
llvm-svn: 307429
This commit is contained in:
parent
2d20120a2d
commit
1d94b62277
@ -6118,19 +6118,22 @@ SDValue DAGCombiner::visitSELECT(SDNode *N) {
|
|||||||
SDValue N2 = N->getOperand(2);
|
SDValue N2 = N->getOperand(2);
|
||||||
EVT VT = N->getValueType(0);
|
EVT VT = N->getValueType(0);
|
||||||
EVT VT0 = N0.getValueType();
|
EVT VT0 = N0.getValueType();
|
||||||
|
SDLoc DL(N);
|
||||||
|
|
||||||
// fold (select C, X, X) -> X
|
// fold (select C, X, X) -> X
|
||||||
if (N1 == N2)
|
if (N1 == N2)
|
||||||
return N1;
|
return N1;
|
||||||
|
|
||||||
if (const ConstantSDNode *N0C = dyn_cast<const ConstantSDNode>(N0)) {
|
if (const ConstantSDNode *N0C = dyn_cast<const ConstantSDNode>(N0)) {
|
||||||
// fold (select true, X, Y) -> X
|
// fold (select true, X, Y) -> X
|
||||||
// fold (select false, X, Y) -> Y
|
// fold (select false, X, Y) -> Y
|
||||||
return !N0C->isNullValue() ? N1 : N2;
|
return !N0C->isNullValue() ? N1 : N2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fold (select X, X, Y) -> (or X, Y)
|
// fold (select X, X, Y) -> (or X, Y)
|
||||||
// fold (select X, 1, Y) -> (or C, Y)
|
// fold (select X, 1, Y) -> (or C, Y)
|
||||||
if (VT == VT0 && VT == MVT::i1 && (N0 == N1 || isOneConstant(N1)))
|
if (VT == VT0 && VT == MVT::i1 && (N0 == N1 || isOneConstant(N1)))
|
||||||
return DAG.getNode(ISD::OR, SDLoc(N), VT, N0, N2);
|
return DAG.getNode(ISD::OR, DL, VT, N0, N2);
|
||||||
|
|
||||||
if (SDValue V = foldSelectOfConstants(N))
|
if (SDValue V = foldSelectOfConstants(N))
|
||||||
return V;
|
return V;
|
||||||
@ -6139,22 +6142,22 @@ SDValue DAGCombiner::visitSELECT(SDNode *N) {
|
|||||||
if (VT == VT0 && VT == MVT::i1 && isNullConstant(N1)) {
|
if (VT == VT0 && VT == MVT::i1 && isNullConstant(N1)) {
|
||||||
SDValue NOTNode = DAG.getNOT(SDLoc(N0), N0, VT);
|
SDValue NOTNode = DAG.getNOT(SDLoc(N0), N0, VT);
|
||||||
AddToWorklist(NOTNode.getNode());
|
AddToWorklist(NOTNode.getNode());
|
||||||
return DAG.getNode(ISD::AND, SDLoc(N), VT, NOTNode, N2);
|
return DAG.getNode(ISD::AND, DL, VT, NOTNode, N2);
|
||||||
}
|
}
|
||||||
// fold (select C, X, 1) -> (or (not C), X)
|
// fold (select C, X, 1) -> (or (not C), X)
|
||||||
if (VT == VT0 && VT == MVT::i1 && isOneConstant(N2)) {
|
if (VT == VT0 && VT == MVT::i1 && isOneConstant(N2)) {
|
||||||
SDValue NOTNode = DAG.getNOT(SDLoc(N0), N0, VT);
|
SDValue NOTNode = DAG.getNOT(SDLoc(N0), N0, VT);
|
||||||
AddToWorklist(NOTNode.getNode());
|
AddToWorklist(NOTNode.getNode());
|
||||||
return DAG.getNode(ISD::OR, SDLoc(N), VT, NOTNode, N1);
|
return DAG.getNode(ISD::OR, DL, VT, NOTNode, N1);
|
||||||
}
|
}
|
||||||
// fold (select X, Y, X) -> (and X, Y)
|
// fold (select X, Y, X) -> (and X, Y)
|
||||||
// fold (select X, Y, 0) -> (and X, Y)
|
// fold (select X, Y, 0) -> (and X, Y)
|
||||||
if (VT == VT0 && VT == MVT::i1 && (N0 == N2 || isNullConstant(N2)))
|
if (VT == VT0 && VT == MVT::i1 && (N0 == N2 || isNullConstant(N2)))
|
||||||
return DAG.getNode(ISD::AND, SDLoc(N), VT, N0, N1);
|
return DAG.getNode(ISD::AND, DL, VT, N0, N1);
|
||||||
|
|
||||||
// If we can fold this based on the true/false value, do so.
|
// If we can fold this based on the true/false value, do so.
|
||||||
if (SimplifySelectOps(N, N1, N2))
|
if (SimplifySelectOps(N, N1, N2))
|
||||||
return SDValue(N, 0); // Don't revisit N.
|
return SDValue(N, 0); // Don't revisit N.
|
||||||
|
|
||||||
if (VT0 == MVT::i1) {
|
if (VT0 == MVT::i1) {
|
||||||
// The code in this block deals with the following 2 equivalences:
|
// The code in this block deals with the following 2 equivalences:
|
||||||
@ -6165,27 +6168,27 @@ SDValue DAGCombiner::visitSELECT(SDNode *N) {
|
|||||||
// to the right anyway if we find the inner select exists in the DAG anyway
|
// to the right anyway if we find the inner select exists in the DAG anyway
|
||||||
// and we always transform to the left side if we know that we can further
|
// and we always transform to the left side if we know that we can further
|
||||||
// optimize the combination of the conditions.
|
// optimize the combination of the conditions.
|
||||||
bool normalizeToSequence
|
bool normalizeToSequence =
|
||||||
= TLI.shouldNormalizeToSelectSequence(*DAG.getContext(), VT);
|
TLI.shouldNormalizeToSelectSequence(*DAG.getContext(), VT);
|
||||||
// select (and Cond0, Cond1), X, Y
|
// select (and Cond0, Cond1), X, Y
|
||||||
// -> select Cond0, (select Cond1, X, Y), Y
|
// -> select Cond0, (select Cond1, X, Y), Y
|
||||||
if (N0->getOpcode() == ISD::AND && N0->hasOneUse()) {
|
if (N0->getOpcode() == ISD::AND && N0->hasOneUse()) {
|
||||||
SDValue Cond0 = N0->getOperand(0);
|
SDValue Cond0 = N0->getOperand(0);
|
||||||
SDValue Cond1 = N0->getOperand(1);
|
SDValue Cond1 = N0->getOperand(1);
|
||||||
SDValue InnerSelect = DAG.getNode(ISD::SELECT, SDLoc(N),
|
SDValue InnerSelect =
|
||||||
N1.getValueType(), Cond1, N1, N2);
|
DAG.getNode(ISD::SELECT, DL, N1.getValueType(), Cond1, N1, N2);
|
||||||
if (normalizeToSequence || !InnerSelect.use_empty())
|
if (normalizeToSequence || !InnerSelect.use_empty())
|
||||||
return DAG.getNode(ISD::SELECT, SDLoc(N), N1.getValueType(), Cond0,
|
return DAG.getNode(ISD::SELECT, DL, N1.getValueType(), Cond0,
|
||||||
InnerSelect, N2);
|
InnerSelect, N2);
|
||||||
}
|
}
|
||||||
// select (or Cond0, Cond1), X, Y -> select Cond0, X, (select Cond1, X, Y)
|
// select (or Cond0, Cond1), X, Y -> select Cond0, X, (select Cond1, X, Y)
|
||||||
if (N0->getOpcode() == ISD::OR && N0->hasOneUse()) {
|
if (N0->getOpcode() == ISD::OR && N0->hasOneUse()) {
|
||||||
SDValue Cond0 = N0->getOperand(0);
|
SDValue Cond0 = N0->getOperand(0);
|
||||||
SDValue Cond1 = N0->getOperand(1);
|
SDValue Cond1 = N0->getOperand(1);
|
||||||
SDValue InnerSelect = DAG.getNode(ISD::SELECT, SDLoc(N),
|
SDValue InnerSelect =
|
||||||
N1.getValueType(), Cond1, N1, N2);
|
DAG.getNode(ISD::SELECT, DL, N1.getValueType(), Cond1, N1, N2);
|
||||||
if (normalizeToSequence || !InnerSelect.use_empty())
|
if (normalizeToSequence || !InnerSelect.use_empty())
|
||||||
return DAG.getNode(ISD::SELECT, SDLoc(N), N1.getValueType(), Cond0, N1,
|
return DAG.getNode(ISD::SELECT, DL, N1.getValueType(), Cond0, N1,
|
||||||
InnerSelect);
|
InnerSelect);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6197,15 +6200,13 @@ SDValue DAGCombiner::visitSELECT(SDNode *N) {
|
|||||||
if (N1_2 == N2 && N0.getValueType() == N1_0.getValueType()) {
|
if (N1_2 == N2 && N0.getValueType() == N1_0.getValueType()) {
|
||||||
// Create the actual and node if we can generate good code for it.
|
// Create the actual and node if we can generate good code for it.
|
||||||
if (!normalizeToSequence) {
|
if (!normalizeToSequence) {
|
||||||
SDValue And = DAG.getNode(ISD::AND, SDLoc(N), N0.getValueType(),
|
SDValue And = DAG.getNode(ISD::AND, DL, N0.getValueType(), N0, N1_0);
|
||||||
N0, N1_0);
|
return DAG.getNode(ISD::SELECT, DL, N1.getValueType(), And, N1_1, N2);
|
||||||
return DAG.getNode(ISD::SELECT, SDLoc(N), N1.getValueType(), And,
|
|
||||||
N1_1, N2);
|
|
||||||
}
|
}
|
||||||
// Otherwise see if we can optimize the "and" to a better pattern.
|
// Otherwise see if we can optimize the "and" to a better pattern.
|
||||||
if (SDValue Combined = visitANDLike(N0, N1_0, N))
|
if (SDValue Combined = visitANDLike(N0, N1_0, N))
|
||||||
return DAG.getNode(ISD::SELECT, SDLoc(N), N1.getValueType(), Combined,
|
return DAG.getNode(ISD::SELECT, DL, N1.getValueType(), Combined, N1_1,
|
||||||
N1_1, N2);
|
N2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// select Cond0, X, (select Cond1, X, Y) -> select (or Cond0, Cond1), X, Y
|
// select Cond0, X, (select Cond1, X, Y) -> select (or Cond0, Cond1), X, Y
|
||||||
@ -6216,15 +6217,13 @@ SDValue DAGCombiner::visitSELECT(SDNode *N) {
|
|||||||
if (N2_1 == N1 && N0.getValueType() == N2_0.getValueType()) {
|
if (N2_1 == N1 && N0.getValueType() == N2_0.getValueType()) {
|
||||||
// Create the actual or node if we can generate good code for it.
|
// Create the actual or node if we can generate good code for it.
|
||||||
if (!normalizeToSequence) {
|
if (!normalizeToSequence) {
|
||||||
SDValue Or = DAG.getNode(ISD::OR, SDLoc(N), N0.getValueType(),
|
SDValue Or = DAG.getNode(ISD::OR, DL, N0.getValueType(), N0, N2_0);
|
||||||
N0, N2_0);
|
return DAG.getNode(ISD::SELECT, DL, N1.getValueType(), Or, N1, N2_2);
|
||||||
return DAG.getNode(ISD::SELECT, SDLoc(N), N1.getValueType(), Or,
|
|
||||||
N1, N2_2);
|
|
||||||
}
|
}
|
||||||
// Otherwise see if we can optimize to a better pattern.
|
// Otherwise see if we can optimize to a better pattern.
|
||||||
if (SDValue Combined = visitORLike(N0, N2_0, N))
|
if (SDValue Combined = visitORLike(N0, N2_0, N))
|
||||||
return DAG.getNode(ISD::SELECT, SDLoc(N), N1.getValueType(), Combined,
|
return DAG.getNode(ISD::SELECT, DL, N1.getValueType(), Combined, N1,
|
||||||
N1, N2_2);
|
N2_2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6235,8 +6234,7 @@ SDValue DAGCombiner::visitSELECT(SDNode *N) {
|
|||||||
if (auto *C = dyn_cast<ConstantSDNode>(N0->getOperand(1))) {
|
if (auto *C = dyn_cast<ConstantSDNode>(N0->getOperand(1))) {
|
||||||
SDValue Cond0 = N0->getOperand(0);
|
SDValue Cond0 = N0->getOperand(0);
|
||||||
if (C->isOne())
|
if (C->isOne())
|
||||||
return DAG.getNode(ISD::SELECT, SDLoc(N), N1.getValueType(),
|
return DAG.getNode(ISD::SELECT, DL, N1.getValueType(), Cond0, N2, N1);
|
||||||
Cond0, N2, N1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6253,24 +6251,21 @@ SDValue DAGCombiner::visitSELECT(SDNode *N) {
|
|||||||
// FIXME: Instead of testing for UnsafeFPMath, this should be checking for
|
// FIXME: Instead of testing for UnsafeFPMath, this should be checking for
|
||||||
// no signed zeros as well as no nans.
|
// no signed zeros as well as no nans.
|
||||||
const TargetOptions &Options = DAG.getTarget().Options;
|
const TargetOptions &Options = DAG.getTarget().Options;
|
||||||
if (Options.UnsafeFPMath &&
|
if (Options.UnsafeFPMath && VT.isFloatingPoint() && N0.hasOneUse() &&
|
||||||
VT.isFloatingPoint() && N0.hasOneUse() &&
|
|
||||||
DAG.isKnownNeverNaN(N1) && DAG.isKnownNeverNaN(N2)) {
|
DAG.isKnownNeverNaN(N1) && DAG.isKnownNeverNaN(N2)) {
|
||||||
ISD::CondCode CC = cast<CondCodeSDNode>(N0.getOperand(2))->get();
|
ISD::CondCode CC = cast<CondCodeSDNode>(N0.getOperand(2))->get();
|
||||||
|
|
||||||
if (SDValue FMinMax = combineMinNumMaxNum(SDLoc(N), VT, N0.getOperand(0),
|
if (SDValue FMinMax = combineMinNumMaxNum(
|
||||||
N0.getOperand(1), N1, N2, CC,
|
DL, VT, N0.getOperand(0), N0.getOperand(1), N1, N2, CC, TLI, DAG))
|
||||||
TLI, DAG))
|
|
||||||
return FMinMax;
|
return FMinMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!LegalOperations &&
|
if ((!LegalOperations &&
|
||||||
TLI.isOperationLegalOrCustom(ISD::SELECT_CC, VT)) ||
|
TLI.isOperationLegalOrCustom(ISD::SELECT_CC, VT)) ||
|
||||||
TLI.isOperationLegal(ISD::SELECT_CC, VT))
|
TLI.isOperationLegal(ISD::SELECT_CC, VT))
|
||||||
return DAG.getNode(ISD::SELECT_CC, SDLoc(N), VT,
|
return DAG.getNode(ISD::SELECT_CC, DL, VT, N0.getOperand(0),
|
||||||
N0.getOperand(0), N0.getOperand(1),
|
N0.getOperand(1), N1, N2, N0.getOperand(2));
|
||||||
N1, N2, N0.getOperand(2));
|
return SimplifySelect(DL, N0, N1, N2);
|
||||||
return SimplifySelect(SDLoc(N), N0, N1, N2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SDValue();
|
return SDValue();
|
||||||
|
Loading…
Reference in New Issue
Block a user