Stream: t-compiler/wg-llvm

Topic: abort emits 2 instructions


gnzlbg (Sep 12 2019 at 11:45, on Zulip):

Just to triple check, why is core::intrinsics::abort emitting 2x ud2s? https://gcc.godbolt.org/z/FoqYRc
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.

rkruppe (Sep 12 2019 at 12:15, on Zulip):

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.

gnzlbg (Sep 12 2019 at 13:00, on Zulip):

So do we have a bug in the implementation of core::intrinsics::abort, core::arch::x86_64::ud2, etc. ?

gnzlbg (Sep 12 2019 at 13:01, on Zulip):

IIUC, we could use core::hint::unreachable_unchecked() to only emit a single unreachable, and therefore a single ud2 ?

gnzlbg (Sep 12 2019 at 13:02, on Zulip):

So that works: https://gcc.godbolt.org/z/jrhehx

rkruppe (Sep 12 2019 at 13:03, on Zulip):

No

rkruppe (Sep 12 2019 at 13:03, on Zulip):

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.

gnzlbg (Sep 12 2019 at 13:04, on Zulip):

Ah, makes sense

rkruppe (Sep 12 2019 at 13:04, on Zulip):

Also I am not even sure if every backend does this.

gnzlbg (Sep 12 2019 at 13:04, on Zulip):

Then I maybe should open an LLVM bug for an x86 backend optimization ?

gnzlbg (Sep 12 2019 at 13:04, on Zulip):

multiple ud2s can be coalesced

gnzlbg (Sep 12 2019 at 13:04, on Zulip):

but the x86 backend doesn't do that

rkruppe (Sep 12 2019 at 13:05, on Zulip):

I mean, feel free, but this is literal peanuts

rkruppe (Sep 12 2019 at 13:05, on Zulip):

Not only are the ud2s a minuscle fraction of instructions emitted, they're also just two bytes each

Last update: Nov 15 2019 at 09:55UTC