Just to triple check, why is
core::intrinsics::abort emitting 2x
I can't seem to trigger the same behavior using llc, so the only reason I can imagine is that this is required for alignment purposes or similar.
call @llvm.trap -> ud2, and rustc sets a TargetMachine option to "trap on unreachable" so the
unreachable also becomes an ud2. Manually feeding IR to llc will be missing the latter.
So do we have a bug in the implementation of
core::arch::x86_64::ud2, etc. ?
IIUC, we could use
core::hint::unreachable_unchecked() to only emit a single
unreachable, and therefore a single
So that works: https://gcc.godbolt.org/z/jrhehx
While we're mitigating harm by asking the backend to emit ud2 rather than just letting control flow fall off the end of the function, the entire optimization pipeline will still exploit that
unreachable is, well, unreachable.
Ah, makes sense
Also I am not even sure if every backend does this.
Then I maybe should open an LLVM bug for an x86 backend optimization ?
multiple ud2s can be coalesced
but the x86 backend doesn't do that
I mean, feel free, but this is literal peanuts
Not only are the ud2s a minuscle fraction of instructions emitted, they're also just two bytes each