https://bugs.llvm.org/show_bug.cgi?id=46237

            Bug ID: 46237
           Summary: Size regression -Os constant propagation difference
                    results in larger code
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangb...@nondot.org
          Reporter: michaeljcl...@mac.com
                CC: llvm-bugs@lists.llvm.org, neeil...@live.com,
                    richard-l...@metafoo.co.uk

-Os is using more space than -O2 for this example.

--- BEGIN SCRIPT ---

cat >f.c <<EOF
typedef unsigned long long u64;

u64 f(u64 x, u64 y, u64 z)
{
    return ((z & 3u) << 6) | ((y & 7u) << 3) | (z & 7u);
}
EOF
clang -O2 -c -o O2.o f.c
clang -Os -c -o Os.o f.c
objdump -d O2.o
objdump -d Os.o 

--- END SCRIPT ---

It seems that lifting a small immediate constant into a register takes more
space due to the requirement of a 32-bit immediate for register immediate
constant synthesis on x86, whereas the inlined constant fits within an imm8
operand. It seems more profitable to not hoist constants <= 255 which are used
as operands in simple arith/logical ops 2 or 3 times.


O2.o: <f>:
   0:   89 d0                   mov    %edx,%eax
   2:   c1 e0 06                shl    $0x6,%eax
   5:   0f b6 c8                movzbl %al,%ecx
   8:   83 e6 07                and    $0x7,%esi
   b:   83 e2 07                and    $0x7,%edx
   e:   48 8d 04 f2             lea    (%rdx,%rsi,8),%rax
  12:   48 09 c8                or     %rcx,%rax
  15:   c3                      retq   

Os.o: <f>:
   0:   89 d0                   mov    %edx,%eax
   2:   c1 e0 06                shl    $0x6,%eax
   5:   0f b6 c8                movzbl %al,%ecx
   8:   b8 07 00 00 00          mov    $0x7,%eax
   d:   48 21 c6                and    %rax,%rsi
  10:   48 21 c2                and    %rax,%rdx
  13:   48 8d 04 f2             lea    (%rdx,%rsi,8),%rax
  17:   48 09 c8                or     %rcx,%rax
  1a:   c3                      retq   


$ clang --version
Ubuntu clang version
11.0.0-++20200607081810+e664d0543f8-1~exp1~20200607063338.223 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to