Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td @@ -134,6 +134,29 @@ defm "" : SIMDBinary; defm "" : SIMDBinary; } +multiclass SIMDNeg simdop> { + defm NEG_#vec_t : SIMD_I<(outs V128:$dst), (ins V128:$vec), + (outs), (ins), + [(set + (vec_t V128:$dst), + (vec_t (node + (vec_t (splat_pat lane)), + (vec_t V128:$vec) + )) + )], + vec#".neg\t$dst, $vec", vec#".neg", simdop>; +} +multiclass SIMDNegInt simdop> { + defm "" : SIMDNeg; +} +def fpimm0 : FPImmLeaf; +multiclass SIMDNegFP simdop> { + defm "" : SIMDNeg; +} multiclass SIMDNot { defm NOT_#vec_t : SIMD_I<(outs V128:$dst), (ins V128:$vec), (outs), (ins), @@ -281,6 +304,13 @@ defm SUB : SIMDBinaryFP; defm DIV : SIMDBinaryFP; +defm "" : SIMDNegInt; +defm "" : SIMDNegInt; +defm "" : SIMDNegInt; +defm "" : SIMDNegInt; +defm "" : SIMDNegFP; +defm "" : SIMDNegFP; + let isCommutable = 1 in { defm AND : SIMDBitwise; defm OR : SIMDBitwise; Index: llvm/trunk/test/CodeGen/WebAssembly/simd-arith.ll =================================================================== --- llvm/trunk/test/CodeGen/WebAssembly/simd-arith.ll +++ llvm/trunk/test/CodeGen/WebAssembly/simd-arith.ll @@ -46,6 +46,19 @@ ret <16 x i8> %a } +; CHECK-LABEL: neg_v16i8: +; NO-SIMD128-NOT: i8x16 +; SIMD128-NEXT: .param v128{{$}} +; SIMD128-NEXT: .result v128{{$}} +; SIMD128-NEXT: i8x16.neg $push0=, $0{{$}} +; SIMD128-NEXT: return $pop0{{$}} +define <16 x i8> @neg_v16i8(<16 x i8> %x) { + %a = sub <16 x i8> , + %x + ret <16 x i8> %a +} + ; CHECK-LABEL: and_v16i8: ; NO-SIMD128-NOT: v128 ; SIMD128-NEXT: .param v128, v128{{$}} @@ -129,6 +142,18 @@ ret <8 x i16> %a } +; CHECK-LABEL: neg_v8i16: +; NO-SIMD128-NOT: i16x8 +; SIMD128-NEXT: .param v128{{$}} +; SIMD128-NEXT: .result v128{{$}} +; SIMD128-NEXT: i16x8.neg $push0=, $0{{$}} +; SIMD128-NEXT: return $pop0{{$}} +define <8 x i16> @neg_v8i16(<8 x i16> %x) { + %a = sub <8 x i16> , + %x + ret <8 x i16> %a +} + ; CHECK-LABEL: and_v8i16: ; NO-SIMD128-NOT: v128 ; SIMD128-NEXT: .param v128, v128{{$}} @@ -210,6 +235,17 @@ ret <4 x i32> %a } +; CHECK-LABEL: neg_v4i32: +; NO-SIMD128-NOT: i32x4 +; SIMD128-NEXT: .param v128{{$}} +; SIMD128-NEXT: .result v128{{$}} +; SIMD128-NEXT: i32x4.neg $push0=, $0{{$}} +; SIMD128-NEXT: return $pop0{{$}} +define <4 x i32> @neg_v4i32(<4 x i32> %x) { + %a = sub <4 x i32> , %x + ret <4 x i32> %a +} + ; CHECK-LABEL: and_v4i32: ; NO-SIMD128-NOT: v128 ; SIMD128-NEXT: .param v128, v128{{$}} @@ -293,6 +329,17 @@ ret <2 x i64> %a } +; CHECK-LABEL: neg_v2i64: +; NO-SIMD128-NOT: i64x2 +; SIMD128-NEXT: .param v128{{$}} +; SIMD128-NEXT: .result v128{{$}} +; SIMD128-NEXT: i64x2.neg $push0=, $0{{$}} +; SIMD128-NEXT: return $pop0{{$}} +define <2 x i64> @neg_v2i64(<2 x i64> %x) { + %a = sub <2 x i64> , %x + ret <2 x i64> %a +} + ; CHECK-LABEL: and_v2i64: ; NO-SIMD128-NOT: v128 ; SIMD128-VM-NOT: v128 @@ -344,6 +391,17 @@ ; ============================================================================== ; 4 x float ; ============================================================================== +; CHECK-LABEL: neg_v4f32: +; NO-SIMD128-NOT: f32x4 +; SIMD128-NEXT: .param v128{{$}} +; SIMD128-NEXT: .result v128{{$}} +; SIMD128-NEXT: f32x4.neg $push0=, $0{{$}} +; SIMD128-NEXT: return $pop0{{$}} +define <4 x float> @neg_v4f32(<4 x float> %x) { + %a = fsub <4 x float> , %x + ret <4 x float> %a +} + ; CHECK-LABEL: add_v4f32: ; NO-SIMD128-NOT: f32x4 ; SIMD128-NEXT: .param v128, v128{{$}} @@ -391,6 +449,17 @@ ; ============================================================================== ; 2 x double ; ============================================================================== +; CHECK-LABEL: neg_v2f64: +; NO-SIMD128-NOT: f64x2 +; SIMD128-NEXT: .param v128{{$}} +; SIMD128-NEXT: .result v128{{$}} +; SIMD128-NEXT: f64x2.neg $push0=, $0{{$}} +; SIMD128-NEXT: return $pop0{{$}} +define <2 x double> @neg_v2f64(<2 x double> %x) { + %a = fsub <2 x double> , %x + ret <2 x double> %a +} + ; CHECK-LABEL: add_v2f64: ; NO-SIMD128-NOT: f64x2 ; SIMD128-VM-NOT: f62x2 Index: llvm/trunk/test/MC/WebAssembly/simd-encodings.s =================================================================== --- llvm/trunk/test/MC/WebAssembly/simd-encodings.s +++ llvm/trunk/test/MC/WebAssembly/simd-encodings.s @@ -133,6 +133,18 @@ # CHECK: i32x4.mul # encoding: [0xfd,0x22] i32x4.mul + # CHECK: i8x16.neg # encoding: [0xfd,0x23] + i8x16.neg + + # CHECK: i16x8.neg # encoding: [0xfd,0x24] + i16x8.neg + + # CHECK: i32x4.neg # encoding: [0xfd,0x25] + i32x4.neg + + # CHECK: i64x2.neg # encoding: [0xfd,0x26] + i64x2.neg + # CHECK: v128.and # encoding: [0xfd,0x3b] v128.and @@ -271,6 +283,12 @@ # CHECK: f64x2.ge # encoding: [0xfd,0x71] f64x2.ge + # CHECK: f32x4.neg # encoding: [0xfd,0x72] + f32x4.neg + + # CHECK: f64x2.neg # encoding: [0xfd,0x73] + f64x2.neg + # CHECK: f32x4.add # encoding: [0xfd,0x7a] f32x4.add