Skip to content

Commit e3b49df

Browse files
Petar AvramovicPetar Avramovic
authored andcommitted
[MIPS GlobalISel] Select MSA vector generic and builtin fabs
selectImpl is able to select G_FABS when we set bank for vector operands to fprb. Add detailed tests. Note: G_FABS is generated from llvm-ir intrinsics llvm.fabs.*, and at the moment MIPS is not able to generate this intrinsic for vector type (some targets generate vector llvm.fabs.* from calls to a builtin function). We can handle fabs using __builtin_msa_fmax_a_<format> and passing same vector as both arguments. __builtin_msa_fmax_a_<format> will be directly selected into FMAX_A_<format> in legalizeIntrinsic. Differential Revision: https://reviews.llvm.org/D69346
1 parent 1ae8e8d commit e3b49df

File tree

8 files changed

+309
-3
lines changed

8 files changed

+309
-3
lines changed

llvm/lib/Target/Mips/MipsLegalizerInfo.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ MipsLegalizerInfo::MipsLegalizerInfo(const MipsSubtarget &ST) {
188188
getActionDefinitionsBuilder(G_FCONSTANT)
189189
.legalFor({s32, s64});
190190

191-
getActionDefinitionsBuilder({G_FABS, G_FSQRT})
191+
getActionDefinitionsBuilder(G_FSQRT)
192192
.legalFor({s32, s64});
193193

194-
getActionDefinitionsBuilder({G_FADD, G_FSUB, G_FMUL, G_FDIV})
194+
getActionDefinitionsBuilder({G_FADD, G_FSUB, G_FMUL, G_FDIV, G_FABS})
195195
.legalIf([=, &ST](const LegalityQuery &Query) {
196196
if (CheckTyN(0, Query, {s32, s64}))
197197
return true;
@@ -425,6 +425,10 @@ bool MipsLegalizerInfo::legalizeIntrinsic(MachineInstr &MI,
425425
case Intrinsic::mips_fdiv_w:
426426
case Intrinsic::mips_fdiv_d:
427427
return MSA3OpIntrinsicToGeneric(MI, TargetOpcode::G_FDIV, MIRBuilder, ST);
428+
case Intrinsic::mips_fmax_a_w:
429+
return SelectMSA3OpIntrinsic(MI, Mips::FMAX_A_W, MIRBuilder, ST);
430+
case Intrinsic::mips_fmax_a_d:
431+
return SelectMSA3OpIntrinsic(MI, Mips::FMAX_A_D, MIRBuilder, ST);
428432
default:
429433
break;
430434
}

llvm/lib/Target/Mips/MipsRegisterBankInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,14 +539,14 @@ MipsRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
539539
&Mips::ValueMappings[Mips::GPRIdx]});
540540
MappingID = CustomMappingID;
541541
break;
542-
case G_FABS:
543542
case G_FSQRT:
544543
OperandsMapping = getFprbMapping(Op0Size);
545544
break;
546545
case G_FADD:
547546
case G_FSUB:
548547
case G_FMUL:
549548
case G_FDIV:
549+
case G_FABS:
550550
OperandsMapping = getFprbMapping(Op0Size);
551551
if (Op0Size == 128)
552552
OperandsMapping = getMSAMapping(MF);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -mtriple=mipsel-linux-gnu -mcpu=mips32r5 -mattr=+msa,+fp64,+nan2008 -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s -check-prefixes=P5600
3+
--- |
4+
5+
define void @fabs_v4f32(<4 x float>* %a, <4 x float>* %c) { entry: ret void }
6+
define void @fabs_v2f64(<2 x double>* %a, <2 x double>* %c) { entry: ret void }
7+
8+
...
9+
---
10+
name: fabs_v4f32
11+
alignment: 4
12+
legalized: true
13+
regBankSelected: true
14+
tracksRegLiveness: true
15+
body: |
16+
bb.1.entry:
17+
liveins: $a0, $a1
18+
19+
; P5600-LABEL: name: fabs_v4f32
20+
; P5600: liveins: $a0, $a1
21+
; P5600: [[COPY:%[0-9]+]]:gpr32 = COPY $a0
22+
; P5600: [[COPY1:%[0-9]+]]:gpr32 = COPY $a1
23+
; P5600: [[LD_W:%[0-9]+]]:msa128w = LD_W [[COPY]], 0 :: (load 16 from %ir.a)
24+
; P5600: [[FABS_W:%[0-9]+]]:msa128w = FABS_W [[LD_W]]
25+
; P5600: ST_W [[FABS_W]], [[COPY1]], 0 :: (store 16 into %ir.c)
26+
; P5600: RetRA
27+
%0:gprb(p0) = COPY $a0
28+
%1:gprb(p0) = COPY $a1
29+
%2:fprb(<4 x s32>) = G_LOAD %0(p0) :: (load 16 from %ir.a)
30+
%3:fprb(<4 x s32>) = G_FABS %2
31+
G_STORE %3(<4 x s32>), %1(p0) :: (store 16 into %ir.c)
32+
RetRA
33+
34+
...
35+
---
36+
name: fabs_v2f64
37+
alignment: 4
38+
legalized: true
39+
regBankSelected: true
40+
tracksRegLiveness: true
41+
body: |
42+
bb.1.entry:
43+
liveins: $a0, $a1
44+
45+
; P5600-LABEL: name: fabs_v2f64
46+
; P5600: liveins: $a0, $a1
47+
; P5600: [[COPY:%[0-9]+]]:gpr32 = COPY $a0
48+
; P5600: [[COPY1:%[0-9]+]]:gpr32 = COPY $a1
49+
; P5600: [[LD_D:%[0-9]+]]:msa128d = LD_D [[COPY]], 0 :: (load 16 from %ir.a)
50+
; P5600: [[FABS_D:%[0-9]+]]:msa128d = FABS_D [[LD_D]]
51+
; P5600: ST_D [[FABS_D]], [[COPY1]], 0 :: (store 16 into %ir.c)
52+
; P5600: RetRA
53+
%0:gprb(p0) = COPY $a0
54+
%1:gprb(p0) = COPY $a1
55+
%2:fprb(<2 x s64>) = G_LOAD %0(p0) :: (load 16 from %ir.a)
56+
%3:fprb(<2 x s64>) = G_FABS %2
57+
G_STORE %3(<2 x s64>), %1(p0) :: (store 16 into %ir.c)
58+
RetRA
59+
60+
...
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -mtriple=mipsel-linux-gnu -mcpu=mips32r5 -mattr=+msa,+fp64,+nan2008 -run-pass=legalizer -verify-machineinstrs %s -o - | FileCheck %s -check-prefixes=P5600
3+
--- |
4+
5+
define void @fabs_v4f32(<4 x float>* %a, <4 x float>* %c) { entry: ret void }
6+
define void @fabs_v2f64(<2 x double>* %a, <2 x double>* %c) { entry: ret void }
7+
8+
...
9+
---
10+
name: fabs_v4f32
11+
alignment: 4
12+
tracksRegLiveness: true
13+
body: |
14+
bb.1.entry:
15+
liveins: $a0, $a1
16+
17+
; P5600-LABEL: name: fabs_v4f32
18+
; P5600: liveins: $a0, $a1
19+
; P5600: [[COPY:%[0-9]+]]:_(p0) = COPY $a0
20+
; P5600: [[COPY1:%[0-9]+]]:_(p0) = COPY $a1
21+
; P5600: [[LOAD:%[0-9]+]]:_(<4 x s32>) = G_LOAD [[COPY]](p0) :: (load 16 from %ir.a)
22+
; P5600: [[FABS:%[0-9]+]]:_(<4 x s32>) = G_FABS [[LOAD]]
23+
; P5600: G_STORE [[FABS]](<4 x s32>), [[COPY1]](p0) :: (store 16 into %ir.c)
24+
; P5600: RetRA
25+
%0:_(p0) = COPY $a0
26+
%1:_(p0) = COPY $a1
27+
%2:_(<4 x s32>) = G_LOAD %0(p0) :: (load 16 from %ir.a)
28+
%3:_(<4 x s32>) = G_FABS %2
29+
G_STORE %3(<4 x s32>), %1(p0) :: (store 16 into %ir.c)
30+
RetRA
31+
32+
...
33+
---
34+
name: fabs_v2f64
35+
alignment: 4
36+
tracksRegLiveness: true
37+
body: |
38+
bb.1.entry:
39+
liveins: $a0, $a1
40+
41+
; P5600-LABEL: name: fabs_v2f64
42+
; P5600: liveins: $a0, $a1
43+
; P5600: [[COPY:%[0-9]+]]:_(p0) = COPY $a0
44+
; P5600: [[COPY1:%[0-9]+]]:_(p0) = COPY $a1
45+
; P5600: [[LOAD:%[0-9]+]]:_(<2 x s64>) = G_LOAD [[COPY]](p0) :: (load 16 from %ir.a)
46+
; P5600: [[FABS:%[0-9]+]]:_(<2 x s64>) = G_FABS [[LOAD]]
47+
; P5600: G_STORE [[FABS]](<2 x s64>), [[COPY1]](p0) :: (store 16 into %ir.c)
48+
; P5600: RetRA
49+
%0:_(p0) = COPY $a0
50+
%1:_(p0) = COPY $a1
51+
%2:_(<2 x s64>) = G_LOAD %0(p0) :: (load 16 from %ir.a)
52+
%3:_(<2 x s64>) = G_FABS %2
53+
G_STORE %3(<2 x s64>), %1(p0) :: (store 16 into %ir.c)
54+
RetRA
55+
56+
...
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -mtriple=mipsel-linux-gnu -mcpu=mips32r5 -mattr=+msa,+fp64,+nan2008 -run-pass=legalizer -verify-machineinstrs %s -o - | FileCheck %s -check-prefixes=P5600
3+
--- |
4+
5+
declare <4 x float> @llvm.mips.fmax.a.w(<4 x float>, <4 x float>)
6+
define void @fabs_v4f32_builtin(<4 x float>* %a, <4 x float>* %c) { entry: ret void }
7+
8+
declare <2 x double> @llvm.mips.fmax.a.d(<2 x double>, <2 x double>)
9+
define void @fabs_v2f64_builtin(<2 x double>* %a, <2 x double>* %c) { entry: ret void }
10+
11+
...
12+
---
13+
name: fabs_v4f32_builtin
14+
alignment: 4
15+
tracksRegLiveness: true
16+
body: |
17+
bb.1.entry:
18+
liveins: $a0, $a1
19+
20+
; P5600-LABEL: name: fabs_v4f32_builtin
21+
; P5600: liveins: $a0, $a1
22+
; P5600: [[COPY:%[0-9]+]]:_(p0) = COPY $a0
23+
; P5600: [[COPY1:%[0-9]+]]:_(p0) = COPY $a1
24+
; P5600: [[LOAD:%[0-9]+]]:msa128w(<4 x s32>) = G_LOAD [[COPY]](p0) :: (load 16 from %ir.a)
25+
; P5600: [[FMAX_A_W:%[0-9]+]]:msa128w(<4 x s32>) = FMAX_A_W [[LOAD]](<4 x s32>), [[LOAD]](<4 x s32>)
26+
; P5600: G_STORE [[FMAX_A_W]](<4 x s32>), [[COPY1]](p0) :: (store 16 into %ir.c)
27+
; P5600: RetRA
28+
%0:_(p0) = COPY $a0
29+
%1:_(p0) = COPY $a1
30+
%2:_(<4 x s32>) = G_LOAD %0(p0) :: (load 16 from %ir.a)
31+
%3:_(<4 x s32>) = G_INTRINSIC intrinsic(@llvm.mips.fmax.a.w), %2(<4 x s32>), %2(<4 x s32>)
32+
G_STORE %3(<4 x s32>), %1(p0) :: (store 16 into %ir.c)
33+
RetRA
34+
35+
...
36+
---
37+
name: fabs_v2f64_builtin
38+
alignment: 4
39+
tracksRegLiveness: true
40+
body: |
41+
bb.1.entry:
42+
liveins: $a0, $a1
43+
44+
; P5600-LABEL: name: fabs_v2f64_builtin
45+
; P5600: liveins: $a0, $a1
46+
; P5600: [[COPY:%[0-9]+]]:_(p0) = COPY $a0
47+
; P5600: [[COPY1:%[0-9]+]]:_(p0) = COPY $a1
48+
; P5600: [[LOAD:%[0-9]+]]:msa128d(<2 x s64>) = G_LOAD [[COPY]](p0) :: (load 16 from %ir.a)
49+
; P5600: [[FMAX_A_D:%[0-9]+]]:msa128d(<2 x s64>) = FMAX_A_D [[LOAD]](<2 x s64>), [[LOAD]](<2 x s64>)
50+
; P5600: G_STORE [[FMAX_A_D]](<2 x s64>), [[COPY1]](p0) :: (store 16 into %ir.c)
51+
; P5600: RetRA
52+
%0:_(p0) = COPY $a0
53+
%1:_(p0) = COPY $a1
54+
%2:_(<2 x s64>) = G_LOAD %0(p0) :: (load 16 from %ir.a)
55+
%3:_(<2 x s64>) = G_INTRINSIC intrinsic(@llvm.mips.fmax.a.d), %2(<2 x s64>), %2(<2 x s64>)
56+
G_STORE %3(<2 x s64>), %1(p0) :: (store 16 into %ir.c)
57+
RetRA
58+
59+
...
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -O0 -mtriple=mipsel-linux-gnu -global-isel -mcpu=mips32r5 -mattr=+msa,+fp64,+nan2008 -verify-machineinstrs %s -o -| FileCheck %s -check-prefixes=P5600
3+
4+
declare <4 x float> @llvm.fabs.v4f32(<4 x float> %Val)
5+
define void @fabs_v4f32(<4 x float>* %a, <4 x float>* %c) {
6+
; P5600-LABEL: fabs_v4f32:
7+
; P5600: # %bb.0: # %entry
8+
; P5600-NEXT: ld.w $w0, 0($4)
9+
; P5600-NEXT: fmax_a.w $w0, $w0, $w0
10+
; P5600-NEXT: st.w $w0, 0($5)
11+
; P5600-NEXT: jr $ra
12+
; P5600-NEXT: nop
13+
entry:
14+
%0 = load <4 x float>, <4 x float>* %a, align 16
15+
%fabs = call <4 x float> @llvm.fabs.v4f32 (<4 x float> %0)
16+
store <4 x float> %fabs, <4 x float>* %c, align 16
17+
ret void
18+
}
19+
20+
declare <2 x double> @llvm.fabs.v2f64(<2 x double> %Val)
21+
define void @fabs_v2f64(<2 x double>* %a, <2 x double>* %c) {
22+
; P5600-LABEL: fabs_v2f64:
23+
; P5600: # %bb.0: # %entry
24+
; P5600-NEXT: ld.d $w0, 0($4)
25+
; P5600-NEXT: fmax_a.d $w0, $w0, $w0
26+
; P5600-NEXT: st.d $w0, 0($5)
27+
; P5600-NEXT: jr $ra
28+
; P5600-NEXT: nop
29+
entry:
30+
%0 = load <2 x double>, <2 x double>* %a, align 16
31+
%fabs = call <2 x double> @llvm.fabs.v2f64 (<2 x double> %0)
32+
store <2 x double> %fabs, <2 x double>* %c, align 16
33+
ret void
34+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -O0 -mtriple=mipsel-linux-gnu -global-isel -mcpu=mips32r5 -mattr=+msa,+fp64,+nan2008 -verify-machineinstrs %s -o -| FileCheck %s -check-prefixes=P5600
3+
4+
declare <4 x float> @llvm.mips.fmax.a.w(<4 x float>, <4 x float>)
5+
define void @fabs_v4f32_builtin(<4 x float>* %a, <4 x float>* %c) {
6+
; P5600-LABEL: fabs_v4f32_builtin:
7+
; P5600: # %bb.0: # %entry
8+
; P5600-NEXT: ld.w $w0, 0($4)
9+
; P5600-NEXT: fmax_a.w $w0, $w0, $w0
10+
; P5600-NEXT: st.w $w0, 0($5)
11+
; P5600-NEXT: jr $ra
12+
; P5600-NEXT: nop
13+
entry:
14+
%0 = load <4 x float>, <4 x float>* %a, align 16
15+
%1 = tail call <4 x float> @llvm.mips.fmax.a.w(<4 x float> %0, <4 x float> %0)
16+
store <4 x float> %1, <4 x float>* %c, align 16
17+
ret void
18+
}
19+
20+
21+
declare <2 x double> @llvm.mips.fmax.a.d(<2 x double>, <2 x double>)
22+
define void @fabs_v2f64_builtin(<2 x double>* %a, <2 x double>* %c) {
23+
; P5600-LABEL: fabs_v2f64_builtin:
24+
; P5600: # %bb.0: # %entry
25+
; P5600-NEXT: ld.d $w0, 0($4)
26+
; P5600-NEXT: fmax_a.d $w0, $w0, $w0
27+
; P5600-NEXT: st.d $w0, 0($5)
28+
; P5600-NEXT: jr $ra
29+
; P5600-NEXT: nop
30+
entry:
31+
%0 = load <2 x double>, <2 x double>* %a, align 16
32+
%1 = tail call <2 x double> @llvm.mips.fmax.a.d(<2 x double> %0, <2 x double> %0)
33+
store <2 x double> %1, <2 x double>* %c, align 16
34+
ret void
35+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -mtriple=mipsel-linux-gnu -mcpu=mips32r5 -mattr=+msa,+fp64,+nan2008 -run-pass=regbankselect -verify-machineinstrs %s -o - | FileCheck %s -check-prefixes=P5600
3+
--- |
4+
5+
define void @fabs_v4f32(<4 x float>* %a, <4 x float>* %c) { entry: ret void }
6+
define void @fabs_v2f64(<2 x double>* %a, <2 x double>* %c) { entry: ret void }
7+
8+
...
9+
---
10+
name: fabs_v4f32
11+
alignment: 4
12+
legalized: true
13+
tracksRegLiveness: true
14+
body: |
15+
bb.1.entry:
16+
liveins: $a0, $a1
17+
18+
; P5600-LABEL: name: fabs_v4f32
19+
; P5600: liveins: $a0, $a1
20+
; P5600: [[COPY:%[0-9]+]]:gprb(p0) = COPY $a0
21+
; P5600: [[COPY1:%[0-9]+]]:gprb(p0) = COPY $a1
22+
; P5600: [[LOAD:%[0-9]+]]:fprb(<4 x s32>) = G_LOAD [[COPY]](p0) :: (load 16 from %ir.a)
23+
; P5600: [[FABS:%[0-9]+]]:fprb(<4 x s32>) = G_FABS [[LOAD]]
24+
; P5600: G_STORE [[FABS]](<4 x s32>), [[COPY1]](p0) :: (store 16 into %ir.c)
25+
; P5600: RetRA
26+
%0:_(p0) = COPY $a0
27+
%1:_(p0) = COPY $a1
28+
%2:_(<4 x s32>) = G_LOAD %0(p0) :: (load 16 from %ir.a)
29+
%3:_(<4 x s32>) = G_FABS %2
30+
G_STORE %3(<4 x s32>), %1(p0) :: (store 16 into %ir.c)
31+
RetRA
32+
33+
...
34+
---
35+
name: fabs_v2f64
36+
alignment: 4
37+
legalized: true
38+
tracksRegLiveness: true
39+
body: |
40+
bb.1.entry:
41+
liveins: $a0, $a1
42+
43+
; P5600-LABEL: name: fabs_v2f64
44+
; P5600: liveins: $a0, $a1
45+
; P5600: [[COPY:%[0-9]+]]:gprb(p0) = COPY $a0
46+
; P5600: [[COPY1:%[0-9]+]]:gprb(p0) = COPY $a1
47+
; P5600: [[LOAD:%[0-9]+]]:fprb(<2 x s64>) = G_LOAD [[COPY]](p0) :: (load 16 from %ir.a)
48+
; P5600: [[FABS:%[0-9]+]]:fprb(<2 x s64>) = G_FABS [[LOAD]]
49+
; P5600: G_STORE [[FABS]](<2 x s64>), [[COPY1]](p0) :: (store 16 into %ir.c)
50+
; P5600: RetRA
51+
%0:_(p0) = COPY $a0
52+
%1:_(p0) = COPY $a1
53+
%2:_(<2 x s64>) = G_LOAD %0(p0) :: (load 16 from %ir.a)
54+
%3:_(<2 x s64>) = G_FABS %2
55+
G_STORE %3(<2 x s64>), %1(p0) :: (store 16 into %ir.c)
56+
RetRA
57+
58+
...

0 commit comments

Comments
 (0)