You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found out that Clang codegen emits an unnecessary memcpy for an empty C++ class with an empty struct. I don't know if other (more common) cases are effected.
The problem is within the CodeGenFunction::EmitAggregateCopy function in clang/lib/CodeGen/CGExprAgg.cpp. The function only checks if the record is empty using Record->isEmpty(). Either isEmpty is wrong in that case or the calculated data layout of the record is a better choice to skip memcpy emission.
The text was updated successfully, but these errors were encountered:
… content
Clang codegen emits an unnecessary memcpy for C++ class without content. This patch fixes the issue.
See llvm#59336
Please let me know if the patch is going into the right direction that it can be accepted. If yes, I'll finish it with test cases and also extend it to C.
Hi all,
I found out that Clang codegen emits an unnecessary
memcpy
for an empty C++ class with an empty struct. I don't know if other (more common) cases are effected.The following code
generates the LLVM IR (see https://godbolt.org/z/4hjx8xxqf)
Interestingly, the
memcpy
is generated with an emptytbaa.struct metadata
, indicating that thememcpy
is copying nothing.During IR optimization the
memcpy
is optimized to a load/store.The problem is within the
CodeGenFunction::EmitAggregateCopy
function inclang/lib/CodeGen/CGExprAgg.cpp
. The function only checks if the record is empty usingRecord->isEmpty()
. EitherisEmpty
is wrong in that case or the calculated data layout of the record is a better choice to skipmemcpy
emission.The text was updated successfully, but these errors were encountered: