In commit rL277126, target hook getInstSizeInBytes was added to TargetInstrInfo. This function was already implemented by most backends, but some of them can run into llvm_unreachable which makes it impossible to recover from unknown instruction sizes. This fix returns the sentinel value ~0U instead of unreachable in the AArch64, AMDGPU, MSP430 backends.
Details
Diff Detail
Event Timeline
lib/Target/AArch64/AArch64BranchRelaxation.cpp | ||
---|---|---|
174 | I wanted to avoid exactly that (checking it after every use) because this function is used quite a lot in this file. | |
176 | I wanted to make this a non-functional change. The current/old behaviour is that we can run into a compiler abort (unreachable) for unsupported instructions. If we change unreachable into asserts, then the new behaviour for Release builds that don't have asserts is different. I.e., instead of aborting, the compiler continues its analysis with wrong numbers (it would wrap around as we add ~0U). I think that is undesired behaviour, would you agree? |
lib/Target/AArch64/AArch64BranchRelaxation.cpp | ||
---|---|---|
174 | Maybe it would now, but that might change someday. I think it would be safer to assert after every use. | |
176 | I'm not 100% sure about that. |
lib/Target/AArch64/AArch64BranchRelaxation.cpp | ||
---|---|---|
174 | 430* |
lib/Target/AArch64/AArch64BranchRelaxation.cpp | ||
---|---|---|
176 | Alright, excellent, I am actually more than happy to use asserts because it is much cleaner! And then I will simply do it after each call. |
lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp | ||
---|---|---|
338–340 | Maybe add a TII->getKnownInstSizeInBytes to avoid repeating the same assertion in N places? |
I'm not sure I understand this comment. Why wouldn't you check after every use of getInstSizeInBytes?