[PATCH] D122615: Check if register class was changed in constrainOperandRegClass()

Viacheslav Nikolaev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 31 12:15:50 PDT 2022


wvoquine updated this revision to Diff 419535.
wvoquine retitled this revision from "Early return in constrainOperandRegClass()" to "Check if register class was changed in constrainOperandRegClass()".
wvoquine edited the summary of this revision.
wvoquine added a comment.

Went ahead with the post-check Daniel proposed.
This is a cleaner approach - we just check whether the register class has changed as a part of the constraining and based on that decide whether we need to notify the observers.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122615/new/

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");
 
+  // Save the old register class to check whether
+  // the change notifications will be required.
+  // TODO: A better approach would be to pass
+  // the observers to constrainRegToClass().
+  auto *OldRegClass = MRI.getRegClassOrNull(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.
@@ -83,7 +88,7 @@
     if (GISelChangeObserver *Observer = MF.getObserver()) {
       Observer->changedInstr(*RegMO.getParent());
     }
-  } else {
+  } else if (OldRegClass != MRI.getRegClassOrNull(Reg)) {
     if (GISelChangeObserver *Observer = MF.getObserver()) {
       if (!RegMO.isDef()) {
         MachineInstr *RegDef = MRI.getVRegDef(Reg);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122615.419535.patch
Type: text/x-patch
Size: 1167 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220331/6ae954bd/attachment.bin>


More information about the llvm-commits mailing list