Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 9ad4b7e

Browse files
authored
Merge pull request #117 from alexcrichton/wasm-fix
[WebAssembly] Fix fast-isel lowering illegal argument and return types.
2 parents 56c9319 + 1e0cfd6 commit 9ad4b7e

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

lib/Target/WebAssembly/WebAssemblyFastISel.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -695,14 +695,22 @@ bool WebAssemblyFastISel::fastLowerArguments() {
695695
MRI.addLiveIn(WebAssembly::ARGUMENTS);
696696

697697
auto *MFI = MF->getInfo<WebAssemblyFunctionInfo>();
698-
for (auto const &Arg : F->args())
699-
MFI->addParam(getLegalType(getSimpleType(Arg.getType())));
698+
for (auto const &Arg : F->args()) {
699+
MVT::SimpleValueType ArgTy = getLegalType(getSimpleType(Arg.getType()));
700+
if (ArgTy == MVT::INVALID_SIMPLE_VALUE_TYPE) {
701+
MFI->clearParamsAndResults();
702+
return false;
703+
}
704+
MFI->addParam(ArgTy);
705+
}
700706

701707
if (!F->getReturnType()->isVoidTy()) {
702-
MVT::SimpleValueType RetTy = getSimpleType(F->getReturnType());
703-
if (RetTy == MVT::INVALID_SIMPLE_VALUE_TYPE)
708+
MVT::SimpleValueType RetTy = getLegalType(getSimpleType(F->getReturnType()));
709+
if (RetTy == MVT::INVALID_SIMPLE_VALUE_TYPE) {
710+
MFI->clearParamsAndResults();
704711
return false;
705-
MFI->addResult(getLegalType(RetTy));
712+
}
713+
MFI->addResult(RetTy);
706714
}
707715

708716
return true;

lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class WebAssemblyFunctionInfo final : public MachineFunctionInfo {
6060
void addResult(MVT VT) { Results.push_back(VT); }
6161
const std::vector<MVT> &getResults() const { return Results; }
6262

63+
void clearParamsAndResults() { Params.clear(); Results.clear(); }
64+
6365
void setNumLocals(size_t NumLocals) { Locals.resize(NumLocals, MVT::i32); }
6466
void setLocal(size_t i, MVT VT) { Locals[i] = VT; }
6567
void addLocal(MVT VT) { Locals.push_back(VT); }
+12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
; RUN: llc < %s -O0
22
; PR36564
3+
; PR37546
34

45
; Test that fast-isel properly copes with i24 arguments and return types.
56

67
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
78
target triple = "wasm32-unknown-unknown-wasm"
89

10+
; CHECK-LABEL: add:
11+
; CHECK-NEXT: .param i32, i32{{$}}
12+
; CHECK-NEXT: .result i32{{$}}
13+
; CHECK-NEXT: get_local $push2=, 0{{$}}
14+
; CHECK-NEXT: get_local $push1=, 1{{$}}
15+
; CHECK-NEXT: i32.add $push0=, $pop2, $pop1{{$}}
16+
; CHECK-NEXT: end_function
917
define i24 @add(i24 %x, i24 %y) {
1018
%z = add i24 %x, %y
1119
ret i24 %z
1220
}
1321

22+
; CHECK-LABEL: return_zero:
23+
; CHECK-NEXT: .result i32{{$}}
24+
; CHECK-NEXT: i32.const $push0=, 0{{$}}
25+
; CHECK-NEXT: end_function
1426
define i24 @return_zero() {
1527
ret i24 0
1628
}
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; RUN: llc < %s -O0
2+
; PR36564
3+
; PR37546
4+
5+
; Test that fast-isel properly copes with i256 arguments and return types.
6+
7+
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
8+
target triple = "wasm32-unknown-unknown"
9+
10+
; CHECK-LABEL: add:
11+
; CHECK-NEXT: .param i32, i64, i64, i64, i64, i64, i64, i64, i64{{$}}
12+
; CHECK-NOT: .result
13+
; CHECK: end_function
14+
define i256 @add(i256 %x, i256 %y) {
15+
%z = add i256 %x, %y
16+
ret i256 %z
17+
}
18+
19+
; CHECK-LABEL: return_zero:
20+
; CHECK-NEXT: .param i32{{$}}
21+
; CHECK-NOT: .result
22+
; CHECK: end_function
23+
define i256 @return_zero() {
24+
ret i256 0
25+
}
26+
27+
; CHECK-LABEL: return_zero_with_params:
28+
; CHECK-NEXT: .param i32, f32{{$}}
29+
; CHECK-NOT: .result
30+
; CHECK: end_function
31+
define i256 @return_zero_with_params(float %x) {
32+
ret i256 0
33+
}

0 commit comments

Comments
 (0)