[llvm] 93977f3 - Check if register class was changed in constrainOperandRegClass()

Daniel Sanders via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 5 11:55:16 PDT 2022


Author: Daniel Sanders
Date: 2022-04-05T11:55:07-07:00
New Revision: 93977f37e67eae26d9bc88e5c3970c11d8861dfc

URL: https://github.com/llvm/llvm-project/commit/93977f37e67eae26d9bc88e5c3970c11d8861dfc
DIFF: https://github.com/llvm/llvm-project/commit/93977f37e67eae26d9bc88e5c3970c11d8861dfc.diff

LOG: Check if register class was changed in constrainOperandRegClass()

NFC
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 avoid notifying observers when no change has
happened, because this can dramatically affect compile
time for particular test cases.

Reviewed By: dsanders, arsenm

Differential Revision: https://reviews.llvm.org/D122615

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
index 98883747e1ed4..1544268be9fc2 100644
--- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -58,6 +58,11 @@ Register llvm::constrainOperandRegClass(
   // 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 @@ Register llvm::constrainOperandRegClass(
     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);


        


More information about the llvm-commits mailing list