[llvm] r324047 - [GlobalISel] Constrain the dest reg of IMPLICT_DEF.
Amara Emerson via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 1 17:44:44 PST 2018
Author: aemerson
Date: Thu Feb 1 17:44:43 2018
New Revision: 324047
URL: http://llvm.org/viewvc/llvm-project?rev=324047&view=rev
Log:
[GlobalISel] Constrain the dest reg of IMPLICT_DEF.
This fixes a crash where the user is a COPY, which deliberately does not
constrain its source operands, resulting in a vreg without a reg class escaping
selection.
Differential Revision: https://reviews.llvm.org/D42697
Modified:
llvm/trunk/lib/Target/AArch64/AArch64InstructionSelector.cpp
llvm/trunk/test/CodeGen/AArch64/GlobalISel/select-implicit-def.mir
Modified: llvm/trunk/lib/Target/AArch64/AArch64InstructionSelector.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64InstructionSelector.cpp?rev=324047&r1=324046&r2=324047&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64InstructionSelector.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64InstructionSelector.cpp Thu Feb 1 17:44:43 2018
@@ -1407,6 +1407,12 @@ bool AArch64InstructionSelector::select(
: selectVaStartAAPCS(I, MF, MRI);
case TargetOpcode::G_IMPLICIT_DEF:
I.setDesc(TII.get(TargetOpcode::IMPLICIT_DEF));
+ const LLT DstTy = MRI.getType(I.getOperand(0).getReg());
+ const unsigned DstReg = I.getOperand(0).getReg();
+ const RegisterBank &DstRB = *RBI.getRegBank(DstReg, MRI, TRI);
+ const TargetRegisterClass *DstRC =
+ getRegClassForTypeOnBank(DstTy, DstRB, RBI);
+ RBI.constrainGenericRegister(DstReg, *DstRC, MRI);
return true;
}
Modified: llvm/trunk/test/CodeGen/AArch64/GlobalISel/select-implicit-def.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/GlobalISel/select-implicit-def.mir?rev=324047&r1=324046&r2=324047&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/GlobalISel/select-implicit-def.mir (original)
+++ llvm/trunk/test/CodeGen/AArch64/GlobalISel/select-implicit-def.mir Thu Feb 1 17:44:43 2018
@@ -5,6 +5,7 @@
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
define void @implicit_def() { ret void }
+ define void @implicit_def_copy() { ret void }
...
---
@@ -25,3 +26,21 @@ body: |
%1(s32) = G_ADD %0, %0
$w0 = COPY %1(s32)
...
+---
+name: implicit_def_copy
+legalized: true
+regBankSelected: true
+registers:
+ - { id: 0, class: gpr }
+ - { id: 1, class: gpr }
+
+body: |
+ bb.0:
+ ; CHECK-LABEL: name: implicit_def_copy
+ ; CHECK: [[DEF:%[0-9]+]]:gpr32 = IMPLICIT_DEF
+ ; CHECK: [[COPY:%[0-9]+]]:gpr32all = COPY [[DEF]]
+ ; CHECK: %w0 = COPY [[COPY]]
+ %0(s32) = G_IMPLICIT_DEF
+ %1(s32) = COPY %0(s32)
+ %w0 = COPY %1(s32)
+...
More information about the llvm-commits
mailing list