[llvm] 1341156 - [CodeGen] Use isAllOnesConstant and isNullConstant (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 20 22:56:46 PDT 2023
Author: Kazu Hirata
Date: 2023-08-20T22:56:40-07:00
New Revision: 134115618ad9a1b61f7f850ea5dde4b62de8f692
URL: https://github.com/llvm/llvm-project/commit/134115618ad9a1b61f7f850ea5dde4b62de8f692
DIFF: https://github.com/llvm/llvm-project/commit/134115618ad9a1b61f7f850ea5dde4b62de8f692.diff
LOG: [CodeGen] Use isAllOnesConstant and isNullConstant (NFC)
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
index 7013d4e53b1083..dc59daf5f2189a 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -5149,16 +5149,11 @@ void DAGTypeLegalizer::IntegerExpandSetCCOperands(SDValue &NewLHS,
GetExpandedInteger(NewRHS, RHSLo, RHSHi);
if (CCCode == ISD::SETEQ || CCCode == ISD::SETNE) {
- if (RHSLo == RHSHi) {
- if (ConstantSDNode *RHSCST = dyn_cast<ConstantSDNode>(RHSLo)) {
- if (RHSCST->isAllOnes()) {
- // Equality comparison to -1.
- NewLHS = DAG.getNode(ISD::AND, dl,
- LHSLo.getValueType(), LHSLo, LHSHi);
- NewRHS = RHSLo;
- return;
- }
- }
+ if (RHSLo == RHSHi && isAllOnesConstant(RHSLo)) {
+ // Equality comparison to -1.
+ NewLHS = DAG.getNode(ISD::AND, dl, LHSLo.getValueType(), LHSLo, LHSHi);
+ NewRHS = RHSLo;
+ return;
}
NewLHS = DAG.getNode(ISD::XOR, dl, LHSLo.getValueType(), LHSLo, RHSLo);
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 87be33b2da77ec..b466d72c4e97db 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -2145,11 +2145,8 @@ SDValue SelectionDAG::getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1,
if (Splat && UndefElements.none()) {
// Splat of <x, x, ..., x>, return <x, x, ..., x>, provided that the
// number of elements match or the value splatted is a zero constant.
- if (SameNumElts)
+ if (SameNumElts || isNullConstant(Splat))
return N1;
- if (auto *C = dyn_cast<ConstantSDNode>(Splat))
- if (C->isZero())
- return N1;
}
// 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,
// FIXME: pass in SDLoc
CLI.setDebugLoc(dl).setChain(Chain);
- ConstantSDNode *ConstantSrc = dyn_cast<ConstantSDNode>(Src);
- const bool SrcIsZero = ConstantSrc && ConstantSrc->isZero();
const char *BzeroName = getTargetLoweringInfo().getLibcallName(RTLIB::BZERO);
// Helper function to create an Entry from Node and Type.
@@ -8041,7 +8036,7 @@ SDValue SelectionDAG::getMemset(SDValue Chain, const SDLoc &dl, SDValue Dst,
};
// If zeroing out and bzero is present, use it.
- if (SrcIsZero && BzeroName) {
+ if (isNullConstant(Src) && BzeroName) {
TargetLowering::ArgListTy Args;
Args.push_back(CreateEntry(Dst, PointerType::getUnqual(Ctx)));
Args.push_back(CreateEntry(Size, DL.getIntPtrType(Ctx)));
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index fa07dba142f8c6..31b1b39b34e575 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -3900,8 +3900,7 @@ SDValue TargetLowering::foldSetCCWithAnd(EVT VT, SDValue N0, SDValue N1,
// Bail out if the compare operand that we want to turn into a zero is
// already a zero (otherwise, infinite loop).
- auto *YConst = dyn_cast<ConstantSDNode>(Y);
- if (YConst && YConst->isZero())
+ if (isNullConstant(Y))
return SDValue();
// Transform this into: ~X & Y == 0.
More information about the llvm-commits
mailing list