This is an archive of the discontinued LLVM Phabricator instance.

[X86] Improve code size on X86 segment moves
ClosedPublic

Authored by niravd on Aug 4 2016, 8:57 AM.

Details

Summary

Moves of a value to a segment register from a 16-bit register is
equivalent to one from it's corresponding 32-bit register. Match gas's
behavior and rewrite instructions to the shorter of equivalent forms.

Diff Detail

Repository
rL LLVM

Event Timeline

niravd updated this revision to Diff 66812.Aug 4 2016, 8:57 AM
niravd retitled this revision from to [X86] Improve code size on X86 segment moves.
niravd added reviewers: rnk, ab.
niravd updated this object.
niravd added a subscriber: llvm-commits.
rnk edited edge metadata.Aug 4 2016, 10:25 AM

I dono, if someone really writes movl %eax, %cs I would assume they really want the prefix, right? Obviously gas does something else, but that's surprising to me.

niravd added a comment.Aug 8 2016, 8:39 AM

Adding Joerg's and my comments below because phabricator dropped them on the floor.

Nirav said:

The ISA doesn't actually have a 32-bit mov instruction of this form (though all the processors I've seen accept the bytes pattern associated with the 32-bit variant). I doubt that anyone
dealing with explicit segment twiddling ever wants the effectless prefix added. AFAIK these instructions are only ever emitted via explicit assembly so they it would be easy enough to
add the byte via an explicit ".byte" directive.

Ideally we'd only have the 16-bit mov instruction which accepts but ignores the OpSize prefix, but we need to accept the text syntax "mov %eax, %fs" to handle what objdump dumps,
hence this workaround.

Joerg Sonnenberger said:

Sometimes people want explicitly sized assembler for later runtime
patching. I'm not sure it matters in this case.

Joerg

rnk accepted this revision.Aug 8 2016, 9:30 AM
rnk edited edge metadata.

lgtm I'm OK doing what gas does here for now.

lib/Target/X86/AsmParser/X86AsmParser.cpp
2346 ↗(On Diff #66812)

Please make this and the comment below complete sentences.

2352 ↗(On Diff #66812)

s/reg/Reg/

This revision is now accepted and ready to land.Aug 8 2016, 9:30 AM
This revision was automatically updated to reflect the committed changes.