Hi all,<br><br>Continuing to enjoy LLVM. I'm seeing something strange with the simple function "f(a,b) = (a+b == b+a)", which before optimization passes has the following LLVM code:<br><br>define i1 @f(i64, i64) {<br>
top:<br> %a = alloca i64, !dbg !5697<br> %b = alloca i64, !dbg !5697<br> store i64 %0, i64* %a, !dbg !5697<br> store i64 %1, i64* %b, !dbg !5697<br> %2 = load i64* %a, !dbg !5704<br> %3 = load i64* %b, !dbg !5704<br>
%4 = add i64 %2, %3, !dbg !5704<br> %5 = load i64* %b, !dbg !5704<br> %6 = load i64* %a, !dbg !5704<br> %7 = add i64 %5, %6, !dbg !5704<br> %8 = icmp eq i64 %4, %7, !dbg !5704<br> ret i1 %8, !dbg !5704<br>}<br><br>
After our set of optimization passes, I get this strange result:<br><br>define i1 @f(i64, i64) {<br>top:<br> %2 = icmp eq i64 %1, %0, !dbg !5697<br> ret i1 %2, !dbg !5697<br>}<br><br>If I switch the order of the arguments in the second addition, so the function is "f(a,b) = (a+b == a+b)", then the code is optimized to<br>
<br>define i1 @f(i64, i64) {<br>top:<br> ret i1 true, !dbg !5832<br>}<br><br>which is correct.<br><br>This is LLVM 3.1. You can see the full list of passes I'm running here: <a href="https://github.com/JuliaLang/julia/blob/master/src/codegen.cpp#L2564">https://github.com/JuliaLang/julia/blob/master/src/codegen.cpp#L2564</a><br>
<br>The linked code currently contains a workaround I found, which was to disable the first two instcombine passes. With that, the original function also reduces to returning a constant true.<br><br>Is this a known bug, or am I just mis-ordering the optimization passes somehow?<br>
<br>Many thanks,<br><br>-Jeff<br>