[llvm-dev] Prevent anonymous union optimization

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Thu Jun 1 07:47:15 PDT 2017


On 1 June 2017 at 00:23, Антон Кочков via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> And then performs bitcasts all the time it accesses that structure in the union.

Are these bitcasts actually causing problems? There may be edge cases
where the extra IR-instruction causes an analysis to decide it's done
as much as it can, but in general I'd expect them to be free (i.e.
generate no code at runtime).

> How to force it generate union.anon = type { %struct.struct1 } without
> changing the struct1 (it's an external API so better to avoid the
> changes here)?

There's no way to do this without modifying Clang. And even then
you're arbitrarily choosing one member of the union to have
precedence, which seems pretty sketchy to me. You're just moving the
bitcasts from the struct1 accesses to all the other members.

Cheers.

Tim.


More information about the llvm-dev mailing list