This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Teach instcombine not to create extra PHI nodes when folding GEPs
ClosedPublic

Authored by sbaranga on Oct 20 2015, 4:05 AM.

Details

Summary

InstCombine tries to transform GEP(PHI(GEP1, GEP2, ..)) into GEP(GEP(PHI(...))
when possible. However, this may leave the old PHI node around. Even if we
do end up folding the GEPs, having an extra PHI node might not be beneficial.

This change makes the transformation more conservative. We now only do this if
the PHI has only one use, and can therefore be removed after the transformation.

Diff Detail

Event Timeline

sbaranga updated this revision to Diff 37851.Oct 20 2015, 4:05 AM
sbaranga retitled this revision from to [InstCombine] Teach instcombine not to create extra PHI nodes when folding GEPs.
sbaranga updated this object.
sbaranga added reviewers: majnemer, jmolloy.
sbaranga added a subscriber: llvm-commits.

Benchmark results (lnt, spec2k, spec2k6):

spec.cpu2000.ref.300_twolf -1.96%
spec.cpu2006.ref.400_perlbench -1.55%
lnt.MultiSource/Applications/sqlite3/sqlite3 -1.48%
lnt.MultiSource/Benchmarks/Olden/tsp/tsp -1.26%
spec.cpu2000.ref.176_gcc -1.02%

This look fairly reasonable to me, but I'd prefer input from the other reviewers before signing off on this change.

majnemer accepted this revision.Oct 23 2015, 9:43 AM
majnemer edited edge metadata.

This looks straightforward enough, LGTM. It might be interesting to investigate if we should canonicalize multiple PHIs into a single PHI in cases where the IR ended up like this for other reasons.

This revision is now accepted and ready to land.Oct 23 2015, 9:43 AM
sbaranga closed this revision.Oct 26 2015, 3:27 AM