Skip to content

Commit cdc3732

Browse files
committed
[LoongArch] Mark ISD::FNEG as legal
1 parent 827f8a7 commit cdc3732

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
270270
setOperationAction({ISD::FMUL, ISD::FDIV}, VT, Legal);
271271
setOperationAction(ISD::FMA, VT, Legal);
272272
setOperationAction(ISD::FSQRT, VT, Legal);
273+
setOperationAction(ISD::FNEG, VT, Legal);
273274
setCondCodeAction({ISD::SETGE, ISD::SETGT, ISD::SETOGE, ISD::SETOGT,
274275
ISD::SETUGE, ISD::SETUGT},
275276
VT, Expand);
@@ -311,6 +312,7 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
311312
setOperationAction({ISD::FMUL, ISD::FDIV}, VT, Legal);
312313
setOperationAction(ISD::FMA, VT, Legal);
313314
setOperationAction(ISD::FSQRT, VT, Legal);
315+
setOperationAction(ISD::FNEG, VT, Legal);
314316
setCondCodeAction({ISD::SETGE, ISD::SETGT, ISD::SETOGE, ISD::SETOGT,
315317
ISD::SETUGE, ISD::SETUGT},
316318
VT, Expand);

llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,10 @@ foreach vt = [v32i8, v16i16, v8i32, v4i64, v8f32, v4f64] in
16051605
def : Pat<(vt (vselect LASX256:$xa, LASX256:$xk, LASX256:$xj)),
16061606
(XVBITSEL_V LASX256:$xj, LASX256:$xk, LASX256:$xa)>;
16071607

1608+
// fneg
1609+
def : Pat<(fneg (v8f32 LASX256:$xj)), (XVBITREVI_W LASX256:$xj, 31)>;
1610+
def : Pat<(fneg (v4f64 LASX256:$xj)), (XVBITREVI_D LASX256:$xj, 63)>;
1611+
16081612
} // Predicates = [HasExtLASX]
16091613

16101614
/// Intrinsic pattern

llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,10 @@ foreach vt = [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64] in
17121712
def : Pat<(vt (vselect LSX128:$va, LSX128:$vk, LSX128:$vj)),
17131713
(VBITSEL_V LSX128:$vj, LSX128:$vk, LSX128:$va)>;
17141714

1715+
// fneg
1716+
def : Pat<(fneg (v4f32 LSX128:$vj)), (VBITREVI_W LSX128:$vj, 31)>;
1717+
def : Pat<(fneg (v2f64 LSX128:$vj)), (VBITREVI_D LSX128:$vj, 63)>;
1718+
17151719
} // Predicates = [HasExtLSX]
17161720

17171721
/// Intrinsic pattern
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc --mtriple=loongarch64 --mattr=+lasx < %s | FileCheck %s
3+
4+
define void @fneg_v8f32(ptr %res, ptr %a0) nounwind {
5+
; CHECK-LABEL: fneg_v8f32:
6+
; CHECK: # %bb.0: # %entry
7+
; CHECK-NEXT: xvld $xr0, $a1, 0
8+
; CHECK-NEXT: xvbitrevi.w $xr0, $xr0, 31
9+
; CHECK-NEXT: xvst $xr0, $a0, 0
10+
; CHECK-NEXT: ret
11+
entry:
12+
%v0 = load <8 x float>, ptr %a0
13+
%v1 = fneg <8 x float> %v0
14+
store <8 x float> %v1, ptr %res
15+
ret void
16+
}
17+
define void @fneg_v4f64(ptr %res, ptr %a0) nounwind {
18+
; CHECK-LABEL: fneg_v4f64:
19+
; CHECK: # %bb.0: # %entry
20+
; CHECK-NEXT: xvld $xr0, $a1, 0
21+
; CHECK-NEXT: xvbitrevi.d $xr0, $xr0, 63
22+
; CHECK-NEXT: xvst $xr0, $a0, 0
23+
; CHECK-NEXT: ret
24+
entry:
25+
%v0 = load <4 x double>, ptr %a0
26+
%v1 = fneg <4 x double> %v0
27+
store <4 x double> %v1, ptr %res
28+
ret void
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc --mtriple=loongarch64 --mattr=+lsx < %s | FileCheck %s
3+
4+
define void @fneg_v4f32(ptr %res, ptr %a0) nounwind {
5+
; CHECK-LABEL: fneg_v4f32:
6+
; CHECK: # %bb.0: # %entry
7+
; CHECK-NEXT: vld $vr0, $a1, 0
8+
; CHECK-NEXT: vbitrevi.w $vr0, $vr0, 31
9+
; CHECK-NEXT: vst $vr0, $a0, 0
10+
; CHECK-NEXT: ret
11+
entry:
12+
%v0 = load <4 x float>, ptr %a0
13+
%v1 = fneg <4 x float> %v0
14+
store <4 x float> %v1, ptr %res
15+
ret void
16+
}
17+
define void @fneg_v2f64(ptr %res, ptr %a0) nounwind {
18+
; CHECK-LABEL: fneg_v2f64:
19+
; CHECK: # %bb.0: # %entry
20+
; CHECK-NEXT: vld $vr0, $a1, 0
21+
; CHECK-NEXT: vbitrevi.d $vr0, $vr0, 63
22+
; CHECK-NEXT: vst $vr0, $a0, 0
23+
; CHECK-NEXT: ret
24+
entry:
25+
%v0 = load <2 x double>, ptr %a0
26+
%v1 = fneg <2 x double> %v0
27+
store <2 x double> %v1, ptr %res
28+
ret void
29+
}

0 commit comments

Comments
 (0)