Skip to content

Commit 9a4f57e

Browse files
authored
[SelectionDAG] Use EVT::getIntegerVT in getBitcastedAnyExtOrTrunc (llvm#96658)
`SelectionDAG::getBitcastedAnyExtOrTrunc` assumes that there is always a valid integer type corresponding to another type, which is not always true when it comes to vector type. For example, `<3 x i8>` doesn't have a corresponding integer type. Fix SWDEV-464698.
1 parent e47359a commit 9a4f57e

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,14 +1468,14 @@ SDValue SelectionDAG::getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT) {
14681468
}
14691469

14701470
SDValue SelectionDAG::getBitcastedAnyExtOrTrunc(SDValue Op, const SDLoc &DL,
1471-
EVT VT) {
1471+
EVT VT) {
14721472
assert(!VT.isVector());
14731473
auto Type = Op.getValueType();
14741474
SDValue DestOp;
14751475
if (Type == VT)
14761476
return Op;
14771477
auto Size = Op.getValueSizeInBits();
1478-
DestOp = getBitcast(MVT::getIntegerVT(Size), Op);
1478+
DestOp = getBitcast(EVT::getIntegerVT(*Context, Size), Op);
14791479
if (DestOp.getValueType() == VT)
14801480
return DestOp;
14811481

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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=gfx942 %s -o - | FileCheck %s
3+
4+
define void @no_corresponding_integer_type(i8 %arg, ptr addrspace(1) %ptr) {
5+
; CHECK-LABEL: no_corresponding_integer_type:
6+
; CHECK: ; %bb.0: ; %entry
7+
; CHECK-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
8+
; CHECK-NEXT: v_mov_b32_e32 v3, v2
9+
; CHECK-NEXT: v_mov_b32_e32 v2, v1
10+
; CHECK-NEXT: global_load_ushort v1, v[2:3], off
11+
; CHECK-NEXT: global_load_ubyte v4, v[2:3], off offset:2
12+
; CHECK-NEXT: s_mov_b32 s0, 0xc0c0400
13+
; CHECK-NEXT: s_mov_b32 s1, 0xc0c0000
14+
; CHECK-NEXT: s_waitcnt vmcnt(0)
15+
; CHECK-NEXT: v_lshl_or_b32 v1, v4, 16, v1
16+
; CHECK-NEXT: v_perm_b32 v1, v0, v1, s0
17+
; CHECK-NEXT: v_perm_b32 v0, v0, v0, s1
18+
; CHECK-NEXT: v_dot4_u32_u8 v0, v0, v1, 1
19+
; CHECK-NEXT: s_nop 2
20+
; CHECK-NEXT: global_store_byte v[2:3], v0, off
21+
; CHECK-NEXT: s_waitcnt vmcnt(0)
22+
; CHECK-NEXT: s_setpc_b64 s[30:31]
23+
entry:
24+
%load = load <3 x i8>, ptr addrspace(1) %ptr, align 1
25+
%elt0 = extractelement <3 x i8> %load, i64 0
26+
%mul0 = mul i8 %elt0, %arg
27+
%or = or i8 %mul0, 1
28+
%mul1 = mul i8 %arg, %arg
29+
%add = add i8 %mul1, %or
30+
store i8 %add, ptr addrspace(1) %ptr, align 1
31+
ret void
32+
}

0 commit comments

Comments
 (0)