Skip to content

Commit f15da5f

Browse files
authored
[AMDGPU] Fix an invalid cast in AMDGPULateCodeGenPrepare::visitLoadInst (#122494)
Fixes: SWDEV-507695
1 parent 77e6f43 commit f15da5f

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,11 @@ bool AMDGPULateCodeGenPrepare::visitLoadInst(LoadInst &LI) {
464464
NewLd->setMetadata(LLVMContext::MD_range, nullptr);
465465

466466
unsigned ShAmt = Adjust * 8;
467-
auto *NewVal = IRB.CreateBitCast(
468-
IRB.CreateTrunc(IRB.CreateLShr(NewLd, ShAmt), IntNTy), LI.getType());
467+
Value *NewVal = IRB.CreateBitCast(
468+
IRB.CreateTrunc(IRB.CreateLShr(NewLd, ShAmt),
469+
DL.typeSizeEqualsStoreSize(LI.getType()) ? IntNTy
470+
: LI.getType()),
471+
LI.getType());
469472
LI.replaceAllUsesWith(NewVal);
470473
DeadInsts.emplace_back(&LI);
471474

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a %s -o - | FileCheck %s
3+
4+
define amdgpu_kernel void @load_idx_idy(ptr addrspace(4) %disp, ptr %g) {
5+
; CHECK-LABEL: load_idx_idy:
6+
; CHECK: ; %bb.0: ; %entry
7+
; CHECK-NEXT: s_load_dword s6, s[4:5], 0x4
8+
; CHECK-NEXT: s_load_dwordx4 s[0:3], s[8:9], 0x0
9+
; CHECK-NEXT: v_mov_b32_e32 v0, 0
10+
; CHECK-NEXT: s_waitcnt lgkmcnt(0)
11+
; CHECK-NEXT: s_lshr_b32 s4, s6, 16
12+
; CHECK-NEXT: s_bfe_i64 s[4:5], s[4:5], 0x10000
13+
; CHECK-NEXT: s_lshl_b64 s[4:5], s[4:5], 6
14+
; CHECK-NEXT: s_add_u32 s0, s0, s4
15+
; CHECK-NEXT: s_addc_u32 s1, s1, s5
16+
; CHECK-NEXT: global_load_ubyte v2, v0, s[0:1] offset:4
17+
; CHECK-NEXT: v_mov_b32_e32 v0, s2
18+
; CHECK-NEXT: v_mov_b32_e32 v1, s3
19+
; CHECK-NEXT: s_waitcnt vmcnt(0)
20+
; CHECK-NEXT: flat_store_byte v[0:1], v2
21+
; CHECK-NEXT: s_endpgm
22+
entry:
23+
%disp1 = tail call ptr addrspace(4) @llvm.amdgcn.dispatch.ptr()
24+
%gep_y = getelementptr i8, ptr addrspace(4) %disp1, i64 6
25+
%L = load i1, ptr addrspace(4) %gep_y, align 1
26+
%idxprom = sext i1 %L to i64
27+
%gep0 = getelementptr <32 x i16>, ptr addrspace(4) %disp, i64 %idxprom
28+
%gep1 = getelementptr i8, ptr addrspace(4) %gep0, i64 4
29+
%L1 = load i8, ptr addrspace(4) %gep1
30+
store i8 %L1, ptr %g
31+
ret void
32+
}
33+
34+
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
35+
declare noundef nonnull align 4 ptr addrspace(4) @llvm.amdgcn.dispatch.ptr() #0
36+
37+
attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

0 commit comments

Comments
 (0)