Skip to content

Commit 30e0519

Browse files
authored
Don't mark math fns as nounwind, just willreturn (#2807)
* Don't mark math fns as nounwind, just willreturn * fix * Update Project.toml
1 parent a2c161e commit 30e0519

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ BFloat16s = "0.2, 0.3, 0.4, 0.5, 0.6"
4242
CEnum = "0.4, 0.5"
4343
ChainRulesCore = "1"
4444
EnzymeCore = "0.8.16"
45-
Enzyme_jll = "0.0.220"
45+
Enzyme_jll = "0.0.221"
4646
GPUArraysCore = "0.1.6, 0.2"
4747
GPUCompiler = "1.6.2"
4848
LLVM = "9.1"

src/compiler.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,14 +1057,12 @@ end
10571057
LLVM.Attribute[LLVM.EnumAttribute("readnone"), StringAttribute("enzyme_shouldrecompute"),
10581058
EnumAttribute("willreturn"),
10591059
EnumAttribute("nosync"),
1060-
EnumAttribute("nounwind"),
10611060
EnumAttribute("nofree"),
10621061
]
10631062
else
10641063
LLVM.Attribute[EnumAttribute("memory", NoEffects.data), StringAttribute("enzyme_shouldrecompute"),
10651064
EnumAttribute("willreturn"),
10661065
EnumAttribute("nosync"),
1067-
EnumAttribute("nounwind"),
10681066
EnumAttribute("nofree")]
10691067
end
10701068
handleCustom(state, custom, k_name, llvmfn, name, attrs)

src/compiler/utils.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ Base.@assume_effects :removable :foldable :nothrow function is_noreturn(f::LLVM.
146146
return false
147147
end
148148

149+
Base.@assume_effects :removable :foldable :nothrow function is_nounwind(f::LLVM.Function)::Bool
150+
for attr in collect(function_attributes(f))
151+
if kind(attr) == kind(EnumAttribute("nounwind"))
152+
return true
153+
end
154+
end
155+
return false
156+
end
157+
149158
Base.@assume_effects :removable :foldable :nothrow function is_readonly(f::LLVM.Function)::Bool
150159
intr = LLVM.API.LLVMGetIntrinsicID(f)
151160
if intr == LLVM.Intrinsic("llvm.lifetime.start").id

src/llvm/transforms.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,7 @@ function remove_readonly_unused_calls!(fn::LLVM.Function, next::Set{String})
16321632
return false
16331633
end
16341634

1635-
err_is_readonly = !is_noreturn(cur)
1635+
err_is_readonly = true
16361636

16371637
for bb in blocks(cur)
16381638
for inst in instructions(bb)
@@ -1654,7 +1654,7 @@ function remove_readonly_unused_calls!(fn::LLVM.Function, next::Set{String})
16541654

16551655
changed = set_readonly!(fn)
16561656

1657-
if length(calls) == 0 || hasUser
1657+
if length(calls) == 0 || hasUser || !is_nounwind(fn)
16581658
return changed
16591659
end
16601660

0 commit comments

Comments
 (0)