Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 1e20442

Browse files
author
Stefan Maksimovic
committed
[SelectionDAG] Provide adequate register class for RegisterSDNode
When adding operands to machine instructions in case of RegisterSDNodes, generate a COPY node in case the register class does not match the one in the instruction definition. Differental Revision: https://reviews.llvm.org/D35561 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@324733 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 32bbb27 commit 1e20442

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

lib/CodeGen/SelectionDAG/InstrEmitter.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,26 @@ void InstrEmitter::AddOperand(MachineInstrBuilder &MIB,
394394
} else if (ConstantFPSDNode *F = dyn_cast<ConstantFPSDNode>(Op)) {
395395
MIB.addFPImm(F->getConstantFPValue());
396396
} else if (RegisterSDNode *R = dyn_cast<RegisterSDNode>(Op)) {
397+
unsigned VReg = R->getReg();
398+
MVT OpVT = Op.getSimpleValueType();
399+
const TargetRegisterClass *OpRC =
400+
TLI->isTypeLegal(OpVT) ? TLI->getRegClassFor(OpVT) : nullptr;
401+
const TargetRegisterClass *IIRC =
402+
II ? TRI->getAllocatableClass(TII->getRegClass(*II, IIOpNum, TRI, *MF))
403+
: nullptr;
404+
405+
if (OpRC && IIRC && OpRC != IIRC &&
406+
TargetRegisterInfo::isVirtualRegister(VReg)) {
407+
unsigned NewVReg = MRI->createVirtualRegister(IIRC);
408+
BuildMI(*MBB, InsertPos, Op.getNode()->getDebugLoc(),
409+
TII->get(TargetOpcode::COPY), NewVReg).addReg(VReg);
410+
VReg = NewVReg;
411+
}
397412
// Turn additional physreg operands into implicit uses on non-variadic
398413
// instructions. This is used by call and return instructions passing
399414
// arguments in registers.
400415
bool Imp = II && (IIOpNum >= II->getNumOperands() && !II->isVariadic());
401-
MIB.addReg(R->getReg(), getImplRegState(Imp));
416+
MIB.addReg(VReg, getImplRegState(Imp));
402417
} else if (RegisterMaskSDNode *RM = dyn_cast<RegisterMaskSDNode>(Op)) {
403418
MIB.addRegMask(RM->getRegMask());
404419
} else if (GlobalAddressSDNode *TGA = dyn_cast<GlobalAddressSDNode>(Op)) {

test/CodeGen/AMDGPU/r600.work-item-intrinsics.ll

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
; RUN: llc -march=r600 -mcpu=redwood < %s | FileCheck -check-prefix=EG -check-prefix=FUNC %s
1+
; RUN: llc -march=r600 -mcpu=redwood -verify-machineinstrs < %s | \
2+
; RUN: FileCheck -check-prefix=EG -check-prefix=FUNC %s
23

34
; FUNC-LABEL: {{^}}tgid_x:
45
; EG: MEM_RAT_CACHELESS STORE_RAW T1.X
@@ -10,7 +11,8 @@ entry:
1011
}
1112

1213
; FUNC-LABEL: {{^}}tgid_y:
13-
; EG: MEM_RAT_CACHELESS STORE_RAW T1.Y
14+
; EG: MEM_RAT_CACHELESS STORE_RAW [[REG:T[0-9]+]].X
15+
; EG: MOV [[REG]].X, T1.Y
1416
define amdgpu_kernel void @tgid_y(i32 addrspace(1)* %out) {
1517
entry:
1618
%0 = call i32 @llvm.r600.read.tgid.y() #0
@@ -19,7 +21,8 @@ entry:
1921
}
2022

2123
; FUNC-LABEL: {{^}}tgid_z:
22-
; EG: MEM_RAT_CACHELESS STORE_RAW T1.Z
24+
; EG: MEM_RAT_CACHELESS STORE_RAW [[REG:T[0-9]+]].X
25+
; EG: MOV [[REG]].X, T1.Z
2326
define amdgpu_kernel void @tgid_z(i32 addrspace(1)* %out) {
2427
entry:
2528
%0 = call i32 @llvm.r600.read.tgid.z() #0
@@ -37,7 +40,8 @@ entry:
3740
}
3841

3942
; FUNC-LABEL: {{^}}tidig_y:
40-
; EG: MEM_RAT_CACHELESS STORE_RAW T0.Y
43+
; EG: MEM_RAT_CACHELESS STORE_RAW [[REG:T[0-9]+]].X
44+
; EG: MOV [[REG]].X, T0.Y
4145
define amdgpu_kernel void @tidig_y(i32 addrspace(1)* %out) {
4246
entry:
4347
%0 = call i32 @llvm.r600.read.tidig.y() #0
@@ -46,7 +50,8 @@ entry:
4650
}
4751

4852
; FUNC-LABEL: {{^}}tidig_z:
49-
; EG: MEM_RAT_CACHELESS STORE_RAW T0.Z
53+
; EG: MEM_RAT_CACHELESS STORE_RAW [[REG:T[0-9]+]].X
54+
; EG: MOV [[REG]].X, T0.Z
5055
define amdgpu_kernel void @tidig_z(i32 addrspace(1)* %out) {
5156
entry:
5257
%0 = call i32 @llvm.r600.read.tidig.z() #0

test/CodeGen/Mips/tailcall/tailcall.ll

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@
1010
; RUN: -verify-machineinstrs -mips-tail-calls=1 < %s | \
1111
; RUN: FileCheck %s -check-prefixes=ALL,PIC16
1212

13-
; RUN: llc -march=mipsel -relocation-model=pic -mattr=+micromips -mips-tail-calls=1 < %s | \
14-
; RUN: FileCheck %s -check-prefixes=ALL,PIC32MM
15-
; RUN: llc -march=mipsel -relocation-model=static -mattr=+micromips \
13+
; RUN: llc -march=mipsel -relocation-model=pic -mattr=+micromips -verify-machineinstrs \
14+
; RUN: -mips-tail-calls=1 < %s | FileCheck %s -check-prefixes=ALL,PIC32MM
15+
; RUN: llc -march=mipsel -relocation-model=static -mattr=+micromips -verify-machineinstrs \
1616
; RUN: -mips-tail-calls=1 < %s | FileCheck %s -check-prefixes=ALL,STATIC32
1717

18-
; RUN: llc -march=mipsel -relocation-model=pic -mcpu=mips32r6 -mips-tail-calls=1 < %s | \
19-
; RUN: FileCheck %s -check-prefixes=ALL,PIC32R6
20-
; RUN: llc -march=mipsel -relocation-model=static -mcpu=mips32r2 \
18+
; RUN: llc -march=mipsel -relocation-model=pic -mcpu=mips32r6 -verify-machineinstrs \
19+
; RUN: -mips-tail-calls=1 < %s | FileCheck %s -check-prefixes=ALL,PIC32R6
20+
; RUN: llc -march=mipsel -relocation-model=static -mcpu=mips32r2 -verify-machineinstrs \
2121
; RUN: -mips-tail-calls=1 < %s | FileCheck %s -check-prefixes=ALL,STATIC32
22-
; RUN: llc -march=mips64el -relocation-model=pic -mcpu=mips64r2 \
22+
; RUN: llc -march=mips64el -relocation-model=pic -mcpu=mips64r2 -verify-machineinstrs \
2323
; RUN: -mips-tail-calls=1 < %s | FileCheck %s -check-prefix=PIC64
24-
; RUN: llc -march=mips64el -relocation-model=pic -mcpu=mips64r6 \
24+
; RUN: llc -march=mips64el -relocation-model=pic -mcpu=mips64r6 -verify-machineinstrs \
2525
; RUN: -mips-tail-calls=1 < %s | FileCheck %s -check-prefix=STATIC64
2626

27-
; RUN: llc -march=mipsel -relocation-model=pic -mcpu=mips32r6 -mattr=+micromips \
27+
; RUN: llc -march=mipsel -relocation-model=pic -mcpu=mips32r6 -mattr=+micromips -verify-machineinstrs \
2828
; RUN: -mips-tail-calls=1 < %s | FileCheck %s -check-prefixes=ALL,PIC32MM
29-
; RUN: llc -march=mipsel -relocation-model=static -mcpu=mips32r6 \
29+
; RUN: llc -march=mipsel -relocation-model=static -mcpu=mips32r6 -verify-machineinstrs \
3030
; RUN: -mattr=+micromips -mips-tail-calls=1 < %s | FileCheck %s -check-prefixes=ALL,STATIC32MMR6
3131

3232
@g0 = common global i32 0, align 4

0 commit comments

Comments
 (0)