This is an archive of the discontinued LLVM Phabricator instance.

[SimplifyCFG] Allow dropping block that only contains ephemeral values
AcceptedPublic

Authored by nikic on Jun 28 2023, 5:59 AM.

Details

Summary

Perform the TryToSimplifyUncondBranchFromEmptyBlock() transform if the block is empty except for ephemeral values. The ephemeral values will be dropped in that case.

This makes sure that assumes don't block this transforms, as reported in https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609.

Diff Detail

Event Timeline

nikic created this revision.Jun 28 2023, 5:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2023, 5:59 AM
nikic requested review of this revision.Jun 28 2023, 5:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2023, 5:59 AM

any thoughts on https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609/19 and doing this in AssumeSimplifyPass instead of in SimplifyCFG?

nikic added a comment.Jun 28 2023, 1:14 PM

any thoughts on https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609/19 and doing this in AssumeSimplifyPass instead of in SimplifyCFG?

I think these approaches are largely orthogonal: One is about dropping assumes to enable a specific transform, the other is about dropping assumes that are "unprofitable" according to some heuristic. These are likely to have some overlap, but unless you want to tailor the profitability heuristic exactly to the legality conditions of specific transforms, you can't subsume the former with the latter.

ChuanqiXu accepted this revision.Jun 29 2023, 12:51 AM

LGTM. Thanks.

This revision is now accepted and ready to land.Jun 29 2023, 12:51 AM
This revision was landed with ongoing or failed builds.Jun 30 2023, 6:24 AM
This revision was automatically updated to reflect the committed changes.
maurer added a subscriber: maurer.Jun 30 2023, 10:26 AM

This change causes the rust-lang test issue-73396-bounds-check-after-position.rs to begin failing due to no longer being able to remove some bounds checks from generated code.

I understand that you don't treat the Rust compiler's tests as blockers, but wanted to let y'all know in case you see similar fallout in clang somewhere.

This change causes the rust-lang test issue-73396-bounds-check-after-position.rs to begin failing due to no longer being able to remove some bounds checks from generated code.

I understand that you don't treat the Rust compiler's tests as blockers, but wanted to let y'all know in case you see similar fallout in clang somewhere.

Could you share an LLVM IR reproducer?

I've extracted a reproducer, but still have to minimize it.

I've reverted the patch for now.

I now have a pretty clean reproduction.

I'm having trouble following the original patch author's heuristic for when it's safe to remove the assume, so I'll leave it up to them to rework it to avoid pruning load bearing assumes like this one.

nikic reopened this revision.Jul 3 2023, 7:36 AM
This revision is now accepted and ready to land.Jul 3 2023, 7:36 AM