-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[WebAssembly][FastISel] Bail out on meeting non-integer type in selectTrunc #167165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@llvm/pr-subscribers-backend-webassembly Author: Hongyu Chen (XChy) ChangesFixes #165589 Full diff: https://github.com/llvm/llvm-project/pull/167165.diff 2 Files Affected:
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
index 66ed8b078b808..503d4850459cb 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
@@ -988,11 +988,16 @@ bool WebAssemblyFastISel::selectSelect(const Instruction *I) {
bool WebAssemblyFastISel::selectTrunc(const Instruction *I) {
const auto *Trunc = cast<TruncInst>(I);
- Register Reg = getRegForValue(Trunc->getOperand(0));
+ const Value *Op = Trunc->getOperand(0);
+ Register Reg = getRegForValue(Op);
if (Reg == 0)
return false;
- unsigned FromBitWidth = Trunc->getOperand(0)->getType()->getIntegerBitWidth();
+ // Bail out on meeting non-integer types.
+ if (!Op->getType()->isIntegerTy() || !Trunc->getType()->isIntegerTy())
+ return false;
+
+ unsigned FromBitWidth = Op->getType()->getIntegerBitWidth();
unsigned ToBitWidth = Trunc->getType()->getIntegerBitWidth();
if (ToBitWidth <= 32 && (32 < FromBitWidth && FromBitWidth <= 64)) {
diff --git a/llvm/test/CodeGen/WebAssembly/fast-isel-simd128.ll b/llvm/test/CodeGen/WebAssembly/fast-isel-simd128.ll
new file mode 100644
index 0000000000000..aefadec3e3fc5
--- /dev/null
+++ b/llvm/test/CodeGen/WebAssembly/fast-isel-simd128.ll
@@ -0,0 +1,22 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc < %s -fast-isel -fast-isel-abort=0 -mattr=+simd128 -verify-machineinstrs | FileCheck %s
+
+target triple = "wasm32-unknown-wasi"
+
+define i8 @pr165438(<4 x i32> %0) {
+; CHECK-LABEL: pr165438:
+; CHECK: .functype pr165438 (v128) -> (i32)
+; CHECK-NEXT: # %bb.0: # %entry
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: local.get 0
+; CHECK-NEXT: i8x16.shuffle 0, 4, 8, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+; CHECK-NEXT: i8x16.extract_lane_u 0
+; CHECK-NEXT: # fallthrough-return
+entry:
+ %conv = trunc <4 x i32> %0 to <4 x i8>
+ br label %cond.true
+
+cond.true: ; preds = %entry
+ %vecext = extractelement <4 x i8> %conv, i32 0
+ ret i8 %vecext
+}
|
|
Yeah, I was kind of on the fence about whether to just always bail out on odd-size types or accept the one-off fixup to FastISel. I think this bug basically just proves my stated concern in #138479 that it wouldn't be just a one-off fix, i.e. that there would be more fixes to follow on. So given that, maybe it does make sense to just always bail out on odd-size types. Do you mind making that change in this PR? |
241da61 to
ba8f085
Compare
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
|
i'm new to the fastisel codebase but LG, please wait for another reviewer, ty |
Fixes #165438
With
simd128enabled, we may meet vector type truncation in FastISel. To respect #138479, this patch merely bails out on non-integer IR types, though I prefer bailing out for all non-simple types as most targets (X86, AArch64) do.