This is an archive of the discontinued LLVM Phabricator instance.

Invoke simplifycfg and sroa before instcombine.
ClosedPublic

Authored by danielcdh on Jun 21 2016, 1:16 PM.

Details

Summary

InstCombine needs to be performed after simplifycfg and sroa, otherwise it may make bad optimization decisions.

Diff Detail

Event Timeline

danielcdh updated this revision to Diff 61433.Jun 21 2016, 1:16 PM
danielcdh retitled this revision from to Invoke simplifycfg and sroa before instcombine..
danielcdh updated this object.
danielcdh added reviewers: davidxl, wmi, dnovillo.
danielcdh added a subscriber: llvm-commits.
wmi edited edge metadata.Jun 21 2016, 2:39 PM

It may be helpful to provide more background here, especially whether this change affect samplefdo only or it may affect non-fdo mode too. We may need such information to justify the change.

lib/CodeGen/BackendUtil.cpp
185

This way sroa and cfgsimplify passes will be added before every Instcombine pass. Is it necessary? or it is only needed to add cfgsimplify and sroa for the first instcombine pass before sample fdo annotate?

danielcdh updated this revision to Diff 61455.Jun 21 2016, 3:12 PM
danielcdh edited edge metadata.

Change the function name to assert that this function should only be called for sample profiler.

danielcdh updated this revision to Diff 61456.Jun 21 2016, 3:13 PM

fix typo.

danielcdh updated this revision to Diff 61457.Jun 21 2016, 3:22 PM

add comment to the function to explain why these passes are needed before sample profile pass.

dnovillo added inline comments.Jun 22 2016, 4:55 AM
lib/CodeGen/BackendUtil.cpp
182–184

This is becoming much more than adding instcombine. Perhaps something like addCleanupPassesForSampleProfiler?

185

s/is needed/are needed/

What is this necessary preparation that they're needed for? In these descriptions, brevity is our enemy :) If you could write down more context here, that would be great. Thanks!

test/CodeGen/pgo-sample.c
1

So, for this test case, it's fine that we are showing that the passes are being run. But, is there a test case where we can test that the cleanup passes do something actually useful?

Perhaps an IL test that shows the transformations you're after.

danielcdh updated this revision to Diff 61615.Jun 22 2016, 3:01 PM

address Diego's reviews.

dnovillo accepted this revision.Jun 23 2016, 1:04 PM
dnovillo edited edge metadata.

LGTM. Thanks for the testcase and description.

This revision is now accepted and ready to land.Jun 23 2016, 1:04 PM
danielcdh closed this revision.Jun 23 2016, 1:20 PM