This is an archive of the discontinued LLVM Phabricator instance.

[Analysis] Improve EmitGEPOffset by avoiding summ with zero
AbandonedPublic

Authored by yrouban on Oct 27 2020, 10:47 PM.

Details

Summary

EmitGEPOffset() is improved to avoid generation unneeded operation add 0, Result and return Result instead.

Diff Detail

Event Timeline

yrouban created this revision.Oct 27 2020, 10:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 27 2020, 10:47 PM
yrouban requested review of this revision.Oct 27 2020, 10:47 PM
jdoerfert added a subscriber: jdoerfert.EditedOct 27 2020, 11:28 PM

Drive by: Tests needed, commit message missing, and we should see if we can avoid 3-5 line assignments.

yrouban edited the summary of this revision. (Show Details)Oct 29 2020, 3:36 AM

Drive by: Tests needed, commit message missing, and we should see if we can avoid 3-5 line assignments.

EmitGEPOffset() is used by instcombine and we do not see the redundant add 0, X instruction because it is immediately optimized out in the same iteration. It prevents a simple lit test for this patch. On the other hand you can see the fix in InstCombinerImpl::OptimizePointerDifference() which changes the code to expect X in place of add 0, X and there is a related test (test/Transforms/InstCombine/sub-gep.ll), which I believe is enough for this small improvement.
Keep in mind that EmitGEPOffset() could be used in other custom passes that might not require subsequent instcombine to run.

I believe we do not have to adjust sources to make them look better being formatted by the clang formatter. We should improve the formatter instead. But this should not prevent this patch to be accepted.
I'm ok to rename the variables for a better look if this is the only thing that is needed for LGTM, though.

jdoerfert requested changes to this revision.Oct 29 2020, 9:02 AM

and there is a related test (test/Transforms/InstCombine/sub-gep.ll), which I believe is enough for this small improvement.

Is this test changed? It seems to be missing from the diff.

Keep in mind that EmitGEPOffset() could be used in other custom passes that might not require subsequent instcombine to run.

Noted.

I believe we do not have to adjust sources to make them look better being formatted by the clang formatter. We should improve the formatter instead. But this should not prevent this patch to be accepted. I'm ok to rename the variables for a better look if this is the only thing that is needed for LGTM, though.

Let me rephrase. Please avoid assignments over 3-5 lines, it is hard to read.

This revision now requires changes to proceed.Oct 29 2020, 9:02 AM