[llvm-bugs] [Bug 46681] New: Missed optimization: Inlining behavior can lead to larger code with -Oz than other optimization levels
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Jul 10 19:40:14 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=46681
Bug ID: 46681
Summary: Missed optimization: Inlining behavior can lead to
larger code with -Oz than other optimization levels
Product: libraries
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: Interprocedural Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: vlad at tsyrklevich.net
CC: llvm-bugs at lists.llvm.org
The following example demonstrates this problem. Note that the call to f(a)
with an uninitialized value is somewhat nonsensical--I blame creduce for that:
__attribute__((__noreturn__)) void assert();
void* d(void *e) { return e; }
void f(void *g) {
if (g)
assert();
}
static void compiles_to_ret() {
void *a;
f(a);
}
int example() {
typedef void (*i)();
i j = d(compiles_to_ret);
j();
return 2;
}
When compiled with clang -arch arm64 -Oz, example is compiled to:
0000000000000018 _example:
18: fd 7b bf a9 stp x29, x30, [sp, #-16]!
1c: fd 03 00 91 mov x29, sp
20: 00 00 00 94 bl _compiles_to_ret
24: 40 00 80 52 mov w0, #2
28: fd 7b c1 a8 ldp x29, x30, [sp], #16
2c: c0 03 5f d6 ret
0000000000000030 _compiles_to_ret:
30: c0 03 5f d6 ret
With -Os, it compiles to:
0000000000000018 _example:
18: 40 00 80 52 mov w0, #2
1c: c0 03 5f d6 ret
Using -mllvm -inline-threshold=10 fixes this trivial example; however, in the
original source code, which I can't share, it takes an inline threshold of over
100 to cause compiles_to_ret to be inlined. The following fixes the issue by
running the optimization pipeline twice:
$ clang -arch arm64 ex.c -Oz -S -emit-llvm -o ex.ll
$ clang -arch arm64 ex.ll -Oz -c ex.ll -o ex.o
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200711/c410537c/attachment-0001.html>
More information about the llvm-bugs
mailing list