Skip to content

LLVM 3.6 giving incorrectly signed zeros #10377

@simonbyrne

Description

@simonbyrne

Using LLVM 3.6, branches involving comparison to zero can sometimes return the incorrect sign.

This has come up in #9336 (comment) and #9880 (comment).

Here is a minimal example:

julia> versioninfo()
Julia Version 0.4.0-dev+3639
Commit 7f7e9ae (2015-03-01 22:49 UTC)
Platform Info:
  System: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E7- 8850  @ 2.00GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Nehalem)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.6.0

julia> function foo(x,y)
           if x==y==0
               return y
           end
           y+1
       end
foo (generic function with 1 method)

julia> foo(0.0,-0.0)
0.0

And the @code_llvm foo(0.0,-0.0):

define double @julia_foo_42667(double, double) {
top:
  call void @llvm.dbg.value(metadata double %0, i64 0, metadata !10, metadata !16)
  call void @llvm.dbg.value(metadata double %1, i64 0, metadata !17, metadata !16)
  %2 = fcmp une double %0, %1, !dbg !18
  br i1 %2, label %L3, label %L1, !dbg !18

L1:                                               ; preds = %top
  call void @llvm.dbg.value(metadata double 0.000000e+00, i64 0, metadata !20, metadata !16)
  %phitmp = fcmp une double %0, 0.000000e+00, !dbg !18
  br i1 %phitmp, label %L3, label %if2, !dbg !18

if2:                                              ; preds = %L1
  ret double %0, !dbg !21

L3:                                               ; preds = %top, %L1
  %3 = fadd double %1, 1.000000e+00, !dbg !22
  ret double %3, !dbg !22
}

The problem here is that the if2 label it is returning %0 instead of %1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorupstreamThe issue is with an upstream dependency, e.g. LLVM

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions