Skip to content

Commit a181b42

Browse files
committed
[llvm][NFC] Use SDValue::getConstantOperandAPInt(i) where possible
The helper function allows examples like `cast<ConstantSDNode>(Op.getOperand(0))->getAPIntValue();` to be changed to `Op.getConstantOperandAPInt(0);`. See #76708 for further context. Although there are far fewer opportunities for replacement, I used a similar git grep and sed combo as before, given I already had it to hand: `git grep -l "cast<ConstantSDNode>\(.*->getOperand\(.*\)\)->getAPIntValue\(\)" | xargs sed -E -i 's/cast<ConstantSDNode>\((.*)->getOperand\((.*)\)\)->getAPIntValue\(\)/\1->getConstantOperandAPInt(\2)/'` and `git grep -l "cast<ConstantSDNode>\(.*\.getOperand\(.*\)\)->getAPIntValue\(\)" | xargs sed -E -i 's/cast<ConstantSDNode>\((.*)\.getOperand\((.*)\)\)->getAPIntValue\(\)/\1.getConstantOperandAPInt(\2)/'`
1 parent 3356575 commit a181b42

File tree

7 files changed

+9
-9
lines changed

7 files changed

+9
-9
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5470,7 +5470,7 @@ static SDValue FoldBUILD_VECTOR(const SDLoc &DL, EVT VT,
54705470
Ops[i].getOperand(0).getValueType() != VT ||
54715471
(IdentitySrc && Ops[i].getOperand(0) != IdentitySrc) ||
54725472
!isa<ConstantSDNode>(Ops[i].getOperand(1)) ||
5473-
cast<ConstantSDNode>(Ops[i].getOperand(1))->getAPIntValue() != i) {
5473+
Ops[i].getConstantOperandAPInt(1) != i) {
54745474
IsIdentity = false;
54755475
break;
54765476
}

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14245,7 +14245,7 @@ SDValue AArch64TargetLowering::LowerVSCALE(SDValue Op,
1424514245
assert(VT != MVT::i64 && "Expected illegal VSCALE node");
1424614246

1424714247
SDLoc DL(Op);
14248-
APInt MulImm = cast<ConstantSDNode>(Op.getOperand(0))->getAPIntValue();
14248+
APInt MulImm = Op.getConstantOperandAPInt(0);
1424914249
return DAG.getZExtOrTrunc(DAG.getVScale(DL, MVT::i64, MulImm.sext(64)), DL,
1425014250
VT);
1425114251
}
@@ -18341,7 +18341,7 @@ static bool isEssentiallyExtractHighSubvector(SDValue N) {
1834118341
return false;
1834218342
if (N.getOperand(0).getValueType().isScalableVector())
1834318343
return false;
18344-
return cast<ConstantSDNode>(N.getOperand(1))->getAPIntValue() ==
18344+
return N.getConstantOperandAPInt(1) ==
1834518345
N.getOperand(0).getValueType().getVectorNumElements() / 2;
1834618346
}
1834718347

llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ bool AMDGPUDAGToDAGISel::isUnneededShiftMask(const SDNode *N,
724724
unsigned ShAmtBits) const {
725725
assert(N->getOpcode() == ISD::AND);
726726

727-
const APInt &RHS = cast<ConstantSDNode>(N->getOperand(1))->getAPIntValue();
727+
const APInt &RHS = N->getConstantOperandAPInt(1);
728728
if (RHS.countr_one() >= ShAmtBits)
729729
return true;
730730

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14841,14 +14841,14 @@ static SDValue ParseBFI(SDNode *N, APInt &ToMask, APInt &FromMask) {
1484114841
assert(N->getOpcode() == ARMISD::BFI);
1484214842

1484314843
SDValue From = N->getOperand(1);
14844-
ToMask = ~cast<ConstantSDNode>(N->getOperand(2))->getAPIntValue();
14844+
ToMask = ~N->getConstantOperandAPInt(2);
1484514845
FromMask = APInt::getLowBitsSet(ToMask.getBitWidth(), ToMask.popcount());
1484614846

1484714847
// If the Base came from a SHR #C, we can deduce that it is really testing bit
1484814848
// #C in the base of the SHR.
1484914849
if (From->getOpcode() == ISD::SRL &&
1485014850
isa<ConstantSDNode>(From->getOperand(1))) {
14851-
APInt Shift = cast<ConstantSDNode>(From->getOperand(1))->getAPIntValue();
14851+
APInt Shift = From->getConstantOperandAPInt(1);
1485214852
assert(Shift.getLimitedValue() < 32 && "Shift too large!");
1485314853
FromMask <<= Shift.getLimitedValue(31);
1485414854
From = From->getOperand(0);

llvm/lib/Target/Mips/MipsISelDAGToDAG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ bool MipsDAGToDAGISel::isUnneededShiftMask(SDNode *N,
330330
unsigned ShAmtBits) const {
331331
assert(N->getOpcode() == ISD::AND && "Unexpected opcode");
332332

333-
const APInt &RHS = cast<ConstantSDNode>(N->getOperand(1))->getAPIntValue();
333+
const APInt &RHS = N->getConstantOperandAPInt(1);
334334
if (RHS.countr_one() >= ShAmtBits) {
335335
LLVM_DEBUG(
336336
dbgs()

llvm/lib/Target/Mips/MipsSEISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ static SDValue lowerMSABitClearImm(SDValue Op, SelectionDAG &DAG) {
15191519
SDLoc DL(Op);
15201520
EVT ResTy = Op->getValueType(0);
15211521
APInt BitImm = APInt(ResTy.getScalarSizeInBits(), 1)
1522-
<< cast<ConstantSDNode>(Op->getOperand(2))->getAPIntValue();
1522+
<< Op->getConstantOperandAPInt(2);
15231523
SDValue BitMask = DAG.getConstant(~BitImm, DL, ResTy);
15241524

15251525
return DAG.getNode(ISD::AND, DL, ResTy, Op->getOperand(1), BitMask);

llvm/lib/Target/X86/X86ISelDAGToDAG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ namespace {
487487
// from PatFrags in tablegen.
488488
bool isUnneededShiftMask(SDNode *N, unsigned Width) const {
489489
assert(N->getOpcode() == ISD::AND && "Unexpected opcode");
490-
const APInt &Val = cast<ConstantSDNode>(N->getOperand(1))->getAPIntValue();
490+
const APInt &Val = N->getConstantOperandAPInt(1);
491491

492492
if (Val.countr_one() >= Width)
493493
return true;

0 commit comments

Comments
 (0)