The current implementation of isConstantPhysReg() checks for defs of
physical registers to determine if they are constant. Some
architectures (e.g. AArch64 XZR/WZR) have registers that are constant
and may be used as destinations to indicate the generated value is
discarded, preventing isConstantPhysReg() from returning true. This
change adds a TargetRegisterInfo hook that overrides the no defs check
for cases such as this.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
include/llvm/Target/TargetRegisterInfo.h | ||
---|---|---|
498–499 ↗ | (On Diff #71373) | This needs a comment (even if it just refers to MachineRegisterInfo::isConstantPhysReg())! |
I meant to add this before: I'm interested to hear opinions on whether adding a virtual function call for this is okay, or if this bit should instead say be cached in TargetRegisterInfoDesc like inAllocatableClass is.
Also, this change potentially fixes https://llvm.org/bugs/show_bug.cgi?id=25457
Hard to say in general. Depends on how it is called, whether most implementations are just a few equality comparisons, ...
It looks good enough for todays uses. You could do some measurements though I wouldn't expect any compiletime differences. We can always add more caching later when necessary.
LGTM, but please simplify the test as much as possible before committing:
test/CodeGen/MIR/AArch64/machine-sink-zr.mir | ||
---|---|---|
4–20 ↗ | (On Diff #71533) | I believe there is no need for any backreference here and you can simplify this to define void @sinkwzr() { ret void } (see below for how to block names). |
24–29 ↗ | (On Diff #71533) | I would expect that the default values are fine for those options so you don't need to specify them here. |
40 ↗ | (On Diff #71533) | I would add a CHECK-LABEL: name: sinkwzr to get the checker on the right function (in case people add more functions to this test in the future). |
42 ↗ | (On Diff #71533) | You can simply use bb.0: here to avoid the backreference to the IR code (similar with all other basic block names). |