Skip to content

Commit

Permalink
[AMDGPU] Do not use APInt for simple 64-bit arithmetic. NFC. (#109414)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayfoad committed Sep 20, 2024
1 parent 3bcffe5 commit 73b8074
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,7 @@ bool AMDGPUDAGToDAGISel::SelectMUBUFOffset(SDValue Addr, SDValue &SRsrc,
!cast<ConstantSDNode>(Idxen)->getSExtValue() &&
!cast<ConstantSDNode>(Addr64)->getSExtValue()) {
uint64_t Rsrc = TII->getDefaultRsrcDataFormat() |
APInt::getAllOnes(32).getZExtValue(); // Size
maskTrailingOnes<uint64_t>(32); // Size
SDLoc DL(Addr);

const SITargetLowering& Lowering =
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ static DecodeStatus decodeSOPPBrTarget(MCInst &Inst, unsigned Imm,
const MCDisassembler *Decoder) {
auto DAsm = static_cast<const AMDGPUDisassembler*>(Decoder);

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

if (DAsm->tryAddingSymbolicOperand(Inst, Offset, Addr, true, 2, 2, 0))
return MCDisassembler::Success;
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,8 @@ class AMDGPUMCInstrAnalysis : public MCInstrAnalysis {
return false;

int64_t Imm = Inst.getOperand(0).getImm();
// Our branches take a simm16, but we need two extra bits to account for
// the factor of 4.
APInt SignedOffset(18, Imm * 4, true);
Target = (SignedOffset.sext(64) + Addr + Size).getZExtValue();
// Our branches take a simm16.
Target = SignExtend64<16>(Imm) * 4 + Addr + Size;
return true;
}
};
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3401,13 +3401,13 @@ bool SIInstrInfo::foldImmediate(MachineInstr &UseMI, MachineInstr &DefMI,
case AMDGPU::sub1:
return Hi_32(Imm);
case AMDGPU::lo16:
return APInt(16, Imm).getSExtValue();
return SignExtend64<16>(Imm);
case AMDGPU::hi16:
return APInt(32, Imm).ashr(16).getSExtValue();
return SignExtend64<16>(Imm >> 16);
case AMDGPU::sub1_lo16:
return APInt(16, Hi_32(Imm)).getSExtValue();
return SignExtend64<16>(Imm >> 32);
case AMDGPU::sub1_hi16:
return APInt(32, Hi_32(Imm)).ashr(16).getSExtValue();
return SignExtend64<16>(Imm >> 48);
}
};

Expand Down

0 comments on commit 73b8074

Please sign in to comment.