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.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/CodeGen/GlobalISel/Utils.cpp | ||
---|---|---|
61–65 | I'm not keen on duplicating internals of constrainRegToClass() behaviour (even obvious behaviours like this one). Do you get a similar perf fix if you check between the possible change and the notification with something like this?: auto *OldRegClass = MRI.getRegClassOrNull(Reg); Register ConstrainedReg = constrainRegToClass(MRI, TII, RBI, Reg, RegClass); if (ConstrainedReg != Reg) { insert copy notify observers } else { auto *NewRegClass = MRI.getRegClassOrNull(Reg); if (OldRegClass != &NewRegClass) { notify observers } } | |
97 | It's not for this patch but this call is supposed to happen before the change. It won't work properly for all observers if it's after the change. For example, the debug location info checking one will compare the state after the change to the state after the change with this call where it currently is. |
llvm/lib/CodeGen/GlobalISel/Utils.cpp | ||
---|---|---|
61–65 | We discussed that issue with Daniel separately. It looks like a viable approach could be to add API calls RBI.needToConstrainGenericRegister()->MRI. needToConstrainGenericRegister()->... |
llvm/include/llvm/CodeGen/RegisterBankInfo.h | ||
---|---|---|
644 ↗ | (On Diff #418748) | I just followed the choices made for the corresponding utility functions/methods for constrainGenericRegister() and constrainOperandRegClass(). There's no actual need for the latter to be around at the moment, I can remove the utility function. |
llvm/lib/CodeGen/GlobalISel/Utils.cpp | ||
46 | Good point! I guess, it really makes sense to remove this utility method right now, to avoid fixing the API some of the operands of which are not required... |
llvm/include/llvm/CodeGen/RegisterBankInfo.h | ||
---|---|---|
644 ↗ | (On Diff #418748) |
I mean, there's no real need for needToConstrainRegToClass() at the moment. |
llvm/lib/CodeGen/MachineRegisterInfo.cpp | ||
---|---|---|
82 ↗ | (On Diff #418748) | This is more of a naming nitpick but this path isn't constraining the reg class yet constraining is still needed. I believe the caller is expected to emit a copy instead and that caller should notify the observers correctly FWIW, MinNumRegs is hardly ever used, I can only find a couple instances |
llvm/lib/CodeGen/RegisterBankInfo.cpp | ||
131–132 ↗ | (On Diff #418748) | There's also a chance it isn't and constrainGenericRegister() changes the class requiring that the observers be notified |
llvm/lib/CodeGen/GlobalISel/Utils.cpp | ||
---|---|---|
61–65 | After further discussion of the new patch, it turns out the post-check @dsanders has proposed would be the right way to go. The reasons are
So, considering all this I'm leaning towards the proposed "post-check" suggestion with a "TODO:" about a solution which would be not an ad hoc one. |
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.
Why call a static method through RBI?