This is an archive of the discontinued LLVM Phabricator instance.

[Analysis] Analysis of storing unchanged loaded value
Needs ReviewPublic

Authored by ara-sc on Jul 20 2023, 7:25 AM.

Details

Summary

Presumably patterns of the following kind could be optimized:

%0 = load i8, ptr %c, align 1
store i8 %0, ptr %a, align 1
%1 = load i8, ptr %c, align 1
store i8 %1, ptr %b, align 1

InstCombine is responsible for these optimization. Only this pass (InstCombinerImpl::visitLoadInst) uses llvm::FindAvailableLoadedValue to find previous available loads.
So we can add simple helper to get rid of the redundant code.

Diff Detail

Event Timeline

ara-sc created this revision.Jul 20 2023, 7:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 20 2023, 7:25 AM
ara-sc requested review of this revision.Jul 20 2023, 7:25 AM
ara-sc updated this revision to Diff 542533.Jul 20 2023, 8:07 AM
nikic added a comment.Jul 21 2023, 3:37 AM

InstCombine is responsible for these optimization.

Not really. The pass responsible for this is GVN, via MemDepAnalysis and to a lesser degree EarlyCSE via MSSA. InstCombine implements a very weak version of load CSE optimization for phase ordering reasons. I'm skeptical about making InstCombine handle patterns that GVN cannot handle, because the optimization in InstCombine is fundamentally limited to a tiny instruction window.