From 123ad720f1836813e3a74170d62ece6372c4cac2 Mon Sep 17 00:00:00 2001 From: Andrew Savonichev Date: Wed, 3 Nov 2021 15:48:04 +0300 Subject: [PATCH] [NVPTX] Mark special registers as reserved A reserved register: - is not allocatable - is considered always live - is ignored by liveness tracking NVPTX special registers match the criteria, and marking them as reserved helps to avoid machine verifier error: *** Bad machine code: Using an undefined physical register *** - function: foo - basic block: %bb.0 (0x557bb178b708) - instruction: %0:int32regs = MOV_SPECIAL $envreg0 - operand 1: $envreg0 Differential Revision: https://reviews.llvm.org/D113008 --- llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp | 8 ++++++++ llvm/test/CodeGen/NVPTX/envreg.ll | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp b/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp index 98724f3..ec73072 100644 --- a/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp @@ -107,6 +107,14 @@ NVPTXRegisterInfo::getCalleeSavedRegs(const MachineFunction *) const { BitVector NVPTXRegisterInfo::getReservedRegs(const MachineFunction &MF) const { BitVector Reserved(getNumRegs()); + for (unsigned Reg = NVPTX::ENVREG0; Reg <= NVPTX::ENVREG31; ++Reg) { + markSuperRegs(Reserved, Reg); + } + markSuperRegs(Reserved, NVPTX::VRFrame32); + markSuperRegs(Reserved, NVPTX::VRFrameLocal32); + markSuperRegs(Reserved, NVPTX::VRFrame64); + markSuperRegs(Reserved, NVPTX::VRFrameLocal64); + markSuperRegs(Reserved, NVPTX::VRDepot); return Reserved; } diff --git a/llvm/test/CodeGen/NVPTX/envreg.ll b/llvm/test/CodeGen/NVPTX/envreg.ll index a341b49..8ab5816 100644 --- a/llvm/test/CodeGen/NVPTX/envreg.ll +++ b/llvm/test/CodeGen/NVPTX/envreg.ll @@ -1,4 +1,4 @@ -; RUN: llc < %s -march=nvptx -mcpu=sm_20 | FileCheck %s +; RUN: llc < %s -march=nvptx -mcpu=sm_20 -verify-machineinstrs | FileCheck %s declare i32 @llvm.nvvm.read.ptx.sreg.envreg0() -- 2.7.4