Conversation
|
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/src/absint.jl b/src/absint.jl
index 62817f5..4a9632a 100644
--- a/src/absint.jl
+++ b/src/absint.jl
@@ -268,24 +268,24 @@ function get_base_and_offset(@nospecialize(larg::LLVM.Value); offsetAllowed::Boo
larg = operands(larg)[1]
continue
end
- if opcode(larg) == LLVM.API.LLVMGetElementPtr && pinst isa LLVM.Instruction
- b = LLVM.IRBuilder()
- position!(b, pinst)
- offty = LLVM.IntType(8 * sizeof(Int))
- offset2 = API.EnzymeComputeByteOffsetOfGEP(b, larg, offty)
- if isa(offset2, LLVM.ConstantInt)
- val = convert(Int, offset2)
- if offsetAllowed || val == 0
- offset += val
- larg = operands(larg)[1]
- continue
- else
- break
- end
- else
- break
- end
- end
+ if opcode(larg) == LLVM.API.LLVMGetElementPtr && pinst isa LLVM.Instruction
+ b = LLVM.IRBuilder()
+ position!(b, pinst)
+ offty = LLVM.IntType(8 * sizeof(Int))
+ offset2 = API.EnzymeComputeByteOffsetOfGEP(b, larg, offty)
+ if isa(offset2, LLVM.ConstantInt)
+ val = convert(Int, offset2)
+ if offsetAllowed || val == 0
+ offset += val
+ larg = operands(larg)[1]
+ continue
+ else
+ break
+ end
+ else
+ break
+ end
+ end
end
if isa(larg, LLVM.BitCastInst) || isa(larg, LLVM.AddrSpaceCastInst) || isa(larg, LLVM.IntToPtrInst)
larg = operands(larg)[1]
diff --git a/src/errors.jl b/src/errors.jl
index 08c49dc..e917ed9 100644
--- a/src/errors.jl
+++ b/src/errors.jl
@@ -524,29 +524,29 @@ function julia_error(
return seen[cur]
end
-@static if VERSION < v"1.11-"
-else
- if isa(cur, LLVM.LoadInst) && isa(value_type(cur), LLVM.PointerType) && LLVM.addrspace(value_type(operands(cur)[1])) == Derived
- larg, off = get_base_and_offset(operands(cur)[1]; inst=ncur, inttoptr=true)
- if isa(larg, LLVM.ConstantInt) && off == sizeof(Int)
- ptr = reinterpret(Ptr{Cvoid}, convert(UInt, larg))
- obj = Base.unsafe_pointer_to_objref(ptr)
+ @static if VERSION < v"1.11-"
+ else
+ if isa(cur, LLVM.LoadInst) && isa(value_type(cur), LLVM.PointerType) && LLVM.addrspace(value_type(operands(cur)[1])) == Derived
+ larg, off = get_base_and_offset(operands(cur)[1]; inst = ncur, inttoptr = true)
+ if isa(larg, LLVM.ConstantInt) && off == sizeof(Int)
+ ptr = reinterpret(Ptr{Cvoid}, convert(UInt, larg))
+ obj = Base.unsafe_pointer_to_objref(ptr)
if obj isa Memory && obj == typeof(obj).instance
return make_batched(ncur, prevbb)
end
- end
+ end
end
- if isa(cur, LLVM.ConstantExpr) && isa(value_type(cur), LLVM.PointerType) && LLVM.addrspace(value_type(cur)) == Derived
- larg, off = get_base_and_offset(cur; inst=first(instructions(position(prevbb))), inttoptr=true)
- if isa(larg, LLVM.ConstantInt) && (off == sizeof(Int) || off == 0)
- ptr = reinterpret(Ptr{Cvoid}, convert(UInt, larg))
- obj = Base.unsafe_pointer_to_objref(ptr)
+ if isa(cur, LLVM.ConstantExpr) && isa(value_type(cur), LLVM.PointerType) && LLVM.addrspace(value_type(cur)) == Derived
+ larg, off = get_base_and_offset(cur; inst = first(instructions(position(prevbb))), inttoptr = true)
+ if isa(larg, LLVM.ConstantInt) && (off == sizeof(Int) || off == 0)
+ ptr = reinterpret(Ptr{Cvoid}, convert(UInt, larg))
+ obj = Base.unsafe_pointer_to_objref(ptr)
if obj isa Memory && obj == typeof(obj).instance
return make_batched(ncur, prevbb)
end
- end
+ end
end
-end
+ end
legal, TT, byref = abs_typeof(cur, true)
diff --git a/src/llvm/transforms.jl b/src/llvm/transforms.jl
index fced4df..e0bab8e 100644
--- a/src/llvm/transforms.jl
+++ b/src/llvm/transforms.jl
@@ -2298,31 +2298,31 @@ function checkNoAssumeFalse(mod::LLVM.Module, shouldshow::Bool = false)
end
function rewrite_generic_memory!(mod::LLVM.Module)
-@static if VERSION < v"1.11-"
-else
- for f in functions(mod), bb in blocks(f)
- iter = LLVM.API.LLVMGetFirstInstruction(bb)
- while iter != C_NULL
- inst = LLVM.Instruction(iter)
- iter = LLVM.API.LLVMGetNextInstruction(iter)
- if !isa(inst, LLVM.LoadInst)
- continue
- end
-
- if isa(operands(inst)[1], LLVM.ConstantExpr)
+ return @static if VERSION < v"1.11-"
+ else
+ for f in functions(mod), bb in blocks(f)
+ iter = LLVM.API.LLVMGetFirstInstruction(bb)
+ while iter != C_NULL
+ inst = LLVM.Instruction(iter)
+ iter = LLVM.API.LLVMGetNextInstruction(iter)
+ if !isa(inst, LLVM.LoadInst)
+ continue
+ end
+
+ if isa(operands(inst)[1], LLVM.ConstantExpr)
legal2, obj = absint(inst)
if legal2 && obj isa Memory && obj == typeof(obj).instance
- b = LLVM.IRBuilder()
- position!(b, inst)
- replace_uses!(inst, unsafe_to_llvm(b, obj))
- LLVM.API.LLVMInstructionEraseFromParent(inst)
- continue
- end
- end
- end
+ b = LLVM.IRBuilder()
+ position!(b, inst)
+ replace_uses!(inst, unsafe_to_llvm(b, obj))
+ LLVM.API.LLVMInstructionEraseFromParent(inst)
+ continue
+ end
+ end
+ end
+ end
end
end
-end
function removeDeadArgs!(mod::LLVM.Module, tm::LLVM.TargetMachine)
# We need to run globalopt first. This is because remove dead args will otherwise |
Benchmark Results
Benchmark PlotsA plot of the benchmark results has been uploaded as an artifact at https://github.com/EnzymeAD/Enzyme.jl/actions/runs/17654587380/artifacts/3989541443. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2561 +/- ##
==========================================
+ Coverage 74.93% 75.00% +0.06%
==========================================
Files 56 56
Lines 17445 17494 +49
==========================================
+ Hits 13073 13121 +48
- Misses 4372 4373 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| ptr = reinterpret(Ptr{Cvoid}, convert(UInt, larg)) | ||
| obj = Base.unsafe_pointer_to_objref(ptr) | ||
| if obj isa Memory && obj == typeof(obj).instance | ||
| return make_batched(ncur, prevbb) | ||
| end | ||
| end | ||
| end | ||
| if isa(cur, LLVM.ConstantExpr) && isa(value_type(cur), LLVM.PointerType) && LLVM.addrspace(value_type(cur)) == Derived | ||
| larg, off = get_base_and_offset(cur; inst=ncur, inttoptr=true) | ||
| if isa(larg, LLVM.ConstantInt) && off == sizeof(Int) | ||
| ptr = reinterpret(Ptr{Cvoid}, convert(UInt, larg)) | ||
| obj = Base.unsafe_pointer_to_objref(ptr) | ||
| if obj isa Memory && obj == typeof(obj).instance | ||
| return make_batched(ncur, prevbb) | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Do you need to preserve the pointers? (side note, indentation looks off)
There was a problem hiding this comment.
Nope pointers don't need preservation as they were baked into Ir so already preserved from Julia.
As for fmt, honestly my preference would be setting up a nightly auto format pr like we have in reactant
There was a problem hiding this comment.
I am okay with that, but it would break the open PRs
There was a problem hiding this comment.
we can wait to merge that until any specific big ones are in [or only for certain files]
Separated from #2555
This simplifies the 0-sized memory creation during similar.
The issue from broadcasting stems from the inability to tell the inner pointer from the newly created array doesn't alias with any of the inputs. The complexity of the "check if zero sized and pick a load from this global vs a new alloca" complicates this -- though is not sufficient in isolation.
before:
after: