Skip to content

Commit 66cbf25

Browse files
committed
[SelDag] Add isIntOrFPConstant helper function.
This patch adds a new isIntOrFPConstant helper function to check if a SDValue is a integer of FP constant. This pattern is used in various places. There also are places that incorrectly just check for integer constants, e.g. D99384, so hopefully this helper will help people avoid that issue. Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D99428 (cherry-picked from eb3d9f2)
1 parent 960fd47 commit 66cbf25

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

llvm/include/llvm/CodeGen/SelectionDAGNodes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,11 @@ bool isOneOrOneSplat(SDValue V);
16731673
/// Does not permit build vector implicit truncation.
16741674
bool isAllOnesOrAllOnesSplat(SDValue V);
16751675

1676+
/// Return true if \p V is either a integer or FP constant.
1677+
inline bool isIntOrFPConstant(SDValue V) {
1678+
return isa<ConstantSDNode>(V) || isa<ConstantFPSDNode>(V);
1679+
}
1680+
16761681
class GlobalAddressSDNode : public SDNode {
16771682
friend class SelectionDAG;
16781683

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12148,7 +12148,7 @@ SDValue DAGCombiner::visitBITCAST(SDNode *N) {
1214812148
VT.getVectorElementType());
1214912149

1215012150
// If the input is a constant, let getNode fold it.
12151-
if (isa<ConstantSDNode>(N0) || isa<ConstantFPSDNode>(N0)) {
12151+
if (isIntOrFPConstant(N0)) {
1215212152
// If we can't allow illegal operations, we need to check that this is just
1215312153
// a fp -> int or int -> conversion and that the resulting operation will
1215412154
// be legal.
@@ -12386,7 +12386,7 @@ SDValue DAGCombiner::visitFREEZE(SDNode *N) {
1238612386
return N0;
1238712387

1238812388
// If the input is a constant, return it.
12389-
if (isa<ConstantSDNode>(N0) || isa<ConstantFPSDNode>(N0))
12389+
if (isIntOrFPConstant(N0))
1239012390
return N0;
1239112391

1239212392
return SDValue();
@@ -16634,7 +16634,7 @@ void DAGCombiner::getStoreMergeCandidates(
1663416634
case StoreSource::Constant:
1663516635
if (NoTypeMatch)
1663616636
return false;
16637-
if (!(isa<ConstantSDNode>(OtherBC) || isa<ConstantFPSDNode>(OtherBC)))
16637+
if (!isIntOrFPConstant(OtherBC))
1663816638
return false;
1663916639
break;
1664016640
case StoreSource::Extract:
@@ -20219,7 +20219,7 @@ static SDValue combineShuffleOfScalars(ShuffleVectorSDNode *SVN,
2021920219
// generating a splat; semantically, this is fine, but it's likely to
2022020220
// generate low-quality code if the target can't reconstruct an appropriate
2022120221
// shuffle.
20222-
if (!Op.isUndef() && !isa<ConstantSDNode>(Op) && !isa<ConstantFPSDNode>(Op))
20222+
if (!Op.isUndef() && !isIntOrFPConstant(Op))
2022320223
if (!IsSplat && !DuplicateOps.insert(Op).second)
2022420224
return SDValue();
2022520225

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9728,10 +9728,10 @@ SDValue AArch64TargetLowering::LowerBUILD_VECTOR(SDValue Op,
97289728
}
97299729
if (i > 0)
97309730
isOnlyLowElement = false;
9731-
if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V))
9731+
if (!isIntOrFPConstant(V))
97329732
isConstant = false;
97339733

9734-
if (isa<ConstantSDNode>(V) || isa<ConstantFPSDNode>(V)) {
9734+
if (isIntOrFPConstant(V)) {
97359735
++NumConstantLanes;
97369736
if (!ConstantValue.getNode())
97379737
ConstantValue = V;
@@ -9897,7 +9897,7 @@ SDValue AArch64TargetLowering::LowerBUILD_VECTOR(SDValue Op,
98979897
for (unsigned i = 0; i < NumElts; ++i) {
98989898
SDValue V = Op.getOperand(i);
98999899
SDValue LaneIdx = DAG.getConstant(i, dl, MVT::i64);
9900-
if (!isa<ConstantSDNode>(V) && !isa<ConstantFPSDNode>(V))
9900+
if (!isIntOrFPConstant(V))
99019901
// Note that type legalization likely mucked about with the VT of the
99029902
// source operand, so we may have to convert it here before inserting.
99039903
Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, Val, V, LaneIdx);

0 commit comments

Comments
 (0)