This is an archive of the discontinued LLVM Phabricator instance.

[DSE][WIP] Enable PHI translation to work through GEPs
Needs ReviewPublic

Authored by ebrevnov on Jun 29 2021, 5:55 AM.

Details

Reviewers
fhahn
Summary

Current implementation of PHITransAddr::PHITranslateValue succeeds only if phi translated address has exact match in the predecessor (see code at PHITransAddr.cpp:237 for more details). In other words, it will fail to translate %p5 (and as a result optimize stores) in the following example:

BB1:
%p1 = ...
%p2 = GEP i8* %p1, 2
store i32* %p2, 0
...
BB3:
%p3 = phi([%p1, BB1], ....)
%p4 = GEP i8* %p3, 1
%p5 = bitcast i8*p3 to i16*
store %p5, 0

The solution is to traverse through GEPs (and maintain offsets) before calling PHITransAddr::PHITranslateValue.

Diff Detail

Event Timeline

ebrevnov created this revision.Jun 29 2021, 5:55 AM
ebrevnov requested review of this revision.Jun 29 2021, 5:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 29 2021, 5:55 AM
ebrevnov edited the summary of this revision. (Show Details)Jun 29 2021, 6:01 AM
ebrevnov added a reviewer: fhahn.
ebrevnov updated this revision to Diff 356337.Jul 3 2021, 3:28 AM

Fixed test failures

fhahn added a comment.Sep 17 2021, 1:01 AM

It's hard to evaluate the impact of the change on its own. Is it strictly required for D90095 or could if be a follow-up to D90095 where we can show improvements on tests for this patch?

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
1113–1115

This comment needs updating, the if below now handles the must alias and partial alias case. The logic might be easier to follow & document if mustalias/partialalias logic would be kept separate, at the cost of minor code duplication.

It's hard to evaluate the impact of the change on its own. Is it strictly required for D90095 or could if be a follow-up to D90095 where we can show improvements on tests for this patch?

This should be doable. Do you want me to keep this as a separate NFC change or merge with functional change in PHI translation?

fhahn added a comment.Sep 20 2021, 6:39 AM

It's hard to evaluate the impact of the change on its own. Is it strictly required for D90095 or could if be a follow-up to D90095 where we can show improvements on tests for this patch?

This should be doable. Do you want me to keep this as a separate NFC change or merge with functional change in PHI translation?

If possible, I think it would be best to update D90095 to not require this change. I assume this will mean some cases will be missed. Ideally this patch would then be a follow-up to D90095 where it is not NFC but has a functional impact and the impact is obvious from the test changes. Would that work?

ebrevnov updated this revision to Diff 373603.Sep 20 2021, 8:35 AM

Include functional part exercizing non zero offsets. TODO: add tests.

ebrevnov updated this revision to Diff 373605.Sep 20 2021, 8:40 AM

Wrong diff uploaded last time. Fixed now.

ebrevnov updated this revision to Diff 373609.Sep 20 2021, 8:45 AM

Removed left offs after rebase

ebrevnov updated this revision to Diff 373613.Sep 20 2021, 8:49 AM

Non-zero offsets should be allowed. Removing corresponding assert.

ebrevnov retitled this revision from [DSE][NFC] Extend isOverwrite to take non zero initial offset to [DSE][WIP] Enable PHI translation work through GEPs.Sep 20 2021, 9:21 AM
ebrevnov edited the summary of this revision. (Show Details)
ebrevnov retitled this revision from [DSE][WIP] Enable PHI translation work through GEPs to [DSE][WIP] Enable PHI translation to work through GEPs.
Herald added a project: Restricted Project. · View Herald TranscriptJul 18 2022, 3:43 AM