def : Pat<(i64 (extloadi32 I32:$addr)), (LOAD32_U_I64 $addr)>;
// Basic store.
+// Note that we split the patterns out of the instruction definitions because
+// WebAssembly's stores return their operand value, and tablegen doesn't like
+// instruction definition patterns that don't reference all of the output
+// operands.
// Note: WebAssembly inverts SelectionDAG's usual operand order.
-def STORE_I32 : I<(outs), (ins I32:$addr, I32:$val),
- [(store i32:$val, I32:$addr)],
- "i32.store\t$addr, $val">;
-def STORE_I64 : I<(outs), (ins I32:$addr, I64:$val),
- [(store i64:$val, I32:$addr)],
- "i64.store\t$addr, $val">;
-def STORE_F32 : I<(outs), (ins I32:$addr, F32:$val),
- [(store f32:$val, I32:$addr)],
- "f32.store\t$addr, $val">;
-def STORE_F64 : I<(outs), (ins I32:$addr, F64:$val),
- [(store f64:$val, I32:$addr)],
- "f64.store\t$addr, $val">;
+def STORE_I32 : I<(outs I32:$dst), (ins I32:$addr, I32:$val), [],
+ "i32.store\t$dst, $addr, $val">;
+def STORE_I64 : I<(outs I64:$dst), (ins I32:$addr, I64:$val), [],
+ "i64.store\t$dst, $addr, $val">;
+def STORE_F32 : I<(outs F32:$dst), (ins I32:$addr, F32:$val), [],
+ "f32.store\t$dst, $addr, $val">;
+def STORE_F64 : I<(outs F64:$dst), (ins I32:$addr, F64:$val), [],
+ "f64.store\t$dst, $addr, $val">;
+
+def : Pat<(store I32:$val, I32:$addr), (STORE_I32 I32:$addr, I32:$val)>;
+def : Pat<(store I64:$val, I32:$addr), (STORE_I64 I32:$addr, I64:$val)>;
+def : Pat<(store F32:$val, I32:$addr), (STORE_F32 I32:$addr, F32:$val)>;
+def : Pat<(store F64:$val, I32:$addr), (STORE_F64 I32:$addr, F64:$val)>;
// Truncating store.
-def STORE8_I32 : I<(outs), (ins I32:$addr, I32:$val),
- [(truncstorei8 I32:$val, I32:$addr)],
- "i32.store8\t$addr, $val">;
-def STORE16_I32 : I<(outs), (ins I32:$addr, I32:$val),
- [(truncstorei16 I32:$val, I32:$addr)],
- "i32.store16\t$addr, $val">;
-def STORE8_I64 : I<(outs), (ins I32:$addr, I64:$val),
- [(truncstorei8 I64:$val, I32:$addr)],
- "i64.store8\t$addr, $val">;
-def STORE16_I64 : I<(outs), (ins I32:$addr, I64:$val),
- [(truncstorei16 I64:$val, I32:$addr)],
- "i64.store16\t$addr, $val">;
-def STORE32_I64 : I<(outs), (ins I32:$addr, I64:$val),
- [(truncstorei32 I64:$val, I32:$addr)],
- "i64.store32\t$addr, $val">;
+def STORE8_I32 : I<(outs I32:$dst), (ins I32:$addr, I32:$val), [],
+ "i32.store8\t$dst, $addr, $val">;
+def STORE16_I32 : I<(outs I32:$dst), (ins I32:$addr, I32:$val), [],
+ "i32.store16\t$dst, $addr, $val">;
+def STORE8_I64 : I<(outs I64:$dst), (ins I32:$addr, I64:$val), [],
+ "i64.store8\t$dst, $addr, $val">;
+def STORE16_I64 : I<(outs I64:$dst), (ins I32:$addr, I64:$val), [],
+ "i64.store16\t$dst, $addr, $val">;
+def STORE32_I64 : I<(outs I64:$dst), (ins I32:$addr, I64:$val), [],
+ "i64.store32\t$dst, $addr, $val">;
+
+def : Pat<(truncstorei8 I32:$val, I32:$addr),
+ (STORE8_I32 I32:$addr, I32:$val)>;
+def : Pat<(truncstorei16 I32:$val, I32:$addr),
+ (STORE16_I32 I32:$addr, I32:$val)>;
+def : Pat<(truncstorei8 I64:$val, I32:$addr),
+ (STORE8_I64 I32:$addr, I64:$val)>;
+def : Pat<(truncstorei16 I64:$val, I32:$addr),
+ (STORE16_I64 I32:$addr, I64:$val)>;
+def : Pat<(truncstorei32 I64:$val, I32:$addr),
+ (STORE32_I64 I32:$addr, I64:$val)>;
// Memory size.
def MEMORY_SIZE_I32 : I<(outs I32:$dst), (ins),
target triple = "wasm32-unknown-unknown"
; CHECK-LABEL: trunc_i8_i32:
-; CHECK: i32.store8 $0, $1{{$}}
+; CHECK: i32.store8 $discard, $0, $1{{$}}
define void @trunc_i8_i32(i8 *%p, i32 %v) {
%t = trunc i32 %v to i8
store i8 %t, i8* %p
}
; CHECK-LABEL: trunc_i16_i32:
-; CHECK: i32.store16 $0, $1{{$}}
+; CHECK: i32.store16 $discard, $0, $1{{$}}
define void @trunc_i16_i32(i16 *%p, i32 %v) {
%t = trunc i32 %v to i16
store i16 %t, i16* %p
}
; CHECK-LABEL: trunc_i8_i64:
-; CHECK: i64.store8 $0, $1{{$}}
+; CHECK: i64.store8 $discard, $0, $1{{$}}
define void @trunc_i8_i64(i8 *%p, i64 %v) {
%t = trunc i64 %v to i8
store i8 %t, i8* %p
}
; CHECK-LABEL: trunc_i16_i64:
-; CHECK: i64.store16 $0, $1{{$}}
+; CHECK: i64.store16 $discard, $0, $1{{$}}
define void @trunc_i16_i64(i16 *%p, i64 %v) {
%t = trunc i64 %v to i16
store i16 %t, i16* %p
}
; CHECK-LABEL: trunc_i32_i64:
-; CHECK: i64.store32 $0, $1{{$}}
+; CHECK: i64.store32 $discard, $0, $1{{$}}
define void @trunc_i32_i64(i32 *%p, i64 %v) {
%t = trunc i64 %v to i32
store i32 %t, i32* %p
; CHECK-LABEL: sti32:
; CHECK-NEXT: .param i32, i32{{$}}
-; CHECK-NEXT: i32.store $0, $1{{$}}
+; CHECK-NEXT: i32.store $discard, $0, $1{{$}}
; CHECK-NEXT: return{{$}}
define void @sti32(i32 *%p, i32 %v) {
store i32 %v, i32* %p
; CHECK-LABEL: sti64:
; CHECK-NEXT: .param i32, i64{{$}}
-; CHECK-NEXT: i64.store $0, $1{{$}}
+; CHECK-NEXT: i64.store $discard, $0, $1{{$}}
; CHECK-NEXT: return{{$}}
define void @sti64(i64 *%p, i64 %v) {
store i64 %v, i64* %p
; CHECK-LABEL: stf32:
; CHECK-NEXT: .param i32, f32{{$}}
-; CHECK-NEXT: f32.store $0, $1{{$}}
+; CHECK-NEXT: f32.store $discard, $0, $1{{$}}
; CHECK-NEXT: return{{$}}
define void @stf32(float *%p, float %v) {
store float %v, float* %p
; CHECK-LABEL: stf64:
; CHECK-NEXT: .param i32, f64{{$}}
-; CHECK-NEXT: f64.store $0, $1{{$}}
+; CHECK-NEXT: f64.store $discard, $0, $1{{$}}
; CHECK-NEXT: return{{$}}
define void @stf64(double *%p, double %v) {
store double %v, double* %p