Skip to content

Commit 1341156

Browse files
[CodeGen] Use isAllOnesConstant and isNullConstant (NFC)
1 parent 0baf85c commit 1341156

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5149,16 +5149,11 @@ void DAGTypeLegalizer::IntegerExpandSetCCOperands(SDValue &NewLHS,
51495149
GetExpandedInteger(NewRHS, RHSLo, RHSHi);
51505150

51515151
if (CCCode == ISD::SETEQ || CCCode == ISD::SETNE) {
5152-
if (RHSLo == RHSHi) {
5153-
if (ConstantSDNode *RHSCST = dyn_cast<ConstantSDNode>(RHSLo)) {
5154-
if (RHSCST->isAllOnes()) {
5155-
// Equality comparison to -1.
5156-
NewLHS = DAG.getNode(ISD::AND, dl,
5157-
LHSLo.getValueType(), LHSLo, LHSHi);
5158-
NewRHS = RHSLo;
5159-
return;
5160-
}
5161-
}
5152+
if (RHSLo == RHSHi && isAllOnesConstant(RHSLo)) {
5153+
// Equality comparison to -1.
5154+
NewLHS = DAG.getNode(ISD::AND, dl, LHSLo.getValueType(), LHSLo, LHSHi);
5155+
NewRHS = RHSLo;
5156+
return;
51625157
}
51635158

51645159
NewLHS = DAG.getNode(ISD::XOR, dl, LHSLo.getValueType(), LHSLo, RHSLo);

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,11 +2145,8 @@ SDValue SelectionDAG::getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1,
21452145
if (Splat && UndefElements.none()) {
21462146
// Splat of <x, x, ..., x>, return <x, x, ..., x>, provided that the
21472147
// number of elements match or the value splatted is a zero constant.
2148-
if (SameNumElts)
2148+
if (SameNumElts || isNullConstant(Splat))
21492149
return N1;
2150-
if (auto *C = dyn_cast<ConstantSDNode>(Splat))
2151-
if (C->isZero())
2152-
return N1;
21532150
}
21542151

21552152
// If the shuffle itself creates a splat, build the vector directly.
@@ -8028,8 +8025,6 @@ SDValue SelectionDAG::getMemset(SDValue Chain, const SDLoc &dl, SDValue Dst,
80288025
// FIXME: pass in SDLoc
80298026
CLI.setDebugLoc(dl).setChain(Chain);
80308027

8031-
ConstantSDNode *ConstantSrc = dyn_cast<ConstantSDNode>(Src);
8032-
const bool SrcIsZero = ConstantSrc && ConstantSrc->isZero();
80338028
const char *BzeroName = getTargetLoweringInfo().getLibcallName(RTLIB::BZERO);
80348029

80358030
// Helper function to create an Entry from Node and Type.
@@ -8041,7 +8036,7 @@ SDValue SelectionDAG::getMemset(SDValue Chain, const SDLoc &dl, SDValue Dst,
80418036
};
80428037

80438038
// If zeroing out and bzero is present, use it.
8044-
if (SrcIsZero && BzeroName) {
8039+
if (isNullConstant(Src) && BzeroName) {
80458040
TargetLowering::ArgListTy Args;
80468041
Args.push_back(CreateEntry(Dst, PointerType::getUnqual(Ctx)));
80478042
Args.push_back(CreateEntry(Size, DL.getIntPtrType(Ctx)));

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3900,8 +3900,7 @@ SDValue TargetLowering::foldSetCCWithAnd(EVT VT, SDValue N0, SDValue N1,
39003900

39013901
// Bail out if the compare operand that we want to turn into a zero is
39023902
// already a zero (otherwise, infinite loop).
3903-
auto *YConst = dyn_cast<ConstantSDNode>(Y);
3904-
if (YConst && YConst->isZero())
3903+
if (isNullConstant(Y))
39053904
return SDValue();
39063905

39073906
// Transform this into: ~X & Y == 0.

0 commit comments

Comments
 (0)