[llvm] [AMDGPU] Do not use APInt for simple 64-bit arithmetic. NFC. (PR #109414)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 20 05:39:30 PDT 2024
https://github.com/jayfoad updated https://github.com/llvm/llvm-project/pull/109414
>From cb76e9a505c957a5ec002c34a789eaa68a6fa3e5 Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Fri, 20 Sep 2024 13:25:30 +0100
Subject: [PATCH 1/3] [AMDGPU] Do not use APInt for simple 64-bit arithmetic.
NFC.
---
.../lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp | 6 ++----
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp | 8 ++++----
2 files changed, 6 insertions(+), 8 deletions(-)
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);
}
};
>From 1a6aa4d2702e56099feb3d7ec845ea307999ce5e Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Fri, 20 Sep 2024 13:33:22 +0100
Subject: [PATCH 2/3] Update one more place
---
llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp
index 37eb0b57fb1537..8044810fdab944 100644
--- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp
+++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp
@@ -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;
}
};
>From a09875c6ebf3c523bfd6462ae8cfd009bcd6b7e9 Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Fri, 20 Sep 2024 13:38:17 +0100
Subject: [PATCH 3/3] And another
---
llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp b/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
index 380dc7d3312f32..d70873b2132fa1 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
@@ -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 =
More information about the llvm-commits
mailing list