Skip to content

Commit 241da61

Browse files
committed
[WebAssembly][FastISel] Bail out on meeting non-integer type in selectTrunc
1 parent 5896a25 commit 241da61

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,11 +988,16 @@ bool WebAssemblyFastISel::selectSelect(const Instruction *I) {
988988
bool WebAssemblyFastISel::selectTrunc(const Instruction *I) {
989989
const auto *Trunc = cast<TruncInst>(I);
990990

991-
Register Reg = getRegForValue(Trunc->getOperand(0));
991+
const Value *Op = Trunc->getOperand(0);
992+
Register Reg = getRegForValue(Op);
992993
if (Reg == 0)
993994
return false;
994995

995-
unsigned FromBitWidth = Trunc->getOperand(0)->getType()->getIntegerBitWidth();
996+
// Bail out on meeting non-integer types.
997+
if (!Op->getType()->isIntegerTy() || !Trunc->getType()->isIntegerTy())
998+
return false;
999+
1000+
unsigned FromBitWidth = Op->getType()->getIntegerBitWidth();
9961001
unsigned ToBitWidth = Trunc->getType()->getIntegerBitWidth();
9971002

9981003
if (ToBitWidth <= 32 && (32 < FromBitWidth && FromBitWidth <= 64)) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
2+
; RUN: llc < %s -fast-isel -fast-isel-abort=0 -mattr=+simd128 -verify-machineinstrs | FileCheck %s
3+
4+
target triple = "wasm32-unknown-wasi"
5+
6+
define i8 @pr165438(<4 x i32> %0) {
7+
; CHECK-LABEL: pr165438:
8+
; CHECK: .functype pr165438 (v128) -> (i32)
9+
; CHECK-NEXT: # %bb.0: # %entry
10+
; CHECK-NEXT: local.get 0
11+
; CHECK-NEXT: local.get 0
12+
; CHECK-NEXT: i8x16.shuffle 0, 4, 8, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
13+
; CHECK-NEXT: i8x16.extract_lane_u 0
14+
; CHECK-NEXT: # fallthrough-return
15+
entry:
16+
%conv = trunc <4 x i32> %0 to <4 x i8>
17+
br label %cond.true
18+
19+
cond.true: ; preds = %entry
20+
%vecext = extractelement <4 x i8> %conv, i32 0
21+
ret i8 %vecext
22+
}

0 commit comments

Comments
 (0)