[PATCH] After llvm r195496, code compiled with -Os get substantially larger

Dimitry Andric dimitry at andric.com
Sat Oct 18 09:21:38 PDT 2014


Hi grosbach, bkramer,

In FreeBSD, we have a particular piece of code, a boot loader, which must always fit in 7 kiB, so it is compiled with -Os, and various other parameters that minimize its size.

When I recently started working on importing clang 3.5.0 into the FreeBSD base system, I noticed that the code grew substantially when compiled with 3.5.0.  Previously, with clang 3.4.1, it was 31 bytes below the limit of 7168 bytes, but with 3.5.0 it went 145 bytes //over// the limit.  This is an increase of 176 bytes!

I bisected llvm trunk, and found that r195496 introduced this regression.  The problem is that X86TargetLowering::EmitCmp() now expands comparisons to 32-bit operations, even with -Os.  This is because it only checks for one possible size optimization attribute:

  DAG.getMachineFunction().getFunction()->getAttributes().hasAttribute(AttributeSet::FunctionIndex, Attribute::MinSize)

MinSize is only in effect for -Oz.  It should also check for Attribute::OptimizeForSize, which is in effect for -Os.

This diff adds the additional check, and fixes the original problem for me with the FreeBSD boot loader, which is compiled to its previous size again.

http://reviews.llvm.org/D5859

Files:
  lib/Target/X86/X86ISelLowering.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5859.15121.patch
Type: text/x-patch
Size: 722 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141018/cd66a29a/attachment.bin>


More information about the llvm-commits mailing list