[llvm-bugs] [Bug 35950] New: opt is defunct when code built without optimizations

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jan 15 06:12:10 PST 2018


https://bugs.llvm.org/show_bug.cgi?id=35950

            Bug ID: 35950
           Summary: opt is defunct when code built without optimizations
           Product: libraries
           Version: 5.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Global Analyses
          Assignee: unassignedbugs at nondot.org
          Reporter: jirislaby at gmail.com
                CC: llvm-bugs at lists.llvm.org

$ 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)"}+}

-- 
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/20180115/77dadab0/attachment.html>


More information about the llvm-bugs mailing list