Skip to content

Commit dad6487

Browse files
[llvm] Remove an extraneous cast (NFC) (#144955)
llvm::CallBase::getArgOperand returns Value *, so we do not need const_cast<Value *>.
1 parent d8e6d74 commit dad6487

File tree

3 files changed

+29
-43
lines changed

3 files changed

+29
-43
lines changed

llvm/include/llvm/IR/IntrinsicInst.h

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,8 @@ class MinMaxIntrinsic : public IntrinsicInst {
779779
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
780780
}
781781

782-
Value *getLHS() const { return const_cast<Value *>(getArgOperand(0)); }
783-
Value *getRHS() const { return const_cast<Value *>(getArgOperand(1)); }
782+
Value *getLHS() const { return getArgOperand(0); }
783+
Value *getRHS() const { return getArgOperand(1); }
784784

785785
/// Returns the comparison predicate underlying the intrinsic.
786786
static ICmpInst::Predicate getPredicate(Intrinsic::ID ID) {
@@ -868,8 +868,8 @@ class CmpIntrinsic : public IntrinsicInst {
868868
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
869869
}
870870

871-
Value *getLHS() const { return const_cast<Value *>(getArgOperand(0)); }
872-
Value *getRHS() const { return const_cast<Value *>(getArgOperand(1)); }
871+
Value *getLHS() const { return getArgOperand(0); }
872+
Value *getRHS() const { return getArgOperand(1); }
873873

874874
static bool isSigned(Intrinsic::ID ID) { return ID == Intrinsic::scmp; }
875875
bool isSigned() const { return isSigned(getIntrinsicID()); }
@@ -914,8 +914,8 @@ class BinaryOpIntrinsic : public IntrinsicInst {
914914
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
915915
}
916916

917-
Value *getLHS() const { return const_cast<Value *>(getArgOperand(0)); }
918-
Value *getRHS() const { return const_cast<Value *>(getArgOperand(1)); }
917+
Value *getLHS() const { return getArgOperand(0); }
918+
Value *getRHS() const { return getArgOperand(1); }
919919

920920
/// Returns the binary operation underlying the intrinsic.
921921
LLVM_ABI Instruction::BinaryOps getBinaryOp() const;
@@ -1118,7 +1118,7 @@ class MemIntrinsic : public MemIntrinsicBase<MemIntrinsic> {
11181118

11191119
public:
11201120
ConstantInt *getVolatileCst() const {
1121-
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(ARG_VOLATILE)));
1121+
return cast<ConstantInt>(getArgOperand(ARG_VOLATILE));
11221122
}
11231123

11241124
bool isVolatile() const { return !getVolatileCst()->isZero(); }
@@ -1180,7 +1180,7 @@ class MemSetPatternInst : public MemSetBase<MemIntrinsic> {
11801180

11811181
public:
11821182
ConstantInt *getVolatileCst() const {
1183-
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(ARG_VOLATILE)));
1183+
return cast<ConstantInt>(getArgOperand(ARG_VOLATILE));
11841184
}
11851185

11861186
bool isVolatile() const { return !getVolatileCst()->isZero(); }
@@ -1288,7 +1288,7 @@ class AnyMemIntrinsic : public MemIntrinsicBase<AnyMemIntrinsic> {
12881288

12891289
Value *getRawElementSizeInBytes() const {
12901290
assert(isAtomic());
1291-
return const_cast<Value *>(getArgOperand(ARG_ELEMENTSIZE));
1291+
return getArgOperand(ARG_ELEMENTSIZE);
12921292
}
12931293

12941294
uint32_t getElementSizeInBytes() const {
@@ -1388,7 +1388,7 @@ class VAStartInst : public IntrinsicInst {
13881388
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
13891389
}
13901390

1391-
Value *getArgList() const { return const_cast<Value *>(getArgOperand(0)); }
1391+
Value *getArgList() const { return getArgOperand(0); }
13921392
};
13931393

13941394
/// This represents the llvm.va_end intrinsic.
@@ -1401,7 +1401,7 @@ class VAEndInst : public IntrinsicInst {
14011401
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
14021402
}
14031403

1404-
Value *getArgList() const { return const_cast<Value *>(getArgOperand(0)); }
1404+
Value *getArgList() const { return getArgOperand(0); }
14051405
};
14061406

14071407
/// This represents the llvm.va_copy intrinsic.
@@ -1414,8 +1414,8 @@ class VACopyInst : public IntrinsicInst {
14141414
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
14151415
}
14161416

1417-
Value *getDest() const { return const_cast<Value *>(getArgOperand(0)); }
1418-
Value *getSrc() const { return const_cast<Value *>(getArgOperand(1)); }
1417+
Value *getDest() const { return getArgOperand(0); }
1418+
Value *getSrc() const { return getArgOperand(1); }
14191419
};
14201420

14211421
/// A base class for all instrprof intrinsics.
@@ -1457,16 +1457,12 @@ class InstrProfInstBase : public IntrinsicInst {
14571457
// The "name" operand of the profile instrumentation instruction - this is the
14581458
// operand that can be used to relate the instruction to the function it
14591459
// belonged to at instrumentation time.
1460-
Value *getNameValue() const {
1461-
return const_cast<Value *>(getArgOperand(0))->stripPointerCasts();
1462-
}
1460+
Value *getNameValue() const { return getArgOperand(0)->stripPointerCasts(); }
14631461

14641462
void setNameValue(Value *V) { setArgOperand(0, V); }
14651463

14661464
// The hash of the CFG for the instrumented function.
1467-
ConstantInt *getHash() const {
1468-
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
1469-
}
1465+
ConstantInt *getHash() const { return cast<ConstantInt>(getArgOperand(1)); }
14701466
};
14711467

14721468
/// A base class for all instrprof counter intrinsics.
@@ -1563,18 +1559,14 @@ class InstrProfValueProfileInst : public InstrProfCntrInstBase {
15631559
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
15641560
}
15651561

1566-
Value *getTargetValue() const {
1567-
return cast<Value>(const_cast<Value *>(getArgOperand(2)));
1568-
}
1562+
Value *getTargetValue() const { return cast<Value>(getArgOperand(2)); }
15691563

15701564
ConstantInt *getValueKind() const {
1571-
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
1565+
return cast<ConstantInt>(getArgOperand(3));
15721566
}
15731567

15741568
// Returns the value site index.
1575-
ConstantInt *getIndex() const {
1576-
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(4)));
1577-
}
1569+
ConstantInt *getIndex() const { return cast<ConstantInt>(getArgOperand(4)); }
15781570
};
15791571

15801572
/// A base class for instrprof mcdc intrinsics that require global bitmap bytes.
@@ -1590,7 +1582,7 @@ class InstrProfMCDCBitmapInstBase : public InstrProfInstBase {
15901582
/// \return The number of bits used for the MCDC bitmaps for the instrumented
15911583
/// function.
15921584
ConstantInt *getNumBitmapBits() const {
1593-
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
1585+
return cast<ConstantInt>(getArgOperand(2));
15941586
}
15951587

15961588
/// \return The number of bytes used for the MCDC bitmaps for the instrumented
@@ -1624,14 +1616,12 @@ class InstrProfMCDCTVBitmapUpdate : public InstrProfMCDCBitmapInstBase {
16241616
/// \return The index of the TestVector Bitmap upon which this intrinsic
16251617
/// acts.
16261618
ConstantInt *getBitmapIndex() const {
1627-
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
1619+
return cast<ConstantInt>(getArgOperand(2));
16281620
}
16291621

16301622
/// \return The address of the corresponding condition bitmap containing
16311623
/// the index of the TestVector to update within the TestVector Bitmap.
1632-
Value *getMCDCCondBitmapAddr() const {
1633-
return cast<Value>(const_cast<Value *>(getArgOperand(3)));
1634-
}
1624+
Value *getMCDCCondBitmapAddr() const { return cast<Value>(getArgOperand(3)); }
16351625
};
16361626

16371627
class PseudoProbeInst : public IntrinsicInst {
@@ -1645,20 +1635,16 @@ class PseudoProbeInst : public IntrinsicInst {
16451635
}
16461636

16471637
ConstantInt *getFuncGuid() const {
1648-
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(0)));
1638+
return cast<ConstantInt>(getArgOperand(0));
16491639
}
16501640

1651-
ConstantInt *getIndex() const {
1652-
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
1653-
}
1641+
ConstantInt *getIndex() const { return cast<ConstantInt>(getArgOperand(1)); }
16541642

16551643
ConstantInt *getAttributes() const {
1656-
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
1644+
return cast<ConstantInt>(getArgOperand(2));
16571645
}
16581646

1659-
ConstantInt *getFactor() const {
1660-
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
1661-
}
1647+
ConstantInt *getFactor() const { return cast<ConstantInt>(getArgOperand(3)); }
16621648
};
16631649

16641650
class NoAliasScopeDeclInst : public IntrinsicInst {

llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ bool InlineAsmLowering::lowerInlineAsm(
240240

241241
// Compute the value type for each operand.
242242
if (OpInfo.hasArg()) {
243-
OpInfo.CallOperandVal = const_cast<Value *>(Call.getArgOperand(ArgNo));
243+
OpInfo.CallOperandVal = Call.getArgOperand(ArgNo);
244244

245245
if (isa<BasicBlock>(OpInfo.CallOperandVal)) {
246246
LLVM_DEBUG(dbgs() << "Basic block input operands not supported yet\n");

llvm/lib/IR/IntrinsicInst.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,13 @@ void DbgAssignIntrinsic::setValue(Value *V) {
239239
ConstantInt *InstrProfCntrInstBase::getNumCounters() const {
240240
if (InstrProfValueProfileInst::classof(this))
241241
llvm_unreachable("InstrProfValueProfileInst does not have counters!");
242-
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
242+
return cast<ConstantInt>(getArgOperand(2));
243243
}
244244

245245
ConstantInt *InstrProfCntrInstBase::getIndex() const {
246246
if (InstrProfValueProfileInst::classof(this))
247247
llvm_unreachable("Please use InstrProfValueProfileInst::getIndex()");
248-
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
248+
return cast<ConstantInt>(getArgOperand(3));
249249
}
250250

251251
void InstrProfCntrInstBase::setIndex(uint32_t Idx) {
@@ -255,7 +255,7 @@ void InstrProfCntrInstBase::setIndex(uint32_t Idx) {
255255

256256
Value *InstrProfIncrementInst::getStep() const {
257257
if (InstrProfIncrementInstStep::classof(this)) {
258-
return const_cast<Value *>(getArgOperand(4));
258+
return getArgOperand(4);
259259
}
260260
const Module *M = getModule();
261261
LLVMContext &Context = M->getContext();

0 commit comments

Comments
 (0)