Skip to content

Commit 73b8074

Browse files
authored
[AMDGPU] Do not use APInt for simple 64-bit arithmetic. NFC. (llvm#109414)
1 parent 3bcffe5 commit 73b8074

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ bool AMDGPUDAGToDAGISel::SelectMUBUFOffset(SDValue Addr, SDValue &SRsrc,
15981598
!cast<ConstantSDNode>(Idxen)->getSExtValue() &&
15991599
!cast<ConstantSDNode>(Addr64)->getSExtValue()) {
16001600
uint64_t Rsrc = TII->getDefaultRsrcDataFormat() |
1601-
APInt::getAllOnes(32).getZExtValue(); // Size
1601+
maskTrailingOnes<uint64_t>(32); // Size
16021602
SDLoc DL(Addr);
16031603

16041604
const SITargetLowering& Lowering =

llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,8 @@ static DecodeStatus decodeSOPPBrTarget(MCInst &Inst, unsigned Imm,
106106
const MCDisassembler *Decoder) {
107107
auto DAsm = static_cast<const AMDGPUDisassembler*>(Decoder);
108108

109-
// Our branches take a simm16, but we need two extra bits to account for the
110-
// factor of 4.
111-
APInt SignedOffset(18, Imm * 4, true);
112-
int64_t Offset = (SignedOffset.sext(64) + 4 + Addr).getSExtValue();
109+
// Our branches take a simm16.
110+
int64_t Offset = SignExtend64<16>(Imm) * 4 + 4 + Addr;
113111

114112
if (DAsm->tryAddingSymbolicOperand(Inst, Offset, Addr, true, 2, 2, 0))
115113
return MCDisassembler::Success;

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,8 @@ class AMDGPUMCInstrAnalysis : public MCInstrAnalysis {
130130
return false;
131131

132132
int64_t Imm = Inst.getOperand(0).getImm();
133-
// Our branches take a simm16, but we need two extra bits to account for
134-
// the factor of 4.
135-
APInt SignedOffset(18, Imm * 4, true);
136-
Target = (SignedOffset.sext(64) + Addr + Size).getZExtValue();
133+
// Our branches take a simm16.
134+
Target = SignExtend64<16>(Imm) * 4 + Addr + Size;
137135
return true;
138136
}
139137
};

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3401,13 +3401,13 @@ bool SIInstrInfo::foldImmediate(MachineInstr &UseMI, MachineInstr &DefMI,
34013401
case AMDGPU::sub1:
34023402
return Hi_32(Imm);
34033403
case AMDGPU::lo16:
3404-
return APInt(16, Imm).getSExtValue();
3404+
return SignExtend64<16>(Imm);
34053405
case AMDGPU::hi16:
3406-
return APInt(32, Imm).ashr(16).getSExtValue();
3406+
return SignExtend64<16>(Imm >> 16);
34073407
case AMDGPU::sub1_lo16:
3408-
return APInt(16, Hi_32(Imm)).getSExtValue();
3408+
return SignExtend64<16>(Imm >> 32);
34093409
case AMDGPU::sub1_hi16:
3410-
return APInt(32, Hi_32(Imm)).ashr(16).getSExtValue();
3410+
return SignExtend64<16>(Imm >> 48);
34113411
}
34123412
};
34133413

0 commit comments

Comments
 (0)