Skip to content

Commit 4775e6d

Browse files
[X86][GlobalISel] Added support for G_FSQRT (llvm#132356)
1 parent 23882f0 commit 4775e6d

File tree

4 files changed

+84
-9
lines changed

4 files changed

+84
-9
lines changed

llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
105105
G_FEXP10, G_FLOG, G_FLOG2, G_FLOG10})
106106
.libcall();
107107

108+
getActionDefinitionsBuilder(G_FSQRT)
109+
.legalFor(HasSSE1 || UseX87, {s32})
110+
.legalFor(HasSSE2 || UseX87, {s64})
111+
.legalFor(UseX87, {s80});
112+
108113
// merge/unmerge
109114
for (unsigned Op : {G_MERGE_VALUES, G_UNMERGE_VALUES}) {
110115
unsigned BigTyIdx = Op == G_MERGE_VALUES ? 0 : 1;

llvm/lib/Target/X86/GISel/X86RegisterBankInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ X86RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
288288
SmallVector<PartialMappingIdx, 4> OpRegBankIdx(NumOperands);
289289

290290
switch (Opc) {
291+
case TargetOpcode::G_FSQRT:
291292
case TargetOpcode::G_FPEXT:
292293
case TargetOpcode::G_FPTRUNC:
293294
case TargetOpcode::G_FCONSTANT:
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
2+
# RUN: llc -mtriple=i686-linux-gnu -run-pass=regbankselect,instruction-select %s -o - | FileCheck %s --check-prefixes GISEL-I686
3+
4+
---
5+
name: test_sqrt_f32
6+
alignment: 16
7+
legalized: true
8+
fixedStack:
9+
- { id: 0, type: default, offset: 0, size: 4, alignment: 16, stack-id: default,
10+
isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
11+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
12+
body: |
13+
bb.1:
14+
; GISEL-I686-LABEL: name: test_sqrt_f32
15+
; GISEL-I686: [[LD_Fp32m:%[0-9]+]]:rfp32 = LD_Fp32m %fixed-stack.0, 1, $noreg, 0, $noreg, implicit-def $fpsw, implicit $fpcw :: (invariant load (s32) from %fixed-stack.0, align 16)
16+
; GISEL-I686-NEXT: [[SQRT_Fp32_:%[0-9]+]]:rfp32 = nofpexcept SQRT_Fp32 [[LD_Fp32m]], implicit-def dead $fpsw, implicit $fpcw
17+
; GISEL-I686-NEXT: $fp0 = COPY [[SQRT_Fp32_]]
18+
; GISEL-I686-NEXT: RET 0, implicit $fp0
19+
%1:_(p0) = G_FRAME_INDEX %fixed-stack.0
20+
%0:_(s32) = G_LOAD %1(p0) :: (invariant load (s32) from %fixed-stack.0, align 16)
21+
%2:_(s32) = G_FSQRT %0
22+
$fp0 = COPY %2(s32)
23+
RET 0, implicit $fp0
24+
25+
...
26+
---
27+
name: test_sqrt_f64
28+
alignment: 16
29+
legalized: true
30+
fixedStack:
31+
- { id: 0, type: default, offset: 0, size: 8, alignment: 16, stack-id: default,
32+
isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
33+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
34+
body: |
35+
bb.1:
36+
; GISEL-I686-LABEL: name: test_sqrt_f64
37+
; GISEL-I686: [[DEF:%[0-9]+]]:rfp64 = IMPLICIT_DEF
38+
; GISEL-I686-NEXT: [[SQRT_Fp64_:%[0-9]+]]:rfp64 = nofpexcept SQRT_Fp64 [[DEF]], implicit-def dead $fpsw, implicit $fpcw
39+
; GISEL-I686-NEXT: $fp0 = COPY [[SQRT_Fp64_]]
40+
; GISEL-I686-NEXT: RET 0, implicit $fp0
41+
%0:_(s64) = IMPLICIT_DEF
42+
%2:_(s64) = G_FSQRT %0
43+
$fp0 = COPY %2(s64)
44+
RET 0, implicit $fp0
45+
46+
...
47+
---
48+
name: test_sqrt_f80
49+
alignment: 16
50+
legalized: true
51+
fixedStack:
52+
- { id: 0, type: default, offset: 0, size: 10, alignment: 16, stack-id: default,
53+
isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
54+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
55+
body: |
56+
bb.1:
57+
; GISEL-I686-LABEL: name: test_sqrt_f80
58+
; GISEL-I686: [[LD_Fp80m:%[0-9]+]]:rfp80 = LD_Fp80m %fixed-stack.0, 1, $noreg, 0, $noreg, implicit-def $fpsw, implicit $fpcw :: (invariant load (s80) from %fixed-stack.0, align 16)
59+
; GISEL-I686-NEXT: [[SQRT_Fp80_:%[0-9]+]]:rfp80 = nofpexcept SQRT_Fp80 [[LD_Fp80m]], implicit-def dead $fpsw, implicit $fpcw
60+
; GISEL-I686-NEXT: $fp0 = COPY [[SQRT_Fp80_]]
61+
; GISEL-I686-NEXT: RET 0, implicit $fp0
62+
%1:_(p0) = G_FRAME_INDEX %fixed-stack.0
63+
%0:_(s80) = G_LOAD %1(p0) :: (invariant load (s80) from %fixed-stack.0, align 16)
64+
%2:_(s80) = G_FSQRT %0
65+
$fp0 = COPY %2(s80)
66+
RET 0, implicit $fp0
67+
68+
...

llvm/test/CodeGen/X86/isel-sqrt.ll

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2-
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mattr=-avx,+sse2 | FileCheck %s --check-prefixes=X64,SSE2
3-
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mattr=-avx,+sse2 -fast-isel | FileCheck %s --check-prefixes=X64,SSE2
4-
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mattr=-avx,+sse2 -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes=X64,SSE2
5-
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mattr=-avx2,+avx | FileCheck %s --check-prefixes=X64,AVX
6-
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mattr=-avx2,+avx -fast-isel | FileCheck %s --check-prefixes=X64,AVX
7-
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mattr=-avx2,+avx -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes=X64,AVX
8-
; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel=0 -fast-isel=0 | FileCheck %s --check-prefixes=X86,SDAG-X86
9-
; RUN: llc < %s -mtriple=i686-linux-gnu -fast-isel | FileCheck %s --check-prefixes=X86,FASTISEL-X86
10-
; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes=X86,GISEL-X86
2+
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mattr=-avx,+sse2 | FileCheck %s --check-prefixes=X64,SSE2
3+
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mattr=-avx,+sse2 -fast-isel | FileCheck %s --check-prefixes=X64,SSE2
4+
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mattr=-avx,+sse2 -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X64,SSE2
5+
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mattr=-avx2,+avx | FileCheck %s --check-prefixes=X64,AVX
6+
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mattr=-avx2,+avx -fast-isel | FileCheck %s --check-prefixes=X64,AVX
7+
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mattr=-avx2,+avx -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X64,AVX
8+
; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel=0 -fast-isel=0 | FileCheck %s --check-prefixes=X86,SDAG-X86
9+
; RUN: llc < %s -mtriple=i686-linux-gnu -fast-isel | FileCheck %s --check-prefixes=X86,FASTISEL-X86
10+
; TODO: The last RUN line will fails GISEL selection and will fallback to DAG selection due to lack of support for loads/stores in i686 mode, support is expected soon enough, for this reason the llvm/test/CodeGen/X86/GlobalISel/sqrt.mir test is added for now because of the lack of support for i686 in GlobalISel.
11+
; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes=X86,GISEL-X86
1112

1213
define float @test_sqrt_f32(float %a) {
1314
; SSE2-LABEL: test_sqrt_f32:

0 commit comments

Comments
 (0)