[LLVMbugs] [Bug 14361] New: optimizer produces incorrect code for simple arithmetic with i64 types

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Nov 16 07:24:27 PST 2012


http://llvm.org/bugs/show_bug.cgi?id=14361

             Bug #: 14361
           Summary: optimizer produces incorrect code for simple
                    arithmetic with i64 types
           Product: new-bugs
           Version: 3.1
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: vtjnash at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


The LLVM optimizer (createInstructionCombiningPass?) incorrectly transforms 
a+b == b+a
into
a == b
when a and b are i64 types. I am on a x86_64 machine.
(it correctly transforms that statement into true with smaller types)

---------------

$ clang -O0 opt-test.c 
$ ./a.out 
commutative? true
$ clang -O1 opt-test.c 
$ ./a.out 
commutative? false
$ cat opt-test.c
#include <stdio.h>
#include <stdint.h>

int __attribute__ ((noinline)) f(long long a, long long b) {
    return a+b == b+a;
}

int main() {
    printf("commutative? %s\n", (f(2,3) ? "true" : "false"));
}
$ clang --version
Apple clang version 3.1 (tags/Apple/clang-318.0.61) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.3.0
Thread model: posix


--------------
(as mentioned in
https://github.com/JuliaLang/julia/issues/1555#issuecomment-10438267)
Before optimization:

define i1 @f(i64, i64) {
top:
  %a = alloca i64, !dbg !5697
  %b = alloca i64, !dbg !5697
  store i64 %0, i64* %a, !dbg !5697
  store i64 %1, i64* %b, !dbg !5697
  %2 = load i64* %a, !dbg !5704
  %3 = load i64* %b, !dbg !5704
  %4 = add i64 %2, %3, !dbg !5704
  %5 = load i64* %b, !dbg !5704
  %6 = load i64* %a, !dbg !5704
  %7 = add i64 %5, %6, !dbg !5704
  %8 = icmp eq i64 %4, %7, !dbg !5704
  ret i1 %8, !dbg !5704
}


After optimization:

define i1 @f(i64, i64) {
top:
  %2 = icmp eq i64 %1, %0, !dbg !5697
  ret i1 %2, !dbg !5697
}

--------------

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list