<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - More optimize opportunity for constant folding"
href="http://llvm.org/bugs/show_bug.cgi?id=20916">20916</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>More optimize opportunity for constant folding
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>ishiura-compiler@ml.kwansei.ac.jp
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>The two programs (A.c) and (B.c) only differ by one line
(marked by "// <---HERE"), where (B.c) simply folds local variable a to 1.
Resulting codes by "clang -O3 -S" are different;
the code (A.s) for (A.c) is less optimized than (B.s) for (B.c).
(A.c)
int main (void)
{
static int a = 1;
volatile int b = 1;
int c = (a / (0 + b)) >= 2; // <---HERE
if (c != 0);
else __builtin_abort();
return 0;
}
(B.c)
int main (void)
{
static int a = 1;
volatile int b = 1;
int c = (1 / (0 + b)) >= 2; // <---HERE
if (c != 0);
else __builtin_abort();
return 0;
}
+-----------------------------+-----------------------------+
|(A.s) |(B.s) |
+-----------------------------+-----------------------------+
|main: # @main |main: # @main |
| .cfi_startproc |.LFB0: |
|# BB#0: # %entry | .cfi_startproc |
| pushq %rax | |
|.Ltmp0: |# BB#0: # %entry |
| .cfi_def_cfa_offset 16 | |
| movl $1, 4(%rsp) | movl $1, -4(%rsp) |
| movl 4(%rsp), %eax | movl -4(%rsp), %eax |
| leal 1(%rax), %ecx | |
| cmpl $2, %ecx | |
| ja .LBB0_2 | |
|# BB#1: # %entry | |
| cmpl $2, %eax | |
| jge .LBB0_3 | |
|.LBB0_2: # %if.end | |
| xorl %eax, %eax | xorl %eax, %eax |
| popq %rdx | |
| retq | retq |
|.LBB0_3: # %if.then |.Ltmp0: |
| callq abort | |
| .size main, .Ltmp1-main | .size main, .Ltmp0-main |
| .cfi_endproc | .cfi_endproc |
+-----------------------------+-----------------------------+
FYI, "gcc-4.4.7 -O2 -S" compiles both (A.c) and (B.c) into (B.s).
$ clang -v
clang version 3.6.0 (trunk 217334)
Target: x86_64-unknown-linux-gnu
Thread model: posix</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>