Skip to content

Commit 13a383f

Browse files
committed
address comments
1 parent beedad9 commit 13a383f

File tree

3 files changed

+42
-45
lines changed

3 files changed

+42
-45
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11889,6 +11889,47 @@ bool TargetLowering::LegalizeSetCCCondCode(SelectionDAG &DAG, EVT VT,
1188911889
return true;
1189011890
}
1189111891

11892+
// Special case: expand i1 comparisons using logical operations.
11893+
if (OpVT == MVT::i1) {
11894+
SDValue Ret;
11895+
switch (CCCode) {
11896+
default:
11897+
llvm_unreachable("Unknown integer setcc!");
11898+
case ISD::SETEQ: // X == Y --> ~(X ^ Y)
11899+
Ret = DAG.getNOT(dl, DAG.getNode(ISD::XOR, dl, MVT::i1, LHS, RHS),
11900+
MVT::i1);
11901+
break;
11902+
case ISD::SETNE: // X != Y --> (X ^ Y)
11903+
Ret = DAG.getNode(ISD::XOR, dl, MVT::i1, LHS, RHS);
11904+
break;
11905+
case ISD::SETGT: // X >s Y --> X == 0 & Y == 1 --> ~X & Y
11906+
case ISD::SETULT: // X <u Y --> X == 0 & Y == 1 --> ~X & Y
11907+
Ret = DAG.getNode(ISD::AND, dl, MVT::i1, RHS,
11908+
DAG.getNOT(dl, LHS, MVT::i1));
11909+
break;
11910+
case ISD::SETLT: // X <s Y --> X == 1 & Y == 0 --> ~Y & X
11911+
case ISD::SETUGT: // X >u Y --> X == 1 & Y == 0 --> ~Y & X
11912+
Ret = DAG.getNode(ISD::AND, dl, MVT::i1, LHS,
11913+
DAG.getNOT(dl, RHS, MVT::i1));
11914+
break;
11915+
case ISD::SETULE: // X <=u Y --> X == 0 | Y == 1 --> ~X | Y
11916+
case ISD::SETGE: // X >=s Y --> X == 0 | Y == 1 --> ~X | Y
11917+
Ret = DAG.getNode(ISD::OR, dl, MVT::i1, RHS,
11918+
DAG.getNOT(dl, LHS, MVT::i1));
11919+
break;
11920+
case ISD::SETUGE: // X >=u Y --> X == 1 | Y == 0 --> ~Y | X
11921+
case ISD::SETLE: // X <=s Y --> X == 1 | Y == 0 --> ~Y | X
11922+
Ret = DAG.getNode(ISD::OR, dl, MVT::i1, LHS,
11923+
DAG.getNOT(dl, RHS, MVT::i1));
11924+
break;
11925+
}
11926+
11927+
LHS = DAG.getZExtOrTrunc(Ret, dl, VT);
11928+
RHS = SDValue();
11929+
CC = SDValue();
11930+
return true;
11931+
}
11932+
1189211933
ISD::CondCode CC1 = ISD::SETCC_INVALID, CC2 = ISD::SETCC_INVALID;
1189311934
unsigned Opc = 0;
1189411935
switch (CCCode) {

llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ NVPTXTargetLowering::NVPTXTargetLowering(const NVPTXTargetMachine &TM,
670670
setCondCodeAction({ISD::SETNE, ISD::SETEQ, ISD::SETUGE, ISD::SETULE,
671671
ISD::SETUGT, ISD::SETULT, ISD::SETGT, ISD::SETLT,
672672
ISD::SETGE, ISD::SETLE},
673-
MVT::i1, Custom);
673+
MVT::i1, Expand);
674674

675675
// expand extload of vector of integers.
676676
setLoadExtAction({ISD::EXTLOAD, ISD::SEXTLOAD, ISD::ZEXTLOAD}, MVT::v2i16,
@@ -2673,46 +2673,6 @@ SDValue NVPTXTargetLowering::LowerShiftLeftParts(SDValue Op,
26732673
}
26742674
}
26752675

2676-
// Lowers SETCC nodes that aren't directly supported by our arch.
2677-
SDValue NVPTXTargetLowering::LowerSETCC(SDValue Op, SelectionDAG &DAG) const {
2678-
SDValue L = Op->getOperand(0);
2679-
SDValue R = Op->getOperand(1);
2680-
2681-
if (L.getValueType() != MVT::i1)
2682-
return SDValue();
2683-
2684-
SDLoc DL(Op);
2685-
SDValue Ret;
2686-
switch (cast<CondCodeSDNode>(Op->getOperand(2))->get()) {
2687-
default:
2688-
llvm_unreachable("Unknown integer setcc!");
2689-
case ISD::SETEQ: // X == Y -> ~(X^Y)
2690-
Ret = DAG.getNOT(DL, DAG.getNode(ISD::XOR, DL, MVT::i1, L, R), MVT::i1);
2691-
break;
2692-
case ISD::SETNE: // X != Y --> (X^Y)
2693-
Ret = DAG.getNode(ISD::XOR, DL, MVT::i1, L, R);
2694-
break;
2695-
case ISD::SETGT: // X >s Y --> X == 0 & Y == 1 --> ~X & Y
2696-
case ISD::SETULT: // X <u Y --> X == 0 & Y == 1 --> ~X & Y
2697-
Ret = DAG.getNode(ISD::AND, DL, MVT::i1, R, DAG.getNOT(DL, L, MVT::i1));
2698-
break;
2699-
case ISD::SETLT: // X <s Y --> X == 1 & Y == 0 --> ~Y & X
2700-
case ISD::SETUGT: // X >u Y --> X == 1 & Y == 0 --> ~Y & X
2701-
Ret = DAG.getNode(ISD::AND, DL, MVT::i1, L, DAG.getNOT(DL, R, MVT::i1));
2702-
break;
2703-
case ISD::SETULE: // X <=u Y --> X == 0 | Y == 1 --> ~X | Y
2704-
case ISD::SETGE: // X >=s Y --> X == 0 | Y == 1 --> ~X | Y
2705-
Ret = DAG.getNode(ISD::OR, DL, MVT::i1, R, DAG.getNOT(DL, L, MVT::i1));
2706-
break;
2707-
case ISD::SETUGE: // X >=u Y --> X == 1 | Y == 0 --> ~Y | X
2708-
case ISD::SETLE: // X <=s Y --> X == 1 | Y == 0 --> ~Y | X
2709-
Ret = DAG.getNode(ISD::OR, DL, MVT::i1, L, DAG.getNOT(DL, R, MVT::i1));
2710-
break;
2711-
}
2712-
2713-
return DAG.getZExtOrTrunc(Ret, DL, Op.getValueType());
2714-
}
2715-
27162676
/// If the types match, convert the generic copysign to the NVPTXISD version,
27172677
/// otherwise bail ensuring that mismatched cases are properly expaned.
27182678
SDValue NVPTXTargetLowering::LowerFCOPYSIGN(SDValue Op,
@@ -2966,8 +2926,6 @@ NVPTXTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
29662926
return LowerSTORE(Op, DAG);
29672927
case ISD::LOAD:
29682928
return LowerLOAD(Op, DAG);
2969-
case ISD::SETCC:
2970-
return LowerSETCC(Op, DAG);
29712929
case ISD::SHL_PARTS:
29722930
return LowerShiftLeftParts(Op, DAG);
29732931
case ISD::SRA_PARTS:

llvm/lib/Target/NVPTX/NVPTXISelLowering.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,6 @@ class NVPTXTargetLowering : public TargetLowering {
628628
SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
629629
SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
630630

631-
SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
632-
633631
SDValue LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const;
634632

635633
SDValue LowerFROUND(SDValue Op, SelectionDAG &DAG) const;

0 commit comments

Comments
 (0)