Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nondeterministic ranges test failure #23522

Closed
yuyichao opened this issue Aug 31, 2017 · 3 comments · Fixed by #23564
Closed

nondeterministic ranges test failure #23522

yuyichao opened this issue Aug 31, 2017 · 3 comments · Fixed by #23564
Assignees
Labels
compiler:codegen Generation of LLVM IR and native code GC Garbage collector

Comments

@yuyichao
Copy link
Contributor

Similar to #23497 but I think this is actually quite difference since the test is nondeterministic even after the random number is fixed. Possibly a compiler/llvm bug. I haven't looked into it yet.

Reproduced with the following code.
When it fails, none of strt, Δ, stop are NaN but the start and end of r are both NaN.

@noinline function f(strt, Δ, i, r, stop)
    @show(strt, Δ, i, r, stop)
    ccall(:jl_breakpoint, Void, ())
    error("")
end

function range_fuzztests(N)
    for i = 1:N
        strt = 1.3761519988366908
        Δ = -0.7928641255557751
        stop = 0.5832878732809157
        r = strt:Δ:stop
        if !(strt == first(r))
            f(strt, Δ, i, r, stop)
        end
    end
end
# @code_warntype range_fuzztests(5 * 2^16)
# @code_llvm range_fuzztests(5 * 2^16)
range_fuzztests(5 * 2^16)
@yuyichao
Copy link
Contributor Author

Actually I believe this is another missing GC root. Likely in codegen and possibly similar to #23520

@yuyichao yuyichao added GC Garbage collector compiler:codegen Generation of LLVM IR and native code labels Aug 31, 2017
@yuyichao
Copy link
Contributor Author

From @code_llvm 1.0:1.0:1.0

; Function colon
; Location: twiceprecision.jl
define void @julia_colon_62316(%StepRangeLen addrspace(11)* noalias nocapture sret, double, double, double) #0 {
top:
  %4 = alloca [6 x %jl_value_t addrspace(10)*], align 8
  %gcframe82 = alloca [3 x %jl_value_t addrspace(10)*], align 8
  %gcframe82.sub = getelementptr inbounds [3 x %jl_value_t addrspace(10)*], [3 x %jl_value_t addrspace(10)*]* %gcframe82, i64 0, i64 0
  %5 = getelementptr inbounds [3 x %jl_value_t addrspace(10)*], [3 x %jl_value_t addrspace(10)*]* %gcframe82, i64 0, i64 1
  %6 = bitcast %jl_value_t addrspace(10)** %5 to i8*
  call void @llvm.memset.p0i8.i32(i8* %6, i8 0, i32 16, i32 8, i1 false)
  %7 = alloca [2 x i64], align 8
  %8 = alloca [2 x i64], align 8
  %9 = alloca [2 x i64], align 8
  %10 = alloca %StepRangeLen, align 8
  %ptls_i8 = call i8* asm "movq %fs:0, $0;\0Aaddq $$-10920, $0", "=r,~{dirflag},~{fpsr},~{flags}"() #7
  %11 = bitcast [3 x %jl_value_t addrspace(10)*]* %gcframe82 to i64*
  store i64 2, i64* %11, align 8
  %12 = getelementptr inbounds [3 x %jl_value_t addrspace(10)*], [3 x %jl_value_t addrspace(10)*]* %gcframe82, i64 0, i64 1
  %13 = bitcast i8* %ptls_i8 to i64*
  %14 = load i64, i64* %13, align 8
  %15 = bitcast %jl_value_t addrspace(10)** %12 to i64*
  store i64 %14, i64* %15, align 8
  %16 = bitcast i8* %ptls_i8 to %jl_value_t addrspace(10)***
  store %jl_value_t addrspace(10)** %gcframe82.sub, %jl_value_t addrspace(10)*** %16, align 8
; Location: twiceprecision.jl:380
  %17 = fcmp une double %2, 0.000000e+00
  br i1 %17, label %L17, label %if

if:                                               ; preds = %top
  %18 = call noalias %jl_value_t addrspace(10)* @jl_gc_pool_alloc(i8* %ptls_i8, i32 1424, i32 16)
  %19 = addrspacecast %jl_value_t addrspace(10)* %18 to %jl_value_t addrspace(11)*
  %20 = bitcast %jl_value_t addrspace(11)* %19 to %jl_value_t addrspace(10)* addrspace(11)*
  %21 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)* addrspace(11)* %20, i64 -1
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465608667184 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)* addrspace(11)* %21, align 8
  %22 = bitcast %jl_value_t addrspace(10)* %18 to %jl_value_t addrspace(10)* addrspace(10)*
  %23 = addrspacecast %jl_value_t addrspace(10)* addrspace(10)* %22 to %jl_value_t addrspace(10)* addrspace(11)*
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465643814608 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)* addrspace(11)* %23, align 8
  %24 = addrspacecast %jl_value_t addrspace(10)* %18 to %jl_value_t addrspace(12)*
  %25 = getelementptr inbounds [3 x %jl_value_t addrspace(10)*], [3 x %jl_value_t addrspace(10)*]* %gcframe82, i64 0, i64 2
  store %jl_value_t addrspace(10)* %18, %jl_value_t addrspace(10)** %25, align 8
  call void @jl_throw(%jl_value_t addrspace(12)* %24)
  unreachable

L17:                                              ; preds = %top
  %.sub = getelementptr inbounds [6 x %jl_value_t addrspace(10)*], [6 x %jl_value_t addrspace(10)*]* %4, i64 0, i64 0
; Location: twiceprecision.jl:383
  %26 = addrspacecast [2 x i64]* %7 to [2 x i64] addrspace(11)*
  call void @julia_rat_62317([2 x i64] addrspace(11)* noalias nocapture sret %26, double %2)
  %27 = getelementptr inbounds [2 x i64], [2 x i64]* %7, i64 0, i64 1
  %28 = load i64, i64* %27, align 8
; Location: twiceprecision.jl:384
  %29 = icmp eq i64 %28, 0
  br i1 %29, label %L193, label %L32

L32:                                              ; preds = %L17
; Location: twiceprecision.jl:383
  %30 = getelementptr inbounds [2 x i64], [2 x i64]* %7, i64 0, i64 0
  %31 = load i64, i64* %30, align 8
; Location: twiceprecision.jl:384
  %32 = sitofp i64 %31 to double
  %33 = sitofp i64 %28 to double
  %34 = fdiv double %32, %33
  %35 = fcmp oeq double %34, %2
  br i1 %35, label %if25, label %L193

if25:                                             ; preds = %L32
; Location: twiceprecision.jl:385
  %36 = addrspacecast [2 x i64]* %8 to [2 x i64] addrspace(11)*
  call void @julia_rat_62317([2 x i64] addrspace(11)* noalias nocapture sret %36, double %1)
  %37 = getelementptr inbounds [2 x i64], [2 x i64]* %8, i64 0, i64 1
  %38 = load i64, i64* %37, align 8
; Location: twiceprecision.jl:386
  %39 = addrspacecast [2 x i64]* %9 to [2 x i64] addrspace(11)*
  call void @julia_rat_62317([2 x i64] addrspace(11)* noalias nocapture sret %39, double %3)
; Location: twiceprecision.jl:387
  %40 = icmp eq i64 %38, 0
  br i1 %40, label %L193, label %if26

L193:                                             ; preds = %L177, %if48, %L100, %L68, %L32, %L157, %after_srem, %if31, %if30, %if29, %if27, %if26, %if25, %L17
; Location: twiceprecision.jl:406
  %41 = fsub double %3, %1
  %42 = fdiv double %41, %2
; Location: twiceprecision.jl:407
  %43 = fcmp uge double %42, 0.000000e+00
  br i1 %43, label %L204, label %L250

if26:                                             ; preds = %if25
; Location: twiceprecision.jl:386
  %44 = getelementptr inbounds [2 x i64], [2 x i64]* %9, i64 0, i64 1
  %45 = load i64, i64* %44, align 8
; Location: twiceprecision.jl:387
  %46 = icmp eq i64 %45, 0
  br i1 %46, label %L193, label %if27

if27:                                             ; preds = %if26
; Location: twiceprecision.jl:385
  %47 = getelementptr inbounds [2 x i64], [2 x i64]* %8, i64 0, i64 0
  %48 = load i64, i64* %47, align 8
; Location: twiceprecision.jl:387
  %49 = sitofp i64 %48 to double
  %50 = sitofp i64 %38 to double
  %51 = fdiv double %49, %50
  %52 = fcmp une double %51, %1
  br i1 %52, label %L193, label %L68

L68:                                              ; preds = %if27
; Location: twiceprecision.jl:386
  %53 = getelementptr inbounds [2 x i64], [2 x i64]* %9, i64 0, i64 0
  %54 = load i64, i64* %53, align 8
; Location: twiceprecision.jl:387
  %55 = sitofp i64 %54 to double
  %56 = sitofp i64 %45 to double
  %57 = fdiv double %55, %56
  %58 = fcmp oeq double %57, %3
  br i1 %58, label %if29, label %L193

if29:                                             ; preds = %L68
; Location: twiceprecision.jl:389
  %59 = call i64 @julia_lcm_62318(i64 %38, i64 %28)
; Location: twiceprecision.jl:391
  %60 = icmp eq i64 %59, 0
  br i1 %60, label %L193, label %if30

if30:                                             ; preds = %if29
  %61 = sitofp i64 %59 to double
  %62 = fmul double %61, %1
  %63 = call double @llvm.fabs.f64(double %62)
  %64 = fcmp ugt double %63, 0x4340000000000000
  br i1 %64, label %L193, label %if31

if31:                                             ; preds = %if30
  %65 = fmul double %61, %2
  %66 = call double @llvm.fabs.f64(double %65)
  %67 = fcmp ugt double %66, 0x4340000000000000
  br i1 %67, label %L193, label %if32

if32:                                             ; preds = %if31
  switch i64 %38, label %after_srem [
    i64 0, label %fail
    i64 -1, label %if33
  ]

fail:                                             ; preds = %if32
  call void @jl_throw(%jl_value_t addrspace(12)* addrspacecast (%jl_value_t* inttoptr (i64 140465621913936 to %jl_value_t*) to %jl_value_t addrspace(12)*))
  unreachable

after_srem:                                       ; preds = %if32
  %68 = srem i64 %59, %38
  %69 = icmp eq i64 %68, 0
  br i1 %69, label %if33, label %L193

if33:                                             ; preds = %if32, %after_srem
  switch i64 %28, label %L100 [
    i64 0, label %fail34
    i64 -1, label %if39
  ]

fail34:                                           ; preds = %if33
  call void @jl_throw(%jl_value_t addrspace(12)* addrspacecast (%jl_value_t* inttoptr (i64 140465621913936 to %jl_value_t*) to %jl_value_t addrspace(12)*))
  unreachable

L100:                                             ; preds = %if33
  %70 = srem i64 %59, %28
  %71 = icmp eq i64 %70, 0
  br i1 %71, label %if39, label %L193

if39:                                             ; preds = %L100, %if33
; Location: twiceprecision.jl:393
; Function round; {
; Location: float.jl:353
; Function trunc; {
; Location: float.jl:693
  %72 = call double @llvm.rint.f64(double %62)
  %73 = fcmp oge double %72, 0xC3E0000000000000
  %74 = fcmp olt double %72, 0x43E0000000000000
  %or.cond = and i1 %73, %74
  br i1 %or.cond, label %if41, label %L115

if41:                                             ; preds = %if39
;}}
; Location: twiceprecision.jl:394
; Function round; {
; Location: float.jl:353
; Function trunc; {
; Location: float.jl:693
  %75 = call double @llvm.rint.f64(double %65)
  %76 = fcmp oge double %75, 0xC3E0000000000000
  %77 = fcmp olt double %75, 0x43E0000000000000
  %or.cond133 = and i1 %76, %77
  br i1 %or.cond133, label %if43, label %L135

L115:                                             ; preds = %if39
;}}
; Location: twiceprecision.jl:393
; Function round; {
; Location: float.jl:353
; Function trunc; {
; Location: float.jl:696
  %78 = call noalias %jl_value_t addrspace(10)* @jl_gc_pool_alloc(i8* %ptls_i8, i32 1424, i32 16)
  %79 = addrspacecast %jl_value_t addrspace(10)* %78 to %jl_value_t addrspace(11)*
  %80 = bitcast %jl_value_t addrspace(11)* %79 to %jl_value_t addrspace(10)* addrspace(11)*
  %81 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)* addrspace(11)* %80, i64 -1
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465608533920 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)* addrspace(11)* %81, align 8
  %82 = bitcast %jl_value_t addrspace(10)* %78 to double addrspace(10)*
  store double %72, double addrspace(10)* %82, align 8
  %83 = getelementptr inbounds [3 x %jl_value_t addrspace(10)*], [3 x %jl_value_t addrspace(10)*]* %gcframe82, i64 0, i64 2
  store %jl_value_t addrspace(10)* %78, %jl_value_t addrspace(10)** %83, align 8
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465520320000 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %.sub, align 8
  %84 = getelementptr inbounds [6 x %jl_value_t addrspace(10)*], [6 x %jl_value_t addrspace(10)*]* %4, i64 0, i64 1
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465522804528 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %84, align 8
  %85 = getelementptr inbounds [6 x %jl_value_t addrspace(10)*], [6 x %jl_value_t addrspace(10)*]* %4, i64 0, i64 2
  store %jl_value_t addrspace(10)* %78, %jl_value_t addrspace(10)** %85, align 8
  %86 = call %jl_value_t addrspace(10)* @jsys1_Type_38464(%jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465612974944 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %.sub, i32 3)
  %87 = addrspacecast %jl_value_t addrspace(10)* %86 to %jl_value_t addrspace(12)*
  store %jl_value_t addrspace(10)* %86, %jl_value_t addrspace(10)** %83, align 8
  call void @jl_throw(%jl_value_t addrspace(12)* %87)
  unreachable

if43:                                             ; preds = %if41
; Location: float.jl:694
  %88 = fptosi double %72 to i64
;}}
; Location: twiceprecision.jl:394
; Function round; {
; Location: float.jl:353
; Function trunc; {
; Location: float.jl:694
  %89 = fptosi double %75 to i64
;}}
; Location: twiceprecision.jl:395
  %90 = mul i64 %59, %54
  %91 = mul i64 %88, %45
  %92 = sub i64 %90, %91
  %93 = mul i64 %89, %45
  %94 = add i64 %92, %93
  %95 = icmp ne i64 %94, -9223372036854775808
  %96 = icmp ne i64 %93, -1
  %97 = or i1 %96, %95
  %98 = icmp ne i64 %93, 0
  %99 = and i1 %98, %97
  br i1 %99, label %pass45, label %fail44

L135:                                             ; preds = %if41
; Location: twiceprecision.jl:394
; Function round; {
; Location: float.jl:353
; Function trunc; {
; Location: float.jl:696
  %100 = call noalias %jl_value_t addrspace(10)* @jl_gc_pool_alloc(i8* %ptls_i8, i32 1424, i32 16)
  %101 = addrspacecast %jl_value_t addrspace(10)* %100 to %jl_value_t addrspace(11)*
  %102 = bitcast %jl_value_t addrspace(11)* %101 to %jl_value_t addrspace(10)* addrspace(11)*
  %103 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)* addrspace(11)* %102, i64 -1
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465608533920 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)* addrspace(11)* %103, align 8
  %104 = bitcast %jl_value_t addrspace(10)* %100 to double addrspace(10)*
  store double %75, double addrspace(10)* %104, align 8
  %105 = getelementptr inbounds [3 x %jl_value_t addrspace(10)*], [3 x %jl_value_t addrspace(10)*]* %gcframe82, i64 0, i64 2
  store %jl_value_t addrspace(10)* %100, %jl_value_t addrspace(10)** %105, align 8
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465520320000 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %.sub, align 8
  %106 = getelementptr inbounds [6 x %jl_value_t addrspace(10)*], [6 x %jl_value_t addrspace(10)*]* %4, i64 0, i64 1
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465522804528 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %106, align 8
  %107 = getelementptr inbounds [6 x %jl_value_t addrspace(10)*], [6 x %jl_value_t addrspace(10)*]* %4, i64 0, i64 2
  store %jl_value_t addrspace(10)* %100, %jl_value_t addrspace(10)** %107, align 8
  %108 = call %jl_value_t addrspace(10)* @jsys1_Type_38464(%jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465612974944 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %.sub, i32 3)
  %109 = addrspacecast %jl_value_t addrspace(10)* %108 to %jl_value_t addrspace(12)*
  store %jl_value_t addrspace(10)* %108, %jl_value_t addrspace(10)** %105, align 8
  call void @jl_throw(%jl_value_t addrspace(12)* %109)
  unreachable

fail44:                                           ; preds = %if43
;}}
; Location: twiceprecision.jl:395
  call void @jl_throw(%jl_value_t addrspace(12)* addrspacecast (%jl_value_t* inttoptr (i64 140465621913936 to %jl_value_t*) to %jl_value_t addrspace(12)*))
  unreachable

pass45:                                           ; preds = %if43
  %110 = sdiv i64 %94, %93
  %111 = icmp sgt i64 %110, 0
  %112 = select i1 %111, i64 %110, i64 0
; Location: twiceprecision.jl:397
; Function isbetween; {
; Location: twiceprecision.jl:694
  %113 = add nsw i64 %112, -1
  %114 = sitofp i64 %113 to double
  %115 = fmul double %114, %2
  %116 = fadd double %115, %1
  %117 = fcmp ult double %116, %1
  %.pre = fmul double %2, 5.000000e-01
  %.pre131 = fadd double %.pre, %3
  %118 = fcmp ugt double %116, %.pre131
  %or.cond134 = or i1 %117, %118
  br i1 %or.cond134, label %L157, label %if48

L157:                                             ; preds = %pass45
  %119 = fcmp ugt double %.pre131, %116
  %120 = fcmp ugt double %116, %1
  %or.cond135 = or i1 %119, %120
  br i1 %or.cond135, label %L193, label %if48

if48:                                             ; preds = %L157, %pass45
  %121 = sitofp i64 %112 to double
  %122 = fmul double %121, %2
  %123 = fadd double %122, %1
  %124 = fcmp ult double %123, %1
  %125 = fcmp ugt double %123, %3
  %or.cond136 = or i1 %124, %125
  br i1 %or.cond136, label %L177, label %L193

L177:                                             ; preds = %if48
  %126 = fcmp ult double %123, %3
  %127 = fcmp ugt double %123, %1
  %or.cond137 = or i1 %126, %127
  br i1 %or.cond137, label %if51, label %L193

if51:                                             ; preds = %L177
;}
; Location: twiceprecision.jl:400
  %128 = addrspacecast %StepRangeLen* %10 to %StepRangeLen addrspace(11)*
  call void @julia_floatrange_62320(%StepRangeLen addrspace(11)* noalias nocapture sret %128, %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465608533920 to %jl_value_t*) to %jl_value_t addrspace(10)*), i64 %88, i64 %89, i64 %112, i64 %59)
  %129 = bitcast %StepRangeLen* %10 to i8*
  %130 = bitcast %StepRangeLen addrspace(11)* %0 to i8 addrspace(11)*
  call void @llvm.memcpy.p11i8.p0i8.i32(i8 addrspace(11)* %130, i8* %129, i32 48, i32 8, i1 false)
  %131 = load %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %12, align 8
  %132 = bitcast i8* %ptls_i8 to %jl_value_t addrspace(10)**
  store %jl_value_t addrspace(10)* %131, %jl_value_t addrspace(10)** %132, align 8
  ret void

L204:                                             ; preds = %L193
; Location: twiceprecision.jl:409
  %133 = fcmp une double %42, 0.000000e+00
  br i1 %133, label %L213, label %L250

L250:                                             ; preds = %L204, %L193, %if76
  %len.0 = phi i64 [ %183, %if76 ], [ 0, %L193 ], [ 1, %L204 ]
; Location: twiceprecision.jl:417
; Function steprangelen_hp; {
; Location: twiceprecision.jl:334
  %134 = call noalias %jl_value_t addrspace(10)* @jl_gc_pool_alloc(i8* %ptls_i8, i32 1424, i32 16)
  %135 = addrspacecast %jl_value_t addrspace(10)* %134 to %jl_value_t addrspace(11)*
  %136 = bitcast %jl_value_t addrspace(11)* %135 to %jl_value_t addrspace(10)* addrspace(11)*
  %137 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)* addrspace(11)* %136, i64 -1
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465608533920 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)* addrspace(11)* %137, align 8
  %138 = bitcast %jl_value_t addrspace(10)* %134 to double addrspace(10)*
  store double %1, double addrspace(10)* %138, align 8
  %139 = getelementptr inbounds [3 x %jl_value_t addrspace(10)*], [3 x %jl_value_t addrspace(10)*]* %gcframe82, i64 0, i64 2
  store %jl_value_t addrspace(10)* %134, %jl_value_t addrspace(10)** %139, align 8
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465543501168 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %.sub, align 8
  %140 = getelementptr inbounds [6 x %jl_value_t addrspace(10)*], [6 x %jl_value_t addrspace(10)*]* %4, i64 0, i64 1
  store %jl_value_t addrspace(10)* %134, %jl_value_t addrspace(10)** %140, align 8
  %141 = call %jl_value_t addrspace(10)* @jl_f__apply(%jl_value_t addrspace(10)* addrspacecast (%jl_value_t* null to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %.sub, i32 2)
  %142 = call noalias %jl_value_t addrspace(10)* @jl_gc_pool_alloc(i8* %ptls_i8, i32 1424, i32 16)
  %143 = addrspacecast %jl_value_t addrspace(10)* %142 to %jl_value_t addrspace(11)*
  %144 = bitcast %jl_value_t addrspace(11)* %143 to %jl_value_t addrspace(10)* addrspace(11)*
  %145 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)* addrspace(11)* %144, i64 -1
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465608533920 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)* addrspace(11)* %145, align 8
  %146 = bitcast %jl_value_t addrspace(10)* %142 to double addrspace(10)*
  store double %2, double addrspace(10)* %146, align 8
  store %jl_value_t addrspace(10)* %142, %jl_value_t addrspace(10)** %139, align 8
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465543501168 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %.sub, align 8
  store %jl_value_t addrspace(10)* %142, %jl_value_t addrspace(10)** %140, align 8
  %147 = call %jl_value_t addrspace(10)* @jl_f__apply(%jl_value_t addrspace(10)* addrspacecast (%jl_value_t* null to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %.sub, i32 2)
; Function Type; {
; Location: twiceprecision.jl:348
; Function Type; {
; Location: range.jl:200
  %148 = icmp slt i64 %len.0, 0
  br i1 %148, label %L263, label %L280

L263:                                             ; preds = %L250
  %149 = call %jl_value_t addrspace(10)* @jl_box_int64(i64 signext %len.0)
  store %jl_value_t addrspace(10)* %149, %jl_value_t addrspace(10)** %139, align 8
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465520148488 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %.sub, align 8
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465611373728 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %140, align 8
  %150 = getelementptr inbounds [6 x %jl_value_t addrspace(10)*], [6 x %jl_value_t addrspace(10)*]* %4, i64 0, i64 2
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465656653104 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %150, align 8
  %151 = getelementptr inbounds [6 x %jl_value_t addrspace(10)*], [6 x %jl_value_t addrspace(10)*]* %4, i64 0, i64 3
  store %jl_value_t addrspace(10)* %149, %jl_value_t addrspace(10)** %151, align 8
  %152 = call %jl_value_t addrspace(10)* @"jsys1_#print_to_string#249_35723"(%jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465649640656 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %.sub, i32 4)
  store %jl_value_t addrspace(10)* %152, %jl_value_t addrspace(10)** %139, align 8
  %153 = call noalias %jl_value_t addrspace(10)* @jl_gc_pool_alloc(i8* %ptls_i8, i32 1424, i32 16)
  %154 = addrspacecast %jl_value_t addrspace(10)* %153 to %jl_value_t addrspace(11)*
  %155 = bitcast %jl_value_t addrspace(11)* %154 to %jl_value_t addrspace(10)* addrspace(11)*
  %156 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)* addrspace(11)* %155, i64 -1
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465608667184 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)* addrspace(11)* %156, align 8
  %157 = bitcast %jl_value_t addrspace(10)* %153 to %jl_value_t addrspace(10)* addrspace(10)*
  %158 = addrspacecast %jl_value_t addrspace(10)* addrspace(10)* %157 to %jl_value_t addrspace(10)* addrspace(11)*
  store %jl_value_t addrspace(10)* %152, %jl_value_t addrspace(10)* addrspace(11)* %158, align 8
  %159 = addrspacecast %jl_value_t addrspace(10)* %153 to %jl_value_t addrspace(12)*
  store %jl_value_t addrspace(10)* %153, %jl_value_t addrspace(10)** %139, align 8
  call void @jl_throw(%jl_value_t addrspace(12)* %159)
  unreachable

L280:                                             ; preds = %L250
;}}
; Function twiceprecision; {
; Location: twiceprecision.jl:225
  %160 = bitcast %jl_value_t addrspace(10)* %147 to i64 addrspace(10)*
  %161 = addrspacecast i64 addrspace(10)* %160 to i64 addrspace(11)*
  %162 = load i64, i64 addrspace(11)* %161, align 8
;}
; Function Type; {
; Location: twiceprecision.jl:348
; Function Type; {
; Location: range.jl:200
  %163 = bitcast i64 %162 to double
;}}}
  %164 = fsub double %163, %163
  %165 = bitcast %jl_value_t addrspace(10)* %147 to %TwicePrecision addrspace(10)*
  %166 = addrspacecast %TwicePrecision addrspace(10)* %165 to %TwicePrecision addrspace(11)*
  %167 = getelementptr inbounds %TwicePrecision, %TwicePrecision addrspace(11)* %166, i64 0, i32 1
  %168 = load double, double addrspace(11)* %167, align 8
  %169 = fadd double %164, %168
  %.sroa.0.sroa.0.0..sroa.0.0..sroa_raw_cast.sroa_raw_cast = bitcast %jl_value_t addrspace(10)* %141 to i8 addrspace(10)*
  %170 = bitcast %StepRangeLen addrspace(11)* %0 to i8 addrspace(11)*
  %171 = addrspacecast i8 addrspace(11)* %170 to i8*
  call void @llvm.memcpy.p0i8.p10i8.i64(i8* %171, i8 addrspace(10)* %.sroa.0.sroa.0.0..sroa.0.0..sroa_raw_cast.sroa_raw_cast, i64 16, i32 1, i1 false)
  %.sroa.0.sroa.2.0..sroa.0.0..sroa_cast.sroa_idx123 = getelementptr inbounds %StepRangeLen, %StepRangeLen addrspace(11)* %0, i64 0, i32 1
  %.sroa.0.sroa.2.0..sroa.0.0..sroa_cast.sroa_cast = bitcast %TwicePrecision addrspace(11)* %.sroa.0.sroa.2.0..sroa.0.0..sroa_cast.sroa_idx123 to i64 addrspace(11)*
  store i64 %162, i64 addrspace(11)* %.sroa.0.sroa.2.0..sroa.0.0..sroa_cast.sroa_cast, align 8
  %.sroa.0.sroa.3.0..sroa.0.0..sroa_cast.sroa_idx124 = getelementptr inbounds %StepRangeLen, %StepRangeLen addrspace(11)* %0, i64 0, i32 1, i32 1
  store double %169, double addrspace(11)* %.sroa.0.sroa.3.0..sroa.0.0..sroa_cast.sroa_idx124, align 8
  %.sroa.3.0..sroa_idx118 = getelementptr inbounds %StepRangeLen, %StepRangeLen addrspace(11)* %0, i64 0, i32 2
  store i64 %len.0, i64 addrspace(11)* %.sroa.3.0..sroa_idx118, align 8
  %.sroa.4.0..sroa_idx119 = getelementptr inbounds %StepRangeLen, %StepRangeLen addrspace(11)* %0, i64 0, i32 3
  store i64 1, i64 addrspace(11)* %.sroa.4.0..sroa_idx119, align 8
  %172 = load %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %12, align 8
  %173 = bitcast i8* %ptls_i8 to %jl_value_t addrspace(10)**
  store %jl_value_t addrspace(10)* %172, %jl_value_t addrspace(10)** %173, align 8
  ret void

L213:                                             ; preds = %L204
; Location: twiceprecision.jl:412
; Function round; {
; Location: float.jl:353
; Function trunc; {
; Location: float.jl:693
  %174 = call double @llvm.rint.f64(double %42)
  %175 = fcmp ult double %174, 0xC3E0000000000000
  %phitmp = fcmp uge double %174, 0x43E0000000000000
  %or.cond138 = or i1 %175, %phitmp
  br i1 %or.cond138, label %L227, label %if76

if76:                                             ; preds = %L213
; Location: float.jl:694
  %176 = fptosi double %174 to i64
;}}
; Location: twiceprecision.jl:413
  %177 = sitofp i64 %176 to double
  %178 = fmul double %177, %2
  %179 = fadd double %178, %1
; Location: twiceprecision.jl:415
  %180 = fcmp ogt double %179, %3
  %not. = fcmp olt double %1, %3
  %"#temp#9.0" = and i1 %180, %not.
  %181 = fcmp olt double %179, %3
  %not.139 = fcmp olt double %3, %1
  %"#temp#10.0" = and i1 %181, %not.139
  %.neg = sext i1 %"#temp#9.0" to i64
  %.neg129 = sext i1 %"#temp#10.0" to i64
  %.neg130 = add i64 %176, 1
; Location: twiceprecision.jl:412
  %182 = add i64 %.neg130, %.neg
; Location: twiceprecision.jl:415
  %183 = add i64 %182, %.neg129
  br label %L250

L227:                                             ; preds = %L213
; Location: twiceprecision.jl:412
; Function round; {
; Location: float.jl:353
; Function trunc; {
; Location: float.jl:696
  %184 = call noalias %jl_value_t addrspace(10)* @jl_gc_pool_alloc(i8* %ptls_i8, i32 1424, i32 16)
  %185 = addrspacecast %jl_value_t addrspace(10)* %184 to %jl_value_t addrspace(11)*
  %186 = bitcast %jl_value_t addrspace(11)* %185 to %jl_value_t addrspace(10)* addrspace(11)*
  %187 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)* addrspace(11)* %186, i64 -1
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465608533920 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)* addrspace(11)* %187, align 8
  %188 = bitcast %jl_value_t addrspace(10)* %184 to double addrspace(10)*
  store double %174, double addrspace(10)* %188, align 8
  %189 = getelementptr inbounds [3 x %jl_value_t addrspace(10)*], [3 x %jl_value_t addrspace(10)*]* %gcframe82, i64 0, i64 2
  store %jl_value_t addrspace(10)* %184, %jl_value_t addrspace(10)** %189, align 8
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465520320000 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %.sub, align 8
  %190 = getelementptr inbounds [6 x %jl_value_t addrspace(10)*], [6 x %jl_value_t addrspace(10)*]* %4, i64 0, i64 1
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465522804528 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %190, align 8
  %191 = getelementptr inbounds [6 x %jl_value_t addrspace(10)*], [6 x %jl_value_t addrspace(10)*]* %4, i64 0, i64 2
  store %jl_value_t addrspace(10)* %184, %jl_value_t addrspace(10)** %191, align 8
  %192 = call %jl_value_t addrspace(10)* @jsys1_Type_38464(%jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140465612974944 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %.sub, i32 3)
  %193 = addrspacecast %jl_value_t addrspace(10)* %192 to %jl_value_t addrspace(12)*
  store %jl_value_t addrspace(10)* %192, %jl_value_t addrspace(10)** %189, align 8
  call void @jl_throw(%jl_value_t addrspace(12)* %193)
  unreachable
;}}
}

The return value of jl_f__apply doesn't seem to be properly rooted. As an example, there's

  %141 = call %jl_value_t addrspace(10)* @jl_f__apply(%jl_value_t addrspace(10)* addrspacecast (%jl_value_t* null to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %.sub, i32 2)
  %142 = call noalias %jl_value_t addrspace(10)* @jl_gc_pool_alloc(i8* %ptls_i8, i32 1424, i32 16)

which doesn't root %141 anywhere and %141 is used below. It's used in memcpy which IIRC isn't handled as a memory op in the gc frame lowering pass, maybe that's why it's not handled well?

@yuyichao
Copy link
Contributor Author

On another note that's unrelated to this bug. colon(::Float64, ::Float64, ::Float64) is allocating when it creates the TwicePrecision due to the following AST

      SSAValue(17) = (Core._apply)(Base.TwicePrecision{Float64}, start::Float64)::Base.TwicePrecision{Float64}
      SSAValue(15) = (Core._apply)(Base.TwicePrecision{Float64}, step::Float64)::Base.TwicePrecision{Float64}

The inference/codegen should probably be able to optimize this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code GC Garbage collector
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants