This is an archive of the discontinued LLVM Phabricator instance.

Fix for 9807. Avoid over-relaxation of 8-bit immediates in integer arithmetic instructions.
ClosedPublic

Authored by DavidKreitzer on Jun 26 2015, 6:38 AM.

Details

Summary

During some code size experimentation, I observed that ~0.25% of total code size was attributable to this problem. The bug predominantly affects CMP, but I saw a few instances where it affected the other arithmetic ops like ADD, AND, etc.

I opted for this simple localized fix after considering other options that add new infrastructure to be able to tell from the MCFixup itself whether it needs to be relaxed. Note that I removed the mc-x86-disable-arith-relaxation flag, as I think it should no longer be necessary.

Diff Detail

Repository
rL LLVM

Event Timeline

DavidKreitzer retitled this revision from to Fix for 9807. Avoid over-relaxation of 8-bit immediates in integer arithmetic instructions..
DavidKreitzer updated this object.
DavidKreitzer edited the test plan for this revision. (Show Details)
DavidKreitzer added a subscriber: Unknown Object (MLST).

I decided to go ahead and take care of the FIXME regarding RIP-relative memory references in relaxable arith instructions. I submitted https://llvm.org/bugs/show_bug.cgi?id=23986 and added a new regression test, relax-arith3.s, that illustrates the current problem and verifies that this new (and ultimately simpler) patch fixes it.

The patch passes "make check-all".

rafael accepted this revision.Jun 29 2015, 12:54 PM
rafael edited edge metadata.

The code change itself LGTM.

Please change the test to use llvm-objdump.

test/MC/ELF/relax-arith2.s
9 ↗(On Diff #28701)

Can't you used llvm-objdump -d?

This revision is now accepted and ready to land.Jun 29 2015, 12:54 PM
majnemer added inline comments.
lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
247 ↗(On Diff #28701)

Please name this RelaxableOp to match the uppercase convention of the surrounding code.

DavidKreitzer edited edge metadata.

Fixed the style issue pointed out by David and a few others with braces, indentation, and an empty comment line. (Old habits die hard.)

Rafael, I'm happy to change the 2 new tests to use llvm-objdump instead of llvm-readobj if you think that is preferred. I just want to point out that llvm-readobj is used more predominantly in test/MC/ELF:

bash-4.3$ grep llvm-readobj *.s | wc -l
120
bash-4.3$ grep llvm-objdump *.s | wc -l
7

Thanks for the reviews!

Modified the new tests to use llvm-objdump instead of llvm-readobj. Thanks for the suggestion, Rafael. They do look nicer this way.

Thanks, tests LGTM too now!

This revision was automatically updated to reflect the committed changes.