Skip to content

Commit 81132ce

Browse files
Petar AvramovicPetar Avramovic
Petar Avramovic
authored and
Petar Avramovic
committedJun 6, 2019
[MIPS GlobalISel] Select sqrt
Select G_FSQRT for MIPS32. Differential Revision: https://reviews.llvm.org/D62905 llvm-svn: 362692
1 parent cff7d2f commit 81132ce

File tree

6 files changed

+219
-2
lines changed

6 files changed

+219
-2
lines changed
 

‎llvm/lib/Target/Mips/MipsLegalizerInfo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ MipsLegalizerInfo::MipsLegalizerInfo(const MipsSubtarget &ST) {
9494
getActionDefinitionsBuilder(G_FCONSTANT)
9595
.legalFor({s32, s64});
9696

97-
getActionDefinitionsBuilder({G_FADD, G_FSUB, G_FMUL, G_FDIV, G_FABS})
97+
getActionDefinitionsBuilder({G_FADD, G_FSUB, G_FMUL, G_FDIV, G_FABS, G_FSQRT})
9898
.legalFor({s32, s64});
9999

100100
getActionDefinitionsBuilder(G_FCMP)

‎llvm/lib/Target/Mips/MipsRegisterBankInfo.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ MipsRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
134134
case G_FSUB:
135135
case G_FMUL:
136136
case G_FDIV:
137-
case G_FABS: {
137+
case G_FABS:
138+
case G_FSQRT:{
138139
unsigned Size = MRI.getType(MI.getOperand(0).getReg()).getSizeInBits();
139140
assert((Size == 32 || Size == 64) && "Unsupported floating point size");
140141
OperandsMapping = Size == 32 ? &Mips::ValueMappings[Mips::SPRIdx]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -O0 -mtriple=mipsel-linux-gnu -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s -check-prefixes=FP32
3+
# RUN: llc -O0 -mtriple=mipsel-linux-gnu -mattr=+fp64,+mips32r2 -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s -check-prefixes=FP64
4+
--- |
5+
6+
define void @sqrt_f32() {entry: ret void}
7+
define void @sqrt_f64() {entry: ret void}
8+
9+
...
10+
---
11+
name: sqrt_f32
12+
alignment: 2
13+
legalized: true
14+
regBankSelected: true
15+
tracksRegLiveness: true
16+
body: |
17+
bb.1.entry:
18+
liveins: $f12
19+
20+
; FP32-LABEL: name: sqrt_f32
21+
; FP32: liveins: $f12
22+
; FP32: [[COPY:%[0-9]+]]:fgr32 = COPY $f12
23+
; FP32: [[FSQRT_S:%[0-9]+]]:fgr32 = FSQRT_S [[COPY]]
24+
; FP32: $f0 = COPY [[FSQRT_S]]
25+
; FP32: RetRA implicit $f0
26+
; FP64-LABEL: name: sqrt_f32
27+
; FP64: liveins: $f12
28+
; FP64: [[COPY:%[0-9]+]]:fgr32 = COPY $f12
29+
; FP64: [[FSQRT_S:%[0-9]+]]:fgr32 = FSQRT_S [[COPY]]
30+
; FP64: $f0 = COPY [[FSQRT_S]]
31+
; FP64: RetRA implicit $f0
32+
%0:fprb(s32) = COPY $f12
33+
%1:fprb(s32) = G_FSQRT %0
34+
$f0 = COPY %1(s32)
35+
RetRA implicit $f0
36+
37+
...
38+
---
39+
name: sqrt_f64
40+
alignment: 2
41+
legalized: true
42+
regBankSelected: true
43+
tracksRegLiveness: true
44+
body: |
45+
bb.1.entry:
46+
liveins: $d6
47+
48+
; FP32-LABEL: name: sqrt_f64
49+
; FP32: liveins: $d6
50+
; FP32: [[COPY:%[0-9]+]]:afgr64 = COPY $d6
51+
; FP32: [[FSQRT_D32_:%[0-9]+]]:afgr64 = FSQRT_D32 [[COPY]]
52+
; FP32: $d0 = COPY [[FSQRT_D32_]]
53+
; FP32: RetRA implicit $d0
54+
; FP64-LABEL: name: sqrt_f64
55+
; FP64: liveins: $d6
56+
; FP64: [[COPY:%[0-9]+]]:fgr64 = COPY $d6
57+
; FP64: [[FSQRT_D64_:%[0-9]+]]:fgr64 = FSQRT_D64 [[COPY]]
58+
; FP64: $d0 = COPY [[FSQRT_D64_]]
59+
; FP64: RetRA implicit $d0
60+
%0:fprb(s64) = COPY $d6
61+
%1:fprb(s64) = G_FSQRT %0
62+
$d0 = COPY %1(s64)
63+
RetRA implicit $d0
64+
65+
...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -O0 -mtriple=mipsel-linux-gnu -run-pass=legalizer -verify-machineinstrs %s -o - | FileCheck %s -check-prefixes=FP32
3+
# RUN: llc -O0 -mtriple=mipsel-linux-gnu -mattr=+fp64,+mips32r2 -run-pass=legalizer -verify-machineinstrs %s -o - | FileCheck %s -check-prefixes=FP64
4+
--- |
5+
6+
define void @sqrt_f32() {entry: ret void}
7+
define void @sqrt_f64() {entry: ret void}
8+
9+
...
10+
---
11+
name: sqrt_f32
12+
alignment: 2
13+
tracksRegLiveness: true
14+
body: |
15+
bb.1.entry:
16+
liveins: $f12
17+
18+
; FP32-LABEL: name: sqrt_f32
19+
; FP32: liveins: $f12
20+
; FP32: [[COPY:%[0-9]+]]:_(s32) = COPY $f12
21+
; FP32: [[FSQRT:%[0-9]+]]:_(s32) = G_FSQRT [[COPY]]
22+
; FP32: $f0 = COPY [[FSQRT]](s32)
23+
; FP32: RetRA implicit $f0
24+
; FP64-LABEL: name: sqrt_f32
25+
; FP64: liveins: $f12
26+
; FP64: [[COPY:%[0-9]+]]:_(s32) = COPY $f12
27+
; FP64: [[FSQRT:%[0-9]+]]:_(s32) = G_FSQRT [[COPY]]
28+
; FP64: $f0 = COPY [[FSQRT]](s32)
29+
; FP64: RetRA implicit $f0
30+
%0:_(s32) = COPY $f12
31+
%1:_(s32) = G_FSQRT %0
32+
$f0 = COPY %1(s32)
33+
RetRA implicit $f0
34+
35+
...
36+
---
37+
name: sqrt_f64
38+
alignment: 2
39+
tracksRegLiveness: true
40+
body: |
41+
bb.1.entry:
42+
liveins: $d6
43+
44+
; FP32-LABEL: name: sqrt_f64
45+
; FP32: liveins: $d6
46+
; FP32: [[COPY:%[0-9]+]]:_(s64) = COPY $d6
47+
; FP32: [[FSQRT:%[0-9]+]]:_(s64) = G_FSQRT [[COPY]]
48+
; FP32: $d0 = COPY [[FSQRT]](s64)
49+
; FP32: RetRA implicit $d0
50+
; FP64-LABEL: name: sqrt_f64
51+
; FP64: liveins: $d6
52+
; FP64: [[COPY:%[0-9]+]]:_(s64) = COPY $d6
53+
; FP64: [[FSQRT:%[0-9]+]]:_(s64) = G_FSQRT [[COPY]]
54+
; FP64: $d0 = COPY [[FSQRT]](s64)
55+
; FP64: RetRA implicit $d0
56+
%0:_(s64) = COPY $d6
57+
%1:_(s64) = G_FSQRT %0
58+
$d0 = COPY %1(s64)
59+
RetRA implicit $d0
60+
61+
...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -O0 -mtriple=mipsel-linux-gnu -global-isel -verify-machineinstrs %s -o -| FileCheck %s -check-prefixes=MIPS32,FP32
3+
; RUN: llc -O0 -mtriple=mipsel-linux-gnu -mattr=+fp64,+mips32r2 -global-isel -verify-machineinstrs %s -o -| FileCheck %s -check-prefixes=MIPS32,FP64
4+
5+
declare float @llvm.sqrt.f32(float)
6+
define float @sqrt_f32(float %a) {
7+
; MIPS32-LABEL: sqrt_f32:
8+
; MIPS32: # %bb.0: # %entry
9+
; MIPS32-NEXT: sqrt.s $f0, $f12
10+
; MIPS32-NEXT: jr $ra
11+
; MIPS32-NEXT: nop
12+
entry:
13+
%0 = call float @llvm.sqrt.f32(float %a)
14+
ret float %0
15+
}
16+
17+
declare double @llvm.sqrt.f64(double)
18+
define double @sqrt_f64(double %a) {
19+
; MIPS32-LABEL: sqrt_f64:
20+
; MIPS32: # %bb.0: # %entry
21+
; MIPS32-NEXT: sqrt.d $f0, $f12
22+
; MIPS32-NEXT: jr $ra
23+
; MIPS32-NEXT: nop
24+
entry:
25+
%0 = call double @llvm.sqrt.f64(double %a)
26+
ret double %0
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -O0 -mtriple=mipsel-linux-gnu -run-pass=regbankselect -verify-machineinstrs %s -o - | FileCheck %s -check-prefixes=FP32
3+
# RUN: llc -O0 -mtriple=mipsel-linux-gnu -mattr=+fp64,+mips32r2 -run-pass=regbankselect -verify-machineinstrs %s -o - | FileCheck %s -check-prefixes=FP64
4+
--- |
5+
6+
define void @sqrt_f32() {entry: ret void}
7+
define void @sqrt_f64() {entry: ret void}
8+
9+
...
10+
---
11+
name: sqrt_f32
12+
alignment: 2
13+
legalized: true
14+
tracksRegLiveness: true
15+
body: |
16+
bb.1.entry:
17+
liveins: $f12
18+
19+
; FP32-LABEL: name: sqrt_f32
20+
; FP32: liveins: $f12
21+
; FP32: [[COPY:%[0-9]+]]:fprb(s32) = COPY $f12
22+
; FP32: [[FSQRT:%[0-9]+]]:fprb(s32) = G_FSQRT [[COPY]]
23+
; FP32: $f0 = COPY [[FSQRT]](s32)
24+
; FP32: RetRA implicit $f0
25+
; FP64-LABEL: name: sqrt_f32
26+
; FP64: liveins: $f12
27+
; FP64: [[COPY:%[0-9]+]]:fprb(s32) = COPY $f12
28+
; FP64: [[FSQRT:%[0-9]+]]:fprb(s32) = G_FSQRT [[COPY]]
29+
; FP64: $f0 = COPY [[FSQRT]](s32)
30+
; FP64: RetRA implicit $f0
31+
%0:_(s32) = COPY $f12
32+
%1:_(s32) = G_FSQRT %0
33+
$f0 = COPY %1(s32)
34+
RetRA implicit $f0
35+
36+
...
37+
---
38+
name: sqrt_f64
39+
alignment: 2
40+
legalized: true
41+
tracksRegLiveness: true
42+
body: |
43+
bb.1.entry:
44+
liveins: $d6
45+
46+
; FP32-LABEL: name: sqrt_f64
47+
; FP32: liveins: $d6
48+
; FP32: [[COPY:%[0-9]+]]:fprb(s64) = COPY $d6
49+
; FP32: [[FSQRT:%[0-9]+]]:fprb(s64) = G_FSQRT [[COPY]]
50+
; FP32: $d0 = COPY [[FSQRT]](s64)
51+
; FP32: RetRA implicit $d0
52+
; FP64-LABEL: name: sqrt_f64
53+
; FP64: liveins: $d6
54+
; FP64: [[COPY:%[0-9]+]]:fprb(s64) = COPY $d6
55+
; FP64: [[FSQRT:%[0-9]+]]:fprb(s64) = G_FSQRT [[COPY]]
56+
; FP64: $d0 = COPY [[FSQRT]](s64)
57+
; FP64: RetRA implicit $d0
58+
%0:_(s64) = COPY $d6
59+
%1:_(s64) = G_FSQRT %0
60+
$d0 = COPY %1(s64)
61+
RetRA implicit $d0
62+
63+
...

0 commit comments

Comments
 (0)