[llvm-bugs] [Bug 32618] New: Improve merging of identical branches
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Apr 11 00:46:48 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=32618
Bug ID: 32618
Summary: Improve merging of identical branches
Product: clang
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: LLVM Codegen
Assignee: unassignedclangbugs at nondot.org
Reporter: cuoq at trust-in-soft.com
CC: llvm-bugs at lists.llvm.org
Consider the following code:
va_list ap;
void *result;
va_start(ap, ptr_type);
switch (ptr_type) {
case 0: result = va_arg(ap, int*); break;
case 1: result = va_arg(ap, char*); break;
case 2: result = va_arg(ap, short*); break;
default: result = va_arg(ap, void*); break;
}
va_end(ap);
Clang correctly recognizes that the assembly code for all four branches is
identical, which is the difficult part (the source code for the branches is
different and cannot be merged by the programmer unless
https://bugs.llvm.org/show_bug.cgi?id=32616 is resolved). At the time of
writing, the Compiler Explorer trunk version produces:
cmpl $2, %edi
je .LBB0_5
cmpl $1, %edi
je .LBB0_5
testl %edi, %edi
.LBB0_5:
(Compiler Explorer link: https://godbolt.org/g/0NvnSX )
This shows that Clang correctly manages to eliminate the conditional branch in
the pattern:
jcc L
L:
Unfortunately, Clang leaves the “testl %edi, %edi” that preceded the
conditional branch (and is now useless), and this prevents it from eliminating
all the other conditional branches.
It would be nice if all of the assembly snippet posted above could be
eliminated, especially since there are code patterns that must be different at
the source level and identical in assembly, and Clang already recognizes those.
--
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/20170411/1da58077/attachment.html>
More information about the llvm-bugs
mailing list