Skip to content

Commit 1278ac7

Browse files
[NFC][GlobalISel] Pass APInt by const reference (#157827)
Change `SpecificConstantMatch` constructor and `isBuildVectorConstantSplat` overloads to take `const APInt&` instead of by value to avoid unnecessary copies, especially for wide integers.
1 parent 6fda136 commit 1278ac7

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ m_GFCstOrSplat(std::optional<FPValueAndVReg> &FPValReg) {
193193
/// Matcher for a specific constant value.
194194
struct SpecificConstantMatch {
195195
APInt RequestedVal;
196-
SpecificConstantMatch(const APInt RequestedVal)
196+
SpecificConstantMatch(const APInt &RequestedVal)
197197
: RequestedVal(RequestedVal) {}
198198
bool match(const MachineRegisterInfo &MRI, Register Reg) {
199199
APInt MatchedVal;

llvm/include/llvm/CodeGen/GlobalISel/Utils.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ LLVM_ABI bool isBuildVectorConstantSplat(const Register Reg,
463463
/// G_BUILD_VECTOR_TRUNC where all of the elements are \p SplatValue or undef.
464464
LLVM_ABI bool isBuildVectorConstantSplat(const Register Reg,
465465
const MachineRegisterInfo &MRI,
466-
APInt SplatValue, bool AllowUndef);
466+
const APInt &SplatValue,
467+
bool AllowUndef);
467468

468469
/// Return true if the specified instruction is a G_BUILD_VECTOR or
469470
/// G_BUILD_VECTOR_TRUNC where all of the elements are \p SplatValue or undef.
@@ -475,7 +476,8 @@ LLVM_ABI bool isBuildVectorConstantSplat(const MachineInstr &MI,
475476
/// G_BUILD_VECTOR_TRUNC where all of the elements are \p SplatValue or undef.
476477
LLVM_ABI bool isBuildVectorConstantSplat(const MachineInstr &MI,
477478
const MachineRegisterInfo &MRI,
478-
APInt SplatValue, bool AllowUndef);
479+
const APInt &SplatValue,
480+
bool AllowUndef);
479481

480482
/// Return true if the specified instruction is a G_BUILD_VECTOR or
481483
/// G_BUILD_VECTOR_TRUNC where all of the elements are 0 or undef.

llvm/lib/CodeGen/GlobalISel/Utils.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,8 @@ bool llvm::isBuildVectorConstantSplat(const Register Reg,
14091409

14101410
bool llvm::isBuildVectorConstantSplat(const Register Reg,
14111411
const MachineRegisterInfo &MRI,
1412-
APInt SplatValue, bool AllowUndef) {
1412+
const APInt &SplatValue,
1413+
bool AllowUndef) {
14131414
if (auto SplatValAndReg = getAnyConstantSplat(Reg, MRI, AllowUndef)) {
14141415
if (SplatValAndReg->Value.getBitWidth() < SplatValue.getBitWidth())
14151416
return APInt::isSameValue(
@@ -1431,7 +1432,8 @@ bool llvm::isBuildVectorConstantSplat(const MachineInstr &MI,
14311432

14321433
bool llvm::isBuildVectorConstantSplat(const MachineInstr &MI,
14331434
const MachineRegisterInfo &MRI,
1434-
APInt SplatValue, bool AllowUndef) {
1435+
const APInt &SplatValue,
1436+
bool AllowUndef) {
14351437
return isBuildVectorConstantSplat(MI.getOperand(0).getReg(), MRI, SplatValue,
14361438
AllowUndef);
14371439
}

0 commit comments

Comments
 (0)