Skip to content

Commit dd11796

Browse files
committed
Added support for negative multiply add
1 parent 858b22e commit dd11796

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

llvm/include/llvm/Target/TargetSelectionDAG.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,9 @@ def fadd_contract : PatFrag<(ops node:$a, node:$b), (fadd node:$a, node:$b),[{
11471147
return N->getFlags().hasAllowContract();
11481148
}]>;
11491149

1150+
def fsub_contract : PatFrag<(ops node:$a, node:$b), (fsub node:$a, node:$b),[{
1151+
return N->getFlags().hasAllowContract();
1152+
}]>;
11501153

11511154
def not : PatFrag<(ops node:$in), (xor node:$in, -1)>;
11521155
def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;

llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,8 @@ multiclass SIMDMADD<Vec vec, bits<32> simdopA, bits<32> simdopS, list<Predicate>
15401540
def : Pat<(fadd_contract (vec.vt V128:$a), (fmul_contract (vec.vt V128:$b), (vec.vt V128:$c))),
15411541
(!cast<Instruction>("MADD_"#vec) V128:$a, V128:$b, V128:$c)>, Requires<[HasRelaxedSIMD]>;
15421542

1543+
def : Pat<(fsub_contract (vec.vt V128:$a), (fmul_contract (vec.vt V128:$b), (vec.vt V128:$c))),
1544+
(!cast<Instruction>("NMADD_"#vec) V128:$a, V128:$b, V128:$c)>, Requires<[HasRelaxedSIMD]>;
15431545
}
15441546

15451547
defm "" : SIMDMADD<F32x4, 0x105, 0x106, [HasRelaxedSIMD]>;

llvm/test/CodeGen/WebAssembly/simd-relaxed-fnma.ll

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ define <4 x float> @fsub_fmul_contract_4xf32(<4 x float> %a, <4 x float> %b, <4
2727
; RELAXED-LABEL: fsub_fmul_contract_4xf32:
2828
; RELAXED: .functype fsub_fmul_contract_4xf32 (v128, v128, v128) -> (v128)
2929
; RELAXED-NEXT: # %bb.0:
30-
; RELAXED-NEXT: f32x4.mul $push0=, $1, $0
31-
; RELAXED-NEXT: f32x4.sub $push1=, $2, $pop0
32-
; RELAXED-NEXT: return $pop1
30+
; RELAXED-NEXT: f32x4.relaxed_nmadd $push0=, $2, $1, $0
31+
; RELAXED-NEXT: return $pop0
3332
;
3433
; STRICT-LABEL: fsub_fmul_contract_4xf32:
3534
; STRICT: .functype fsub_fmul_contract_4xf32 (v128, v128, v128) -> (v128)
@@ -47,9 +46,8 @@ define <8 x half> @fsub_fmul_contract_8xf16(<8 x half> %a, <8 x half> %b, <8 x h
4746
; RELAXED-LABEL: fsub_fmul_contract_8xf16:
4847
; RELAXED: .functype fsub_fmul_contract_8xf16 (v128, v128, v128) -> (v128)
4948
; RELAXED-NEXT: # %bb.0:
50-
; RELAXED-NEXT: f16x8.mul $push0=, $1, $0
51-
; RELAXED-NEXT: f16x8.sub $push1=, $2, $pop0
52-
; RELAXED-NEXT: return $pop1
49+
; RELAXED-NEXT: f16x8.relaxed_nmadd $push0=, $2, $1, $0
50+
; RELAXED-NEXT: return $pop0
5351
;
5452
; STRICT-LABEL: fsub_fmul_contract_8xf16:
5553
; STRICT: .functype fsub_fmul_contract_8xf16 (v128, v128, v128) -> (v128)
@@ -86,12 +84,10 @@ define <8 x float> @fsub_fmul_contract_8xf32(<8 x float> %a, <8 x float> %b, <8
8684
; RELAXED-LABEL: fsub_fmul_contract_8xf32:
8785
; RELAXED: .functype fsub_fmul_contract_8xf32 (i32, v128, v128, v128, v128, v128, v128) -> ()
8886
; RELAXED-NEXT: # %bb.0:
89-
; RELAXED-NEXT: f32x4.mul $push0=, $4, $2
90-
; RELAXED-NEXT: f32x4.sub $push1=, $6, $pop0
91-
; RELAXED-NEXT: v128.store 16($0), $pop1
92-
; RELAXED-NEXT: f32x4.mul $push2=, $3, $1
93-
; RELAXED-NEXT: f32x4.sub $push3=, $5, $pop2
94-
; RELAXED-NEXT: v128.store 0($0), $pop3
87+
; RELAXED-NEXT: f32x4.relaxed_nmadd $push0=, $6, $4, $2
88+
; RELAXED-NEXT: v128.store 16($0), $pop0
89+
; RELAXED-NEXT: f32x4.relaxed_nmadd $push1=, $5, $3, $1
90+
; RELAXED-NEXT: v128.store 0($0), $pop1
9591
; RELAXED-NEXT: return
9692
;
9793
; STRICT-LABEL: fsub_fmul_contract_8xf32:
@@ -114,9 +110,8 @@ define <2 x double> @fsub_fmul_contract_2xf64(<2 x double> %a, <2 x double> %b,
114110
; RELAXED-LABEL: fsub_fmul_contract_2xf64:
115111
; RELAXED: .functype fsub_fmul_contract_2xf64 (v128, v128, v128) -> (v128)
116112
; RELAXED-NEXT: # %bb.0:
117-
; RELAXED-NEXT: f64x2.mul $push0=, $1, $0
118-
; RELAXED-NEXT: f64x2.sub $push1=, $2, $pop0
119-
; RELAXED-NEXT: return $pop1
113+
; RELAXED-NEXT: f64x2.relaxed_nmadd $push0=, $2, $1, $0
114+
; RELAXED-NEXT: return $pop0
120115
;
121116
; STRICT-LABEL: fsub_fmul_contract_2xf64:
122117
; STRICT: .functype fsub_fmul_contract_2xf64 (v128, v128, v128) -> (v128)

0 commit comments

Comments
 (0)