6.2: [DestroyAddrHoisting] Skip init_enum_data_addrs. #81959
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation: Fix a miscompile introduced by
DestroyAddrHoisting
.The pass rewrites
destroy_addr
s, deleting the original instructions and inserting new ones at locations it determines via backwards dataflow. The pass does not process destroys of subobjects. When hoisting destroys for an aggregate, if adestroy_addr
of some field is encountered, the pass bails out.Previously, though, it was inadvertently processing destroys of
init_enum_data_addr
s. The result was to delete the originaldestroy_addr(init_enum_data_addr(%mem))
and to insert adestroy_addr(%mem)
at the new location. This transformation is incorrect in general; specifically, it is incorrect whenever theinit_enum_data_addr
is not followed by aninject_enum_addr
before thedestroy_addr(%mem)
. In order to destroy the whole enum, it must be known which case the enum is in, data which is provided by theinject_enum_addr
instruction; so if that instruction does not appear between theinit_enum_data_addr
and thedestroy_addr(%mem)
, the emitted code (which checks the enum case in order to determine how to destroy the enum) cannot behave correctly.This was happening because the utility it relies on views
init_enum_data_addr
s as referring to the same memory as the enum out of which that instruction was projecting. This is accurate for many uses, but fails to account for the data provided by theinject_enum_addr
.Here, this is fixed by making the optimization bail out when seeing a
destroy_addr(...(init_enum_data_addr()))
. This matches the behavior of the optimization when it is run on aggregates. For example, the optimization bails out when seeingdestroy_addr %single_field
where%single_field = struct_element_addr %singleton_struct
, thedestroy_addr
of the single field projected out of a struct which consists of only that field.Scope: Affects optimized code.
Issue: rdar://152431332
Original PR: #81952
Risk: Low, this adds a bailout to an optimization. Specifically, it makes bailing out of enums match the bailing out of structs and tuples.
Testing: Added test.
Reviewer: Meghana Gupta ( @meg-gupta ), Andrew Trick ( @atrick )