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

Incorrect derivative on -O0 #6

Closed
timkaler opened this issue Sep 13, 2019 · 0 comments · Fixed by #7
Closed

Incorrect derivative on -O0 #6

timkaler opened this issue Sep 13, 2019 · 0 comments · Fixed by #7

Comments

@timkaler
Copy link
Contributor

; ModuleID = 'silent_failure.c'
source_filename = "silent_failure.c"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

$_ZSt4fabsf = comdat any

@.str = private unnamed_addr constant [36 x i8] c"hello! %f, res2 %f, da: %f, db: %f\0A\00", align 1

; Function Attrs: noinline optnone uwtable
define dso_local void @compute_sumabs(float* %a, float* %b, float* %ret) #0 {
entry:
  %a.addr = alloca float*, align 8
  %b.addr = alloca float*, align 8
  %ret.addr = alloca float*, align 8
  store float* %a, float** %a.addr, align 8
  store float* %b, float** %b.addr, align 8
  store float* %ret, float** %ret.addr, align 8
  %0 = load float*, float** %a.addr, align 8
  %1 = load float, float* %0, align 4
  %call = call float @_ZSt4fabsf(float %1)
  %2 = load float*, float** %b.addr, align 8
  %3 = load float, float* %2, align 4
  %call1 = call float @_ZSt4fabsf(float %3)
  %add = fadd float %call, %call1
  %4 = load float*, float** %ret.addr, align 8
  store float %add, float* %4, align 4
  ret void
}

; Function Attrs: noinline nounwind optnone uwtable
define linkonce_odr dso_local float @_ZSt4fabsf(float %__x) #1 comdat {
entry:
  %__x.addr = alloca float, align 4
  store float %__x, float* %__x.addr, align 4
  %0 = load float, float* %__x.addr, align 4
  %1 = call float @llvm.fabs.f32(float %0)
  ret float %1
}

; Function Attrs: noinline norecurse optnone uwtable
define dso_local i32 @main(i32 %argc, i8** %argv) #2 {
entry:
  %retval = alloca i32, align 4
  %argc.addr = alloca i32, align 4
  %argv.addr = alloca i8**, align 8
  %a = alloca float, align 4
  %b = alloca float, align 4
  %da = alloca float, align 4
  %db = alloca float, align 4
  %ret = alloca float, align 4
  %dret = alloca float, align 4
  store i32 0, i32* %retval, align 4
  store i32 %argc, i32* %argc.addr, align 4
  store i8** %argv, i8*** %argv.addr, align 8
  store float 2.000000e+00, float* %a, align 4
  store float 3.000000e+00, float* %b, align 4
  store float 0.000000e+00, float* %da, align 4
  store float 0.000000e+00, float* %db, align 4
  store float 0.000000e+00, float* %ret, align 4
  store float 1.000000e+00, float* %dret, align 4
  call void @compute_sumabs(float* %a, float* %b, float* %ret)
  %0 = call double (...) @__enzyme_autodiff.f64(void (float*, float*, float*)* @compute_sumabs, float* %a, float* %da, float* %b, float* %db, float* %ret, float* %dret)
  %1 = load float, float* %ret, align 4
  %conv = fpext float %1 to double
  %2 = load float, float* %ret, align 4
  %conv1 = fpext float %2 to double
  %3 = load float, float* %da, align 4
  %conv2 = fpext float %3 to double
  %4 = load float, float* %db, align 4
  %conv3 = fpext float %4 to double
  %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i32 0, i32 0), double %conv, double %conv1, double %conv2, double %conv3)
  ret i32 0
}

declare double @__enzyme_autodiff.f64(...)

declare dso_local i32 @printf(i8*, ...) #3

; Function Attrs: nounwind readnone speculatable
declare float @llvm.fabs.f32(float) #4

attributes #0 = { noinline 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" }
attributes #1 = { 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" }
attributes #2 = { noinline norecurse 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" }
attributes #3 = { "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-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" }
attributes #4 = { nounwind readnone speculatable }

!llvm.module.flags = !{!0}
!llvm.ident = !{!1}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang version 7.1.0 "}
tgymnich pushed a commit that referenced this issue Mar 23, 2023
wsmoses pushed a commit that referenced this issue May 16, 2023
wsmoses pushed a commit that referenced this issue May 18, 2023
wsmoses pushed a commit that referenced this issue May 21, 2023
wsmoses added a commit that referenced this issue May 21, 2023
* compiles with llvm-16 (old PM is gone so I could not run opt) (#1)

* port to llvm-16 (not backward-compatible with older llvms), WIP

* wip, but probably not correct on may places

* rule out old PM on llvm 16 and above

* #if LLVM_VERSION_MAJOR >= 16, WIP

* #if LLVM_VERSION_MAJOR >= 16, WIP

* #if LLVM_VERSION_MAJOR >= 16, WIP

* #if LLVM_VERSION_MAJOR >= 16, WIP

* #if LLVM_VERSION_MAJOR >= 16, WIP

* #if LLVM_VERSION_MAJOR >= 16

* Llvm 16 (#2)

* fix for argmemonly

* disabling old pm tests where new pm tests exist (#3)

* Disable old pm tests fix (#4)

* disabling old pm tests where new pm tests exist: fix typo

* fix build with llvm-16 (#5)

* fix build with llvm < 16 (#6)

* Attribute::Memory fixes (#7)

but still getting zeros instead of derivatives

* curly brace out of macro (#8)

* fix typo (#9)

* fix for llvm-16 (#10)

* fix typo

* fix

* Llvm 16 gha (#11)

* enable build with llvm 16

* enable llvm-16 once this gets to main (on both linux and mac os)

* docker run -it --rm --workdir /Enzyme -v /home/stp/go/src/github.com/stepasite/Enzyme/enzyme/Enzyme:/Enzyme clang-format-lint --clang-format-executable /clang-format/clang-format11 -r --exclude ./Enzyme/SCEV --style llvm --inplace true ./Enzyme

* forward mode vector: new pm tests, wip

* llvm-16: fixing tests, wip (#12)

* llvm-16 tests, WIP

* resolving latest test/ll commits (#13)

* Llvm 16 tests (#14)

* llvm-16 tests, WIP

* fix bug introduced in (FunctionUtils.cpp)

* llvm 16 tests, wip

* llvm tests, WIP (#15)

* continued test fixes

* fixup

* fix build

* fix

* cleanup

* fixes

* fix

* fix attr

* fix format

* fixup

* fix attrs

* fix

* fix

* fix

* fix sret

* fix

* add type analysis

* activity analysis

* fix ta

* fix

* fix

* fixes

* more tests

* more fixes

* 297

* more tests

* fix

* fix

* fix

* fix

* fix

---------

Co-authored-by: Pavel Stepanek <stepasite@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant