<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 - opt is defunct when code built without optimizations"
href="https://bugs.llvm.org/show_bug.cgi?id=35950">35950</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>opt is defunct when code built without optimizations
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>5.0
</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>Global Analyses
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>jirislaby@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>$ cat a.c
void foo()
{
int a;
for (a = 0; a < 100; a++)
;
}
$ clang -emit-llvm a.c -S -o - -O2
...
; Function Attrs: norecurse nounwind readnone uwtable
define void @foo() local_unnamed_addr #0 {
ret void
}
...
That one behaved correctly ^^^^^^^^^
Now no optimizations by clang:
$ clang -emit-llvm a.c -S -o a.bc
$ opt a.bc -O2 -o aopt.bc
$ llvm-dis aopt.bc
$ cat aopt.ll
...
; Function Attrs: noinline nounwind optnone uwtable
define void @foo() local_unnamed_addr #0 {
%1 = alloca i32, align 4
store i32 0, i32* %1, align 4
br label %2
; <label>:2: ; preds = %6, %0
%3 = load i32, i32* %1, align 4
%4 = icmp slt i32 %3, 100
br i1 %4, label %5, label %9
; <label>:5: ; preds = %2
br label %6
; <label>:6: ; preds = %5
%7 = load i32, i32* %1, align 4
%8 = add nsw i32 %7, 1
store i32 %8, i32* %1, align 4
br label %2
; <label>:9: ; preds = %2
ret void
}
That is not definitely OK ^^^^^^^
As can be seen, no optimization happened via `opt'.
When I remove the optnone attribute from the clang's -O0 build manually, opt
starts optimizing again.
Now if I try clang 4, it works as expected -- the function gets trimmed. The
difference in the assembly is indeed in `optnone':
$ diff -u <(clang-4.0 -emit-llvm a.c -S -o -) <(clang -emit-llvm a.c -S -o
-)|wdiff -d|colordiff
[--- /dev/fd/63-]{+++ /dev/fd/62+} 2018-01-15 15:12:37.253849366 +0100
@@ -3,7 +3,7 @@
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; Function Attrs: noinline nounwind {+optnone+} uwtable
define void @foo() #0 {
%1 = alloca i32, align 4
store i32 0, i32* %1, align 4
@@ -27,8 +27,10 @@
ret void
}
attributes #0 = { noinline nounwind {+optnone+} uwtable
"correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false"
"less-precise-fpmad"="false" "no-frame-pointer-elim"="true"
"no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false"
"no-jump-tables"="false" "no-nans-fp-math"="false"
"no-signed-zeros-fp-math"="false" "no-trapping-math"="false"
"stack-protector-buffer-size"="8" "target-cpu"="x86-64"
"target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false"
"use-soft-float"="false" }
[-!llvm.ident-]
{+!llvm.module.flags+} = !{!0}
{+!llvm.ident = !{!1}+}
!0 = {+!{i32 1, !"wchar_size", i32 4}
!1 =+} !{!"clang version [-4.0.1 (tags/RELEASE_401/final 305264)"}-] {+5.0.1
(tags/RELEASE_501/final 312548)"}+}</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>