<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - Missed optimization opportunity for constant folding"
href="https://bugs.llvm.org/show_bug.cgi?id=35271">35271</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Missed optimization opportunity for constant folding
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</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>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>ishiura-compiler@ml.kwansei.ac.jp
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>We compiled two programs (A1.c, A2.c) by LLVM/clang-6.0 with -O3 option.
Though the two programs are equivalent, LLVM/clang outputs different assembly
codes.
+---------------------------------+---------------------------------+
| A1.c | A2.c |
+---------------------------------+---------------------------------+
|int main (void) |int main (void) |
|{ |{ |
| volatile int x = 1; | volatile int x = 1; |
| int t = 1/(1%(2/x)); | int t = 1; |
| | |
| if (t != 1) __builtin_abort(); | if (t != 1) __builtin_abort(); |
| return 0; | return 0; |
|} |} |
+---------------------------------+---------------------------------+
+-------------------------------------+-------------------------------------+
| A1.s (clang-6.0 A1.c -O3 -S) | A2.s (clang-6.0 A2.c -O3 -S) |
+-------------------------------------+-------------------------------------+
|main: # @main |main: # @main |
| .cfi_startproc | .cfi_startproc |
|# BB#0: |# BB#0: |
| pushq %rax | |
| .cfi_def_cfa_offset 16 | |
| movl $1, 4(%rsp) | movl $1, -4(%rsp) |
| movl $2, %eax | |
| xorl %edx, %edx | |
| idivl 4(%rsp) | |
| movl %eax, %ecx | |
| movl $1, %eax | |
| xorl %edx, %edx | |
| idivl %ecx | |
| cmpl $1, %edx | |
| jne .LBB0_2 | |
|# BB#1: | |
| xorl %eax, %eax | xorl %eax, %eax |
| popq %rcx | |
| retq | retq |
|.LBB0_2: | |
| callq abort | |
|.Lfunc_end0: |.Lfunc_end0: |
| .size main, .Lfunc_end0-main | .size main, .Lfunc_end0-main |
+-------------------------------------+-------------------------------------+
FYI, GCC generates almost the same assembly codes for A1.c and A2.c.
+-------------------------------------+-------------------------------------+
| A1.s (gcc-8.0.0 A1.c -O3 -S) | A2.s (gcc-8.0.0 A2.c -O3 -S) |
+-------------------------------------+-------------------------------------+
|main: |main: |
| | |
|.LFB0: |.LFB0: |
|.cfi_startproc |.cfi_startproc |
|movl $1, -4(%rsp) |movl $1, -4(%rsp) |
|movl -4(%rsp), %eax | |
|xorl %eax, %eax |xorl %eax, %eax |
|ret |ret |
|.cfi_endproc |.cfi_endproc |
|.LFE0: |.LFE0: |
|.size main, .-main |.size main, .-main |
+-------------------------------------+-------------------------------------+
clang version 6.0.0 (trunk 317454)
Target: x86_64-unknown-linux-gnu
Thread model: posix
gcc-8.0 (GCC) 8.0.0 20171109 (experimental)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</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>