[PATCH] D122615: Early return in constrainOperandRegClass()

Viacheslav Nikolaev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 28 14:16:53 PDT 2022


wvoquine created this revision.
wvoquine added reviewers: aditya_nandakumar, dsanders, arsenm.
Herald added a subscriber: hiraditya.
Herald added a project: All.
wvoquine requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

When no actual change happens there's no need to notify the
observers about the fact the register class is being constrained.
So we should return early on.

Notifying the observers about instruction changes when
no change actually happens dramatically affects compile
time for particular test cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122615

Files:
  llvm/lib/CodeGen/GlobalISel/Utils.cpp


Index: llvm/lib/CodeGen/GlobalISel/Utils.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -58,6 +58,11 @@
   // Assume physical registers are properly constrained.
   assert(Register::isVirtualRegister(Reg) && "PhysReg not implemented");
 
+  // Check if the register class is already as required.
+  auto *OldRegClass = MRI.getRegClassOrNull(Reg);
+  if (OldRegClass == &RegClass)
+    return Reg;
+
   Register ConstrainedReg = constrainRegToClass(MRI, TII, RBI, Reg, RegClass);
   // If we created a new virtual register because the class is not compatible
   // then create a copy between the new and the old register.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122615.418700.patch
Type: text/x-patch
Size: 733 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220328/2a12cce3/attachment.bin>


More information about the llvm-commits mailing list