Skip to content

Commit 9a0352f

Browse files
committed
Merging r343443:
------------------------------------------------------------------------ r343443 | ctopper | 2018-10-01 00:08:41 -0700 (Mon, 01 Oct 2018) | 9 lines [X86] Stop X86DomainReassignment from creating copies between GR8/GR16 physical registers and k-registers. We can only copy between a k-register and a GR32/GR64 register. This patch detects that the copy will be illegal and prevents the domain reassignment from happening for that closure. This probably isn't the best fix, and we should probably figure out how to handle this correctly. Fixes PR38803. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_70@344804 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 6c2e5a1 commit 9a0352f

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

lib/Target/X86/X86DomainReassignment.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,27 @@ class InstrCOPYReplacer : public InstrReplacer {
217217
InstrCOPYReplacer(unsigned SrcOpcode, RegDomain DstDomain, unsigned DstOpcode)
218218
: InstrReplacer(SrcOpcode, DstOpcode), DstDomain(DstDomain) {}
219219

220+
bool isLegal(const MachineInstr *MI,
221+
const TargetInstrInfo *TII) const override {
222+
if (!InstrConverterBase::isLegal(MI, TII))
223+
return false;
224+
225+
// Don't allow copies to/flow GR8/GR16 physical registers.
226+
// FIXME: Is there some better way to support this?
227+
unsigned DstReg = MI->getOperand(0).getReg();
228+
if (TargetRegisterInfo::isPhysicalRegister(DstReg) &&
229+
(X86::GR8RegClass.contains(DstReg) ||
230+
X86::GR16RegClass.contains(DstReg)))
231+
return false;
232+
unsigned SrcReg = MI->getOperand(1).getReg();
233+
if (TargetRegisterInfo::isPhysicalRegister(SrcReg) &&
234+
(X86::GR8RegClass.contains(SrcReg) ||
235+
X86::GR16RegClass.contains(SrcReg)))
236+
return false;
237+
238+
return true;
239+
}
240+
220241
double getExtraCost(const MachineInstr *MI,
221242
MachineRegisterInfo *MRI) const override {
222243
assert(MI->getOpcode() == TargetOpcode::COPY && "Expected a COPY");

test/CodeGen/X86/pr38803.ll

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc < %s -mcpu=skylake-avx512 -mtriple=x86_64-unknown-unknown | FileCheck %s
3+
4+
@b = local_unnamed_addr global i32 0, align 4
5+
@c = local_unnamed_addr global i32 0, align 4
6+
@d = local_unnamed_addr global float 0.000000e+00, align 4
7+
8+
define float @_Z3fn2v() {
9+
; CHECK-LABEL: _Z3fn2v:
10+
; CHECK: # %bb.0: # %entry
11+
; CHECK-NEXT: pushq %rax
12+
; CHECK-NEXT: .cfi_def_cfa_offset 16
13+
; CHECK-NEXT: callq _Z1av
14+
; CHECK-NEXT: # kill: def $al killed $al def $eax
15+
; CHECK-NEXT: kmovd %eax, %k1
16+
; CHECK-NEXT: vmovss {{.*#+}} xmm0 = mem[0],zero,zero,zero
17+
; CHECK-NEXT: vmovss %xmm0, %xmm0, %xmm0 {%k1} {z}
18+
; CHECK-NEXT: cmpl $0, {{.*}}(%rip)
19+
; CHECK-NEXT: je .LBB0_2
20+
; CHECK-NEXT: # %bb.1: # %if.then
21+
; CHECK-NEXT: vcvtsi2ssl {{.*}}(%rip), %xmm1, %xmm1
22+
; CHECK-NEXT: kmovd %eax, %k1
23+
; CHECK-NEXT: vxorps %xmm2, %xmm2, %xmm2
24+
; CHECK-NEXT: vmovss %xmm2, %xmm0, %xmm1 {%k1}
25+
; CHECK-NEXT: vmovss %xmm1, {{.*}}(%rip)
26+
; CHECK-NEXT: .LBB0_2: # %if.end
27+
; CHECK-NEXT: popq %rax
28+
; CHECK-NEXT: .cfi_def_cfa_offset 8
29+
; CHECK-NEXT: retq
30+
entry:
31+
%call = tail call zeroext i1 @_Z1av()
32+
%cond = select i1 %call, float 7.500000e-01, float 0.000000e+00
33+
%0 = load i32, i32* @c, align 4
34+
%tobool2 = icmp eq i32 %0, 0
35+
br i1 %tobool2, label %if.end, label %if.then
36+
37+
if.then: ; preds = %entry
38+
%1 = load i32, i32* @b, align 4
39+
%2 = sitofp i32 %1 to float
40+
%conv5 = select i1 %call, float 0.000000e+00, float %2
41+
store float %conv5, float* @d, align 4
42+
br label %if.end
43+
44+
if.end: ; preds = %entry, %if.then
45+
ret float %cond
46+
}
47+
48+
declare zeroext i1 @_Z1av()

0 commit comments

Comments
 (0)