[llvm] [AMDGPU] Do not use APInt for simple 64-bit arithmetic. NFC. (PR #109414)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 20 05:30:13 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Jay Foad (jayfoad)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/109414.diff
2 Files Affected:
- (modified) llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp (+2-4)
- (modified) llvm/lib/Target/AMDGPU/SIInstrInfo.cpp (+4-4)
``````````diff
diff --git a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
index 6c2a6643e67c76..2f5eba47afc27f 100644
--- a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
+++ b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
@@ -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;
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index c6a9a627d457e7..f2de8bab6397d2 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -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);
}
};
``````````
</details>
https://github.com/llvm/llvm-project/pull/109414
More information about the llvm-commits
mailing list