[PATCH] D113008: [NVPTX] Mark special registers as reserved

Andrew Savonichev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 2 05:21:56 PDT 2021


asavonic created this revision.
asavonic added reviewers: tra, jlebar, jholewinski.
Herald added a subscriber: hiraditya.
asavonic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113008

Files:
  llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp
  llvm/test/CodeGen/NVPTX/envreg.ll


Index: llvm/test/CodeGen/NVPTX/envreg.ll
===================================================================
--- llvm/test/CodeGen/NVPTX/envreg.ll
+++ 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()
Index: llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp
===================================================================
--- llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp
+++ llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp
@@ -107,6 +107,14 @@
 
 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;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113008.384051.patch
Type: text/x-patch
Size: 1120 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211102/3041b690/attachment.bin>


More information about the llvm-commits mailing list