[llvm] r298954 - [DAGCombiner] reduce code duplication with local variables; NFCI
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 28 15:45:54 PDT 2017
Author: spatel
Date: Tue Mar 28 17:45:53 2017
New Revision: 298954
URL: http://llvm.org/viewvc/llvm-project?rev=298954&view=rev
Log:
[DAGCombiner] reduce code duplication with local variables; NFCI
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=298954&r1=298953&r2=298954&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Tue Mar 28 17:45:53 2017
@@ -3181,13 +3181,17 @@ SDValue DAGCombiner::foldAndOfSetCCs(SDV
ISD::CondCode CC0 = cast<CondCodeSDNode>(N0CC)->get();
ISD::CondCode CC1 = cast<CondCodeSDNode>(N1CC)->get();
EVT VT = N1.getValueType();
+ assert(VT == N0.getValueType() && "Unexpected operand types for 'and'");
+ EVT LLVT = LL.getValueType();
+ EVT LRVT = LR.getValueType();
+ bool IsInteger = LLVT.isInteger();
- if (LR == RR && CC0 == CC1 && LL.getValueType().isInteger()) {
- EVT CCVT = getSetCCResultType(LR.getValueType());
+ if (LR == RR && CC0 == CC1 && IsInteger) {
+ EVT CCVT = getSetCCResultType(LRVT);
// fold (and (seteq X, 0), (seteq Y, 0)) -> (seteq (or X, Y), 0)
if (isNullConstant(LR) && CC1 == ISD::SETEQ) {
if (VT == CCVT || (!LegalOperations && VT == MVT::i1)) {
- SDValue Or = DAG.getNode(ISD::OR, SDLoc(N0), LR.getValueType(), LL, RL);
+ SDValue Or = DAG.getNode(ISD::OR, SDLoc(N0), LRVT, LL, RL);
AddToWorklist(Or.getNode());
return DAG.getSetCC(DL, VT, Or, LR, CC1);
}
@@ -3196,8 +3200,7 @@ SDValue DAGCombiner::foldAndOfSetCCs(SDV
// fold (and (seteq X, -1), (seteq Y, -1)) -> (seteq (and X, Y), -1)
if (CC1 == ISD::SETEQ) {
if (VT == CCVT || (!LegalOperations && VT == MVT::i1)) {
- SDValue And =
- DAG.getNode(ISD::AND, SDLoc(N0), LR.getValueType(), LL, RL);
+ SDValue And = DAG.getNode(ISD::AND, SDLoc(N0), LRVT, LL, RL);
AddToWorklist(And.getNode());
return DAG.getSetCC(DL, VT, And, LR, CC1);
}
@@ -3205,8 +3208,7 @@ SDValue DAGCombiner::foldAndOfSetCCs(SDV
// fold (and (setgt X, -1), (setgt Y, -1)) -> (setgt (or X, Y), -1)
if (CC1 == ISD::SETGT) {
if (VT == CCVT || (!LegalOperations && VT == MVT::i1)) {
- SDValue Or =
- DAG.getNode(ISD::OR, SDLoc(N0), LR.getValueType(), LL, RL);
+ SDValue Or = DAG.getNode(ISD::OR, SDLoc(N0), LRVT, LL, RL);
AddToWorklist(Or.getNode());
return DAG.getSetCC(DL, VT, Or, LR, CC1);
}
@@ -3215,17 +3217,17 @@ SDValue DAGCombiner::foldAndOfSetCCs(SDV
}
// Simplify (and (setne X, 0), (setne X, -1)) -> (setuge (add X, 1), 2)
- if (LL == RL && CC0 == CC1 && LL.getValueType().isInteger() &&
- CC0 == ISD::SETNE && ((isNullConstant(LR) && isAllOnesConstant(RR)) ||
- (isAllOnesConstant(LR) && isNullConstant(RR)))) {
- EVT CCVT = getSetCCResultType(LL.getValueType());
+ if (LL == RL && CC0 == CC1 && IsInteger && CC0 == ISD::SETNE &&
+ ((isNullConstant(LR) && isAllOnesConstant(RR)) ||
+ (isAllOnesConstant(LR) && isNullConstant(RR)))) {
+ EVT CCVT = getSetCCResultType(LLVT);
if (VT == CCVT || (!LegalOperations && VT == MVT::i1)) {
SDLoc DL0(N0);
- SDValue Add = DAG.getNode(ISD::ADD, DL0, LL.getValueType(), LL,
- DAG.getConstant(1, DL, LL.getValueType()));
+ SDValue Add =
+ DAG.getNode(ISD::ADD, DL0, LLVT, LL, DAG.getConstant(1, DL, LLVT));
AddToWorklist(Add.getNode());
- return DAG.getSetCC(
- DL, VT, Add, DAG.getConstant(2, DL, LL.getValueType()), ISD::SETUGE);
+ return DAG.getSetCC(DL, VT, Add, DAG.getConstant(2, DL, LLVT),
+ ISD::SETUGE);
}
}
@@ -3235,16 +3237,14 @@ SDValue DAGCombiner::foldAndOfSetCCs(SDV
std::swap(RL, RR);
}
if (LL == RL && LR == RR) {
- bool IsInteger = LL.getValueType().isInteger();
ISD::CondCode NewCC = ISD::getSetCCAndOperation(CC0, CC1, IsInteger);
if (NewCC != ISD::SETCC_INVALID &&
(!LegalOperations ||
(TLI.isCondCodeLegal(NewCC, LL.getSimpleValueType()) &&
- TLI.isOperationLegal(ISD::SETCC, LL.getValueType())))) {
- EVT CCVT = getSetCCResultType(LL.getValueType());
- if (N0.getValueType() == CCVT ||
- (!LegalOperations && N0.getValueType() == MVT::i1))
- return DAG.getSetCC(DL, N0.getValueType(), LL, LR, NewCC);
+ TLI.isOperationLegal(ISD::SETCC, LLVT)))) {
+ EVT CCVT = getSetCCResultType(LLVT);
+ if (VT == CCVT || (!LegalOperations && VT == MVT::i1))
+ return DAG.getSetCC(DL, VT, LL, LR, NewCC);
}
}
More information about the llvm-commits
mailing list