Skip to content

Commit 6595176

Browse files
committed
[AMDGPU][GlobalISel] Fix assert on APInt creation.
Since 3494ee9 APInt stopped to implicitly truncate values, therefore it asserts on a big signed value converted to (implicitly) unsigned APInt. The change explicitly marks offset as a signed value.
1 parent bd38c49 commit 6595176

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

llvm/lib/Target/AMDGPU/AMDGPUGlobalISelUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ AMDGPU::getBaseWithConstantOffset(MachineRegisterInfo &MRI, Register Reg,
5656

5757
Register Base;
5858
if (KnownBits && mi_match(Reg, MRI, m_GOr(m_Reg(Base), m_ICst(Offset))) &&
59-
KnownBits->maskedValueIsZero(Base, APInt(32, Offset)))
59+
KnownBits->maskedValueIsZero(Base, APInt(32, Offset, /*isSigned=*/true)))
6060
return std::pair(Base, Offset);
6161

6262
// Handle G_PTRTOINT (G_PTR_ADD base, const) case
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; REQUIRES: asserts
2+
; RUN: llc -global-isel -mtriple=amdgcn -mcpu=gfx1200 -verify-machineinstrs -stop-after=instruction-select -o - %s | FileCheck %s
3+
4+
;
5+
6+
; CHECK-LABEL: @test
7+
; CHECK: S_BUFFER_LOAD_DWORD_SGPR_IMM
8+
9+
define amdgpu_cs void @test(<4 x i32> inreg %base, i32 inreg %i, ptr addrspace(1) inreg %out) {
10+
%off = or i32 %i, -2147483648
11+
%v = call i32 @llvm.amdgcn.s.buffer.load.i32(<4 x i32> %base, i32 %off, i32 0)
12+
store i32 %v, ptr addrspace(1) %out, align 4
13+
ret void
14+
}

0 commit comments

Comments
 (0)