Skip to content

Commit abc1056

Browse files
committed
[AMDGPU] Fix an invalid cast in AMDGPULateCodeGenPrepare::visitLoadInst
1 parent c664a7f commit abc1056

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,14 @@ 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 = nullptr;
468+
if (DL.typeSizeEqualsStoreSize(LI.getType())) {
469+
NewVal = IRB.CreateBitCast(
470+
IRB.CreateTrunc(IRB.CreateLShr(NewLd, ShAmt), IntNTy), LI.getType());
471+
} else {
472+
assert(DL.getTypeSizeInBits(LI.getType()) < LdBits);
473+
NewVal = IRB.CreateTrunc(IRB.CreateLShr(NewLd, ShAmt), LI.getType());
474+
}
469475
LI.replaceAllUsesWith(NewVal);
470476
DeadInsts.emplace_back(&LI);
471477

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
@g = global ptr null
5+
6+
define amdgpu_kernel void @load_idx_idy(ptr addrspace(4) %disp) {
7+
; CHECK-LABEL: load_idx_idy:
8+
; CHECK: ; %bb.0: ; %entry
9+
; CHECK-NEXT: s_load_dword s2, s[4:5], 0x4
10+
; CHECK-NEXT: s_load_dwordx2 s[0:1], s[8:9], 0x0
11+
; CHECK-NEXT: v_mov_b32_e32 v0, 0
12+
; CHECK-NEXT: s_waitcnt lgkmcnt(0)
13+
; CHECK-NEXT: s_lshr_b32 s2, s2, 16
14+
; CHECK-NEXT: s_bfe_i64 s[2:3], s[2:3], 0x10000
15+
; CHECK-NEXT: s_lshl_b64 s[2:3], s[2:3], 6
16+
; CHECK-NEXT: s_add_u32 s0, s0, s2
17+
; CHECK-NEXT: s_addc_u32 s1, s1, s3
18+
; CHECK-NEXT: global_load_ubyte v2, v0, s[0:1] offset:4
19+
; CHECK-NEXT: s_getpc_b64 s[0:1]
20+
; CHECK-NEXT: s_add_u32 s0, s0, g@gotpcrel32@lo+4
21+
; CHECK-NEXT: s_addc_u32 s1, s1, g@gotpcrel32@hi+12
22+
; CHECK-NEXT: s_load_dwordx2 s[0:1], s[0:1], 0x0
23+
; CHECK-NEXT: s_waitcnt lgkmcnt(0)
24+
; CHECK-NEXT: v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
25+
; CHECK-NEXT: s_waitcnt vmcnt(0)
26+
; CHECK-NEXT: flat_store_byte v[0:1], v2
27+
; CHECK-NEXT: s_endpgm
28+
entry:
29+
%disp1 = tail call ptr addrspace(4) @llvm.amdgcn.dispatch.ptr()
30+
%gep_y = getelementptr i8, ptr addrspace(4) %disp1, i64 6
31+
%L = load i1, ptr addrspace(4) %gep_y, align 1
32+
%idxprom = sext i1 %L to i64
33+
%gep0 = getelementptr <32 x i16>, ptr addrspace(4) %disp, i64 %idxprom
34+
%gep1 = getelementptr i8, ptr addrspace(4) %gep0, i64 4
35+
%L1 = load i8, ptr addrspace(4) %gep1
36+
store i8 %L1, ptr @g
37+
ret void
38+
}
39+
40+
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
41+
declare noundef nonnull align 4 ptr addrspace(4) @llvm.amdgcn.dispatch.ptr() #0
42+
43+
attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

0 commit comments

Comments
 (0)