This is an archive of the discontinued LLVM Phabricator instance.

getInstSizeInBytes: sentinel value fix for AArch64, AMDGPU, MSP430
AbandonedPublic

Authored by SjoerdMeijer on Aug 10 2016, 8:44 AM.

Details

Summary

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.

Diff Detail

Event Timeline

SjoerdMeijer retitled this revision from to getInstSizeInBytes: sentinel value fix for AArch64, AMDGPU, MSP430.
SjoerdMeijer updated this object.
SjoerdMeijer added a subscriber: llvm-commits.
rovka added a subscriber: rovka.Aug 11 2016, 3:59 AM
rovka added inline comments.
lib/Target/AArch64/AArch64BranchRelaxation.cpp
174

I'm not sure I understand this comment. Why wouldn't you check after every use of getInstSizeInBytes?

176

I think you can use an assert instead (here and everywhere else).

SjoerdMeijer added inline comments.Aug 11 2016, 5:58 AM
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.
This function computeBlockSize sees all instructions, so actually also checking it elsewhere would be redundant?

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?

rovka added inline comments.Aug 11 2016, 6:36 AM
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.
Anyway, if you insist on doing this, you should add a similar comment to MSP420BranchSelector, where you're also only checking after the first use.

176

I'm not 100% sure about that.
In the coding standards it says: "When assertions are disabled (i.e. in release builds), llvm_unreachable becomes a hint to compilers to skip generating code for this branch. If the compiler does not support this, it will fall back to the “abort” implementation."
So, yes, we see aborts now, but I'm not convinced that's always the intention (OTOH that might be old text, or I might be misreading it).

rovka added inline comments.Aug 11 2016, 6:37 AM
lib/Target/AArch64/AArch64BranchRelaxation.cpp
174

430*

SjoerdMeijer added inline comments.Aug 11 2016, 6:54 AM
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.

Use asserts for checking the return value.

arsenm added inline comments.Feb 21 2017, 4:04 PM
lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
338–340

Maybe add a TII->getKnownInstSizeInBytes to avoid repeating the same assertion in N places?

arsenm resigned from this revision.Nov 28 2017, 6:39 PM
dexonsmith resigned from this revision.Oct 19 2020, 6:54 PM
SjoerdMeijer abandoned this revision.Mar 17 2023, 1:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2023, 1:41 AM
Herald added a subscriber: kosarev. · View Herald Transcript